From 455852e98129ec657c92f4200fd2fb1d7f339444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BB=B6?= <1060026287@qq.com> Date: Thu, 25 Mar 2021 22:57:09 +0800 Subject: [PATCH] support a way to ignore check some key in parameters. (#7371) --- .../main/java/org/apache/dubbo/config/Constants.java | 2 ++ .../dubbo/config/utils/ConfigValidationUtils.java | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java index 5af0de470fb..659b7bbf563 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java @@ -115,4 +115,6 @@ public interface Constants { String ZOOKEEPER_PROTOCOL = "zookeeper"; String REGISTER_KEY = "register"; + + String IGNORE_CHECK_KEYS = "ignoreCheckKeys"; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java index 5d935fa6054..a6e1276394a 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java @@ -65,6 +65,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -102,6 +103,7 @@ import static org.apache.dubbo.config.Constants.CONTEXTPATH_KEY; import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.config.Constants.ENVIRONMENT; +import static org.apache.dubbo.config.Constants.IGNORE_CHECK_KEYS; import static org.apache.dubbo.config.Constants.LAYER_KEY; import static org.apache.dubbo.config.Constants.NAME; import static org.apache.dubbo.config.Constants.ORGANIZATION; @@ -624,8 +626,14 @@ public static void checkParameterName(Map parameters) { if (CollectionUtils.isEmptyMap(parameters)) { return; } + List ignoreCheckKeys = new ArrayList<>(); + ignoreCheckKeys.add(BACKUP_KEY); + String ignoreCheckKeysStr = parameters.get(IGNORE_CHECK_KEYS); + if (!StringUtils.isBlank(ignoreCheckKeysStr)) { + ignoreCheckKeys.addAll(Arrays.asList(ignoreCheckKeysStr.split(","))); + } for (Map.Entry entry : parameters.entrySet()) { - if (!entry.getKey().equals(BACKUP_KEY)) { + if (!ignoreCheckKeys.contains(entry.getKey())) { checkNameHasSymbol(entry.getKey(), entry.getValue()); } }