diff --git a/common/constant/key.go b/common/constant/key.go index da21a3a9e1254d5a22d670a11c5c01022892e096..e62beffc44c40044691f8285262a47e7d2080578 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -212,9 +212,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 52a7dcbfc77fd576ef8d2917ce51cc09f3cd0b97..aa8fbcbe7d6eca682892d4627878fe6bfc3756fe 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() { diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index cee2a6a625368f655d1b9bc5fe8cc37031e1aef7..15fd3cacfacad36309e0ad4deb3c7c7441e47e26 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -284,3 +284,12 @@ func TestExportWithApplicationConfig(t *testing.T) { v2, _ := regProtocol.bounds.Load(getCacheKey(newUrl)) assert.NotNil(t, v2) } + +func TestGetProviderUrlWithHideKey(t *testing.T) { + url, _ := common.NewURL("dubbo://127.0.0.1:1111?a=a1&b=b1&.c=c1&.d=d1&e=e1&protocol=registry") + providerUrl := getUrlToRegistry(&url, &url) + assert.NotContains(t, providerUrl.GetParams(), ".c") + assert.NotContains(t, providerUrl.GetParams(), ".d") + assert.Contains(t, providerUrl.GetParams(), "a") + +}