Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Apollo secret #1533

Merged
merged 5 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
30 changes: 10 additions & 20 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions config/config_center_config_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format import block please.

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)
}
8 changes: 8 additions & 0 deletions config/testdata/config/center/apollo.yaml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 7 additions & 21 deletions config_center/apollo/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -43,7 +42,6 @@ import (

const (
apolloProtocolPrefix = "http://"
apolloConfigFormat = "%s%s"
)

type apolloConfiguration struct {
Expand All @@ -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()
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion config_center/apollo/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ require (
k8s.io/api v0.16.9
k8s.io/apimachinery v0.16.9
k8s.io/client-go v0.16.9
)
)