This is an automated email from the ASF dual-hosted git repository. laurence pushed a commit to branch fix/nacos-2.0 in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
commit f38a0c261ed751d5780be87841d59431cd87f56b Author: LaurenceLiZhixin <[email protected]> AuthorDate: Wed Nov 10 15:35:15 2021 +0800 fix: nacos servicediscovery group --- common/constant/key.go | 2 -- config/config_center_config.go | 4 ++++ config/registry_config.go | 5 +++++ registry/nacos/registry.go | 3 ++- registry/nacos/service_discovery.go | 14 ++++++++------ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/constant/key.go b/common/constant/key.go index bff5e81..24378de 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -138,8 +138,6 @@ const ( ServiceRegistryProtocol = "service-discovery-registry" RegistryRoleKey = "registry.role" RegistryDefaultKey = "registry.default" - RegistryUsernameKey = "registry.username" - RegistryPasswordKey = "registry.password" RegistryAccessKey = "registry.accesskey" RegistrySecretKey = "registry.secretkey" RegistryTimeoutKey = "registry.timeout" diff --git a/config/config_center_config.go b/config/config_center_config.go index 00cb05b..db81da1 100644 --- a/config/config_center_config.go +++ b/config/config_center_config.go @@ -60,6 +60,8 @@ type CenterConfig struct { Namespace string `yaml:"namespace" json:"namespace,omitempty"` AppID string `default:"dubbo" yaml:"app-id" json:"app-id,omitempty"` Timeout string `default:"10s" yaml:"timeout" json:"timeout,omitempty"` + AccessKey string `yaml:"access-key" json:"access-key,omitempty" property:"access-key"` + SecretKey string `yaml:"secret-key" json:"secret-key,omitempty" property:"secret-key"` Params map[string]string `yaml:"params" json:"parameters,omitempty"` } @@ -94,6 +96,8 @@ func (c *CenterConfig) GetUrlMap() url.Values { urlMap.Set(constant.ConfigClusterKey, c.Cluster) urlMap.Set(constant.ConfigAppIDKey, c.AppID) urlMap.Set(constant.ConfigUsernameKey, c.Username) + urlMap.Set(constant.ConfigAccessKey, c.AccessKey) + urlMap.Set(constant.ConfigSecretKey, c.SecretKey) urlMap.Set(constant.ConfigPasswordKey, c.Password) urlMap.Set(constant.ConfigTimeoutKey, c.Timeout) diff --git a/config/registry_config.go b/config/registry_config.go index a1b0b5c..1ead33e 100644 --- a/config/registry_config.go +++ b/config/registry_config.go @@ -42,6 +42,8 @@ type RegistryConfig struct { Group string `yaml:"group" json:"group,omitempty" property:"group"` Namespace string `yaml:"namespace" json:"namespace,omitempty" property:"namespace"` TTL string `default:"10s" yaml:"ttl" json:"ttl,omitempty" property:"ttl"` // unit: minute + AccessKey string `yaml:"access-key" json:"access-key,omitempty" property:"access-key"` + SecretKey string `yaml:"secret-key" json:"secret-key,omitempty" property:"secret-key"` // for registry Address string `validate:"required" yaml:"address" json:"address,omitempty" property:"address"` Username string `yaml:"username" json:"username,omitempty" property:"username"` @@ -130,6 +132,9 @@ func (c *RegistryConfig) toURL(roleType common.RoleType) (*common.URL, error) { common.WithParamsValue(constant.RegistrySimplifiedKey, strconv.FormatBool(c.Simplified)), common.WithParamsValue(constant.RegistryKey, c.Protocol), common.WithParamsValue(constant.RegistryNamespaceKey, c.Namespace), + common.WithParamsValue(constant.RegistryAccessKey, c.AccessKey), + common.WithParamsValue(constant.RegistrySecretKey, c.SecretKey), + common.WithParamsValue(constant.RegistrySecretKey, c.SecretKey), common.WithUsername(c.Username), common.WithPassword(c.Password), common.WithLocation(c.Address), diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go index 4a6c011..a2bdb51 100644 --- a/registry/nacos/registry.go +++ b/registry/nacos/registry.go @@ -244,7 +244,8 @@ func newNacosRegistry(url *common.URL) (registry.Registry, error) { logger.Infof("[Nacos Registry] New nacos registry with url = %+v", url.ToMap()) // key transfer: registry -> nacos url.SetParam(constant.NacosNamespaceID, url.GetParam(constant.RegistryNamespaceKey, "")) - url.SetParam(constant.NacosUsername, url.GetParam(constant.RegistryUsernameKey, "")) + url.SetParam(constant.NacosUsername, url.Username) + url.SetParam(constant.NacosPassword, url.Password) url.SetParam(constant.NacosAccessKey, url.GetParam(constant.RegistryAccessKey, "")) url.SetParam(constant.NacosSecretKey, url.GetParam(constant.RegistrySecretKey, "")) url.SetParam(constant.TimeoutKey, url.GetParam(constant.RegistryTimeoutKey, "")) diff --git a/registry/nacos/service_discovery.go b/registry/nacos/service_discovery.go index 1f5c939..f0b50f9 100644 --- a/registry/nacos/service_discovery.go +++ b/registry/nacos/service_discovery.go @@ -332,10 +332,15 @@ func newNacosServiceDiscovery(url *common.URL) (registry.ServiceDiscovery, error discoveryURL := common.NewURLWithOptions( common.WithParams(url.GetParams()), common.WithParamsValue(constant.TimeoutKey, url.GetParam(constant.RegistryTimeoutKey, constant.DefaultRegTimeout)), - common.WithParamsValue(constant.RegistryUsernameKey, url.GetParam(constant.RegistryUsernameKey, "")), - common.WithParamsValue(constant.RegistryPasswordKey, url.GetParam(constant.RegistryPasswordKey, "")), + common.WithParamsValue(constant.NacosGroupKey, url.GetParam(constant.RegistryGroupKey, defaultGroup)), + common.WithParamsValue(constant.NacosUsername, url.Username), + common.WithParamsValue(constant.NacosPassword, url.Password), + common.WithParamsValue(constant.NacosAccessKey, url.GetParam(constant.RegistryAccessKey, "")), + common.WithParamsValue(constant.NacosSecretKey, url.GetParam(constant.RegistrySecretKey, "")), common.WithParamsValue(constant.NacosNamespaceID, url.GetParam(constant.RegistryNamespaceKey, ""))) discoveryURL.Location = url.Location + discoveryURL.Username = url.Username + discoveryURL.Password = url.Password client, err := nacos.NewNacosClientByURL(discoveryURL) if err != nil { return nil, perrors.WithMessage(err, "create nacos namingClient failed.") @@ -343,10 +348,7 @@ func newNacosServiceDiscovery(url *common.URL) (registry.ServiceDiscovery, error descriptor := fmt.Sprintf("nacos-service-discovery[%s]", discoveryURL.Location) - group := discoveryURL.Group() - if len(group) == 0 { - group = defaultGroup - } + group := url.GetParam(constant.RegistryGroupKey, defaultGroup) newInstance := &nacosServiceDiscovery{ group: group, namingClient: client,
