You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by la...@apache.org on 2021/10/25 05:37:42 UTC
[dubbo-go] branch 3.0 updated: Support Apollo secret (#1533)
This is an automated email from the ASF dual-hosted git repository.
laurence pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new b1a1617 Support Apollo secret (#1533)
b1a1617 is described below
commit b1a1617a368fba69ec0472362ea0734a5aecf5d4
Author: zhaoyunxing <zh...@apache.org>
AuthorDate: Mon Oct 25 13:37:35 2021 +0800
Support Apollo secret (#1533)
* add:apollo config center
* fmt
* fmt
* fix:apollo namespace
* fmt
---
common/constant/key.go | 23 ++++++++++---------
config/config_center_config.go | 30 +++++++++----------------
config/config_center_config_test.go | 37 +++++++++++++++++++++++++++++++
config/testdata/config/center/apollo.yaml | 8 +++++++
config_center/apollo/impl.go | 28 ++++++-----------------
config_center/apollo/impl_test.go | 2 +-
go.mod | 2 +-
7 files changed, 77 insertions(+), 53 deletions(-)
diff --git a/common/constant/key.go b/common/constant/key.go
index 3160f92..5aeb970 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -164,16 +164,19 @@ const (
)
const (
- CONFIG_NAMESPACE_KEY = "namespace"
- CONFIG_GROUP_KEY = "group"
- CONFIG_APP_ID_KEY = "appId"
- CONFIG_CLUSTER_KEY = "cluster"
- CONFIG_TIMEOUT_KEY = "timeout"
- CONFIG_USERNAME_KEY = "username"
- CONFIG_PASSWORD_KEY = "password"
- CONFIG_LOG_DIR_KEY = "logDir"
- CONFIG_VERSION_KEY = "configVersion"
- COMPATIBLE_CONFIG_KEY = "compatible_config"
+ CONFIG_NAMESPACE_KEY = "namespace"
+ CONFIG_GROUP_KEY = "group"
+ CONFIG_APP_ID_KEY = "appId"
+ CONFIG_CLUSTER_KEY = "cluster"
+ CONFIG_TIMEOUT_KEY = "timeout"
+ CONFIG_USERNAME_KEY = "username"
+ CONFIG_PASSWORD_KEY = "password"
+ CONFIG_LOG_DIR_KEY = "logDir"
+ CONFIG_VERSION_KEY = "configVersion"
+ COMPATIBLE_CONFIG_KEY = "compatible_config"
+ CONFIG_SECRET_KEY = "secret"
+ CONFIG_BACKUP_CONFIG_KEY = "isBackupConfig"
+ CONFIG_BACKUP_CONFIG_PATH_KEY = "backupConfigPath"
)
const (
diff --git a/config/config_center_config.go b/config/config_center_config.go
index 6ac615f..025ca0e 100644
--- a/config/config_center_config.go
+++ b/config/config_center_config.go
@@ -49,25 +49,16 @@ import (
//
// CenterConfig has currently supported Zookeeper, Nacos, Etcd, Consul, Apollo
type CenterConfig struct {
- Protocol string `validate:"required" yaml:"protocol" json:"protocol,omitempty"`
- Address string `validate:"required" yaml:"address" json:"address,omitempty"`
- DataId string `validate:"required" yaml:"data-id" json:"data-id,omitempty"`
- Cluster string `yaml:"cluster" json:"cluster,omitempty"`
- Group string `default:"dubbo" yaml:"group" json:"group,omitempty"`
- Username string `yaml:"username" json:"username,omitempty"`
- Password string `yaml:"password" json:"password,omitempty"`
- // Deprecated
- LogDir string `yaml:"log-dir" json:"log-dir,omitempty"`
- // Deprecated
- ConfigFile string `default:"dubbo.properties" yaml:"config-file" json:"config-file,omitempty"`
- Namespace string `default:"dubbo" yaml:"namespace" json:"namespace,omitempty"`
- // Deprecated
- AppConfigFile string `default:"dubbo.properties" yaml:"app-config-file" json:"app-config-file,omitempty"`
- // Deprecated
- AppID string `default:"dubbo" yaml:"app-id" json:"app-id,omitempty"`
- Timeout string `default:"10s" yaml:"timeout" json:"timeout,omitempty"`
- // Deprecated
- RemoteRef string `required:"false" yaml:"remote-ref" json:"remote-ref,omitempty"`
+ Protocol string `validate:"required" yaml:"protocol" json:"protocol,omitempty"`
+ Address string `validate:"required" yaml:"address" json:"address,omitempty"`
+ DataId string `yaml:"data-id" json:"data-id,omitempty"`
+ Cluster string `yaml:"cluster" json:"cluster,omitempty"`
+ Group string `default:"dubbo" yaml:"group" json:"group,omitempty"`
+ Username string `yaml:"username" json:"username,omitempty"`
+ Password string `yaml:"password" json:"password,omitempty"`
+ Namespace string `default:"dubbo" 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"`
Params map[string]string `yaml:"params" json:"parameters,omitempty"`
}
@@ -101,7 +92,6 @@ func (c *CenterConfig) GetUrlMap() url.Values {
urlMap.Set(constant.CONFIG_GROUP_KEY, c.Group)
urlMap.Set(constant.CONFIG_CLUSTER_KEY, c.Cluster)
urlMap.Set(constant.CONFIG_APP_ID_KEY, c.AppID)
- urlMap.Set(constant.CONFIG_LOG_DIR_KEY, c.LogDir)
urlMap.Set(constant.CONFIG_USERNAME_KEY, c.Username)
urlMap.Set(constant.CONFIG_PASSWORD_KEY, c.Password)
urlMap.Set(constant.CONFIG_TIMEOUT_KEY, c.Timeout)
diff --git a/config/config_center_config_test.go b/config/config_center_config_test.go
new file mode 100644
index 0000000..dca8632
--- /dev/null
+++ b/config/config_center_config_test.go
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package config
+
+import (
+ "testing"
+)
+import (
+ "github.com/stretchr/testify/assert"
+)
+import (
+ _ "dubbo.apache.org/dubbo-go/v3/config_center/apollo"
+)
+
+func TestApolloConfigCenterConfig(t *testing.T) {
+
+ err := Load(WithPath("./testdata/config/center/apollo.yaml"))
+ assert.Nil(t, err)
+
+ registries := rootConfig.Registries
+ assert.NotNil(t, registries)
+}
diff --git a/config/testdata/config/center/apollo.yaml b/config/testdata/config/center/apollo.yaml
new file mode 100644
index 0000000..0b10e9e
--- /dev/null
+++ b/config/testdata/config/center/apollo.yaml
@@ -0,0 +1,8 @@
+dubbo:
+ config-center:
+ address: apollo://106.54.227.205:8080
+ cluster: dev
+ namespace: dubbogo.yaml
+ app-id: dubbo-go
+ params:
+ secret: 3a64cf5cd9ac4fcd94eb045de433689c
\ No newline at end of file
diff --git a/config_center/apollo/impl.go b/config_center/apollo/impl.go
index 6594a92..9df8fd7 100644
--- a/config_center/apollo/impl.go
+++ b/config_center/apollo/impl.go
@@ -30,7 +30,6 @@ import (
perrors "github.com/pkg/errors"
"github.com/zouyx/agollo/v3"
- agolloConstant "github.com/zouyx/agollo/v3/constant"
"github.com/zouyx/agollo/v3/env/config"
)
@@ -43,7 +42,6 @@ import (
const (
apolloProtocolPrefix = "http://"
- apolloConfigFormat = "%s%s"
)
type apolloConfiguration struct {
@@ -59,22 +57,18 @@ func newApolloConfiguration(url *common.URL) (*apolloConfiguration, error) {
c := &apolloConfiguration{
url: url,
}
- configAddr := c.getAddressWithProtocolPrefix(url)
- configCluster := url.GetParam(constant.CONFIG_CLUSTER_KEY, "")
-
- appId := url.GetParam(constant.CONFIG_APP_ID_KEY, "")
- namespaces := getProperties(url.GetParam(constant.CONFIG_NAMESPACE_KEY, cc.DEFAULT_GROUP))
c.appConf = &config.AppConfig{
- AppID: appId,
- Cluster: configCluster,
- NamespaceName: namespaces,
- IP: configAddr,
+ AppID: url.GetParam(constant.CONFIG_APP_ID_KEY, ""),
+ Cluster: url.GetParam(constant.CONFIG_CLUSTER_KEY, ""),
+ NamespaceName: url.GetParam(constant.CONFIG_NAMESPACE_KEY, cc.DEFAULT_GROUP),
+ IP: c.getAddressWithProtocolPrefix(url),
+ Secret: url.GetParam(constant.CONFIG_SECRET_KEY, ""),
+ IsBackupConfig: url.GetParamBool(constant.CONFIG_BACKUP_CONFIG_KEY, true),
+ BackupConfigPath: url.GetParam(constant.CONFIG_BACKUP_CONFIG_PATH_KEY, ""),
}
-
agollo.InitCustomConfig(func() (*config.AppConfig, error) {
return c.appConf, nil
})
-
return c, agollo.Start()
}
@@ -102,14 +96,6 @@ func (c *apolloConfiguration) RemoveListener(key string, listener cc.Configurati
}
}
-func getProperties(namespace string) string {
- return getNamespaceName(namespace, agolloConstant.YAML)
-}
-
-func getNamespaceName(namespace string, configFileFormat agolloConstant.ConfigFileFormat) string {
- return fmt.Sprintf(apolloConfigFormat, namespace, configFileFormat)
-}
-
func (c *apolloConfiguration) GetInternalProperty(key string, opts ...cc.Option) (string, error) {
newConfig := agollo.GetConfig(c.appConf.NamespaceName)
if newConfig == nil {
diff --git a/config_center/apollo/impl_test.go b/config_center/apollo/impl_test.go
index e96ce8d..0a0ab62 100644
--- a/config_center/apollo/impl_test.go
+++ b/config_center/apollo/impl_test.go
@@ -155,7 +155,7 @@ func initMockApollo(t *testing.T) *apolloConfiguration {
Address: "106.12.25.204:8080",
AppID: "testApplication_yang",
Cluster: "dev",
- Namespace: "mockDubbogo",
+ Namespace: "mockDubbogo.yaml",
}}
apollo := initApollo()
apolloUrl := strings.ReplaceAll(apollo.URL, "http", "apollo")
diff --git a/go.mod b/go.mod
index 3804e96..f5ef5bd 100644
--- a/go.mod
+++ b/go.mod
@@ -50,4 +50,4 @@ require (
k8s.io/api v0.16.9
k8s.io/apimachinery v0.16.9
k8s.io/client-go v0.16.9
-)
+)
\ No newline at end of file