2 Commits

Author SHA1 Message Date
yoyofx
badd6647dc Nacos AMC or KMS 2021-06-01 19:33:47 +08:00
yoyofx
66c4e16397 provider with config type 2021-05-12 13:56:58 +08:00
8 changed files with 63 additions and 5 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/nacos-viper-remote.iml" filepath="$PROJECT_DIR$/.idea/nacos-viper-remote.iml" />
</modules>
</component>
</project>

9
.idea/nacos-viper-remote.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -6,17 +6,19 @@ import (
) )
type ViperRemoteProvider struct { type ViperRemoteProvider struct {
configType string
configSet string configSet string
} }
func NewRemoteProvider() *ViperRemoteProvider { func NewRemoteProvider(configType string) *ViperRemoteProvider {
return &ViperRemoteProvider{ return &ViperRemoteProvider{
configType: configType,
configSet: "yoyogo.cloud.discovery.metadata"} configSet: "yoyogo.cloud.discovery.metadata"}
} }
func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *viper.Viper { func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *viper.Viper {
var option *Option var option *Option
err := runtime_viper.Sub("yoyogo.cloud.discovery.metadata").Unmarshal(&option) err := runtime_viper.Sub(provider.configSet).Unmarshal(&option)
if err != nil { if err != nil {
panic(err) panic(err)
return nil return nil
@@ -24,7 +26,10 @@ func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *vi
SetOptions(option) SetOptions(option)
remote_viper := viper.New() remote_viper := viper.New()
err = remote_viper.AddRemoteProvider("nacos", "localhost", "") err = remote_viper.AddRemoteProvider("nacos", "localhost", "")
remote_viper.SetConfigType("yaml") if provider.configType == "" {
provider.configType = "yaml"
}
remote_viper.SetConfigType(provider.configType)
err = remote_viper.ReadRemoteConfig() err = remote_viper.ReadRemoteConfig()
if err == nil { if err == nil {
err = remote_viper.WatchRemoteConfigOnChannel() err = remote_viper.WatchRemoteConfigOnChannel()

View File

@@ -18,3 +18,8 @@ yoyogo:
enable: true enable: true
username: "root" username: "root"
password: "1234" password: "1234"
endpoint: ""
regionId: ""
accessKey: ""
secretKey: ""
openKMS: false

View File

@@ -34,9 +34,15 @@ func NewNacosConfigManager(option *Option) (*nacosConfigManager, error) {
MaxAge: 3, MaxAge: 3,
LogLevel: "info", LogLevel: "info",
} }
if option.Auth != nil && option.Auth.Enable { if option.Auth != nil && option.Auth.Enable {
clientConfig.Username = option.Auth.User clientConfig.Username = option.Auth.User
clientConfig.Password = option.Auth.Password clientConfig.Password = option.Auth.Password
clientConfig.Endpoint = option.Auth.Endpoint
clientConfig.RegionId = option.Auth.RegionId
clientConfig.AccessKey = option.Auth.AccessKey
clientConfig.SecretKey = option.Auth.SecretKey
clientConfig.OpenKMS = option.Auth.OpenKMS
} }
client, err := clients.CreateConfigClient(map[string]interface{}{ client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": serverConfigs, "serverConfigs": serverConfigs,

View File

@@ -17,4 +17,15 @@ type Auth struct {
Enable bool `mapstructure:"enable"` Enable bool `mapstructure:"enable"`
User string `mapstructure:"username"` User string `mapstructure:"username"`
Password string `mapstructure:"password"` Password string `mapstructure:"password"`
// ACM Endpoint
Endpoint string `mapstructure:"endpoint"`
// ACM RegionId
RegionId string `mapstructure:"regionId"`
// ACM AccessKey
AccessKey string `mapstructure:"accessKey"`
// ACM SecretKey
SecretKey string `mapstructure:"secretKey"`
// ACM OpenKMS
OpenKMS bool `mapstructure:"openKMS"`
} }