From 09970cd380eac0013d298d7e531b597a9995a5ea Mon Sep 17 00:00:00 2001 From: jy2156121 Date: Mon, 9 Mar 2020 13:54:10 +0800 Subject: [PATCH] dashboard: Support setting value pattern for client IP and host in gateway flow rule dialog (#1325) --- .../gateway/GatewayFlowRuleController.java | 38 +++++++++---------- .../dialog/gateway/flow-rule-dialog.html | 2 +- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java index 01891637..b0a53e73 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java @@ -146,18 +146,17 @@ public class GatewayFlowRuleController { return Result.ofFail(-1, "fieldName can't be null or empty"); } itemEntity.setFieldName(paramItem.getFieldName()); + } - String pattern = paramItem.getPattern(); - // 如果匹配串不为空,验证匹配模式 - if (StringUtil.isNotEmpty(pattern)) { - itemEntity.setPattern(pattern); - - Integer matchStrategy = paramItem.getMatchStrategy(); - if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { - return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); - } - itemEntity.setMatchStrategy(matchStrategy); + String pattern = paramItem.getPattern(); + // 如果匹配串不为空,验证匹配模式 + if (StringUtil.isNotEmpty(pattern)) { + itemEntity.setPattern(pattern); + Integer matchStrategy = paramItem.getMatchStrategy(); + if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { + return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); } + itemEntity.setMatchStrategy(matchStrategy); } } @@ -292,18 +291,17 @@ public class GatewayFlowRuleController { return Result.ofFail(-1, "fieldName can't be null or empty"); } itemEntity.setFieldName(paramItem.getFieldName()); + } - String pattern = paramItem.getPattern(); - // 如果匹配串不为空,验证匹配模式 - if (StringUtil.isNotEmpty(pattern)) { - itemEntity.setPattern(pattern); - - Integer matchStrategy = paramItem.getMatchStrategy(); - if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { - return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); - } - itemEntity.setMatchStrategy(matchStrategy); + String pattern = paramItem.getPattern(); + // 如果匹配串不为空,验证匹配模式 + if (StringUtil.isNotEmpty(pattern)) { + itemEntity.setPattern(pattern); + Integer matchStrategy = paramItem.getMatchStrategy(); + if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { + return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); } + itemEntity.setMatchStrategy(matchStrategy); } } else { entity.setParamItem(null); diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html index 7dca16d7..ea744a71 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html @@ -70,7 +70,7 @@ -
+