From f25c60fbf934bcacd0fb2b313b468065cf7b326a Mon Sep 17 00:00:00 2001 From: CodingSinger <ooczzoo@gmail.com> Date: Sat, 9 May 2020 17:04:32 +0800 Subject: [PATCH] filter registry url params starting with dot --- common/constant/key.go | 4 ++-- registry/protocol/protocol.go | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/constant/key.go b/common/constant/key.go index d9413fcc9..a07615264 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -210,9 +210,9 @@ const ( // consumer CONSUMER = "consumer" // key of access key id - ACCESS_KEY_ID_KEY = "accessKeyId" + ACCESS_KEY_ID_KEY = ".accessKeyId" // key of secret access key - SECRET_ACCESS_KEY_KEY = "secretAccessKey" + SECRET_ACCESS_KEY_KEY = ".secretAccessKey" ) // metadata report diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 52a7dcbfc..aa8fbcbe7 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -22,9 +22,8 @@ import ( "strings" "sync" ) - import ( - "github.com/dubbogo/gost/container/set" + gxset "github.com/dubbogo/gost/container/set" ) import ( @@ -96,8 +95,24 @@ func getRegistry(regUrl *common.URL) registry.Registry { func getUrlToRegistry(providerUrl *common.URL, registryUrl *common.URL) *common.URL { if registryUrl.GetParamBool("simplified", false) { return providerUrl.CloneWithParams(reserveParams) + } else { + return filterHideKey(providerUrl) + } +} + +// filterHideKey filter the parameters that do not need to be output in url(Starting with .) +func filterHideKey(url *common.URL) *common.URL { + + //be careful params maps in url is map type + cloneURL := url.Clone() + removeSet := gxset.NewSet() + for k, _ := range cloneURL.GetParams() { + if strings.HasPrefix(k, ".") { + removeSet.Add(k) + } } - return providerUrl + cloneURL.RemoveParams(removeSet) + return cloneURL } func (proto *registryProtocol) initConfigurationListeners() { -- GitLab