Skip to content

Commit

Permalink
[Controller] additional domains config
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie committed Oct 17, 2023
1 parent 7746589 commit e3e93f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion server/controller/http/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
package config

type Config struct {
RedisRefreshInterval int `default:"3600" yaml:"redis_refresh_interval"`
RedisRefreshInterval int `default:"3600" yaml:"redis_refresh_interval"`
AdditionalDomains []string `yaml:"additional_domains"`
}
18 changes: 12 additions & 6 deletions server/controller/http/service/resource/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ import (

var log = logging.MustGetLogger("service.resource")

var DOMAIN_PASSWORD_KEYS = []string{
"admin_password", "secret_key", "password", "boss_secret_key", "manage_one_password", "token",
var DOMAIN_PASSWORD_KEYS = map[string]bool{
"admin_password": false,
"secret_key": false,
"client_secret": false,
"password": false,
"boss_secret_key": false,
"manage_one_password": false,
"token": false,
}

func getGrpcServerAndPort(controllerIP string, cfg *config.ControllerConfig) (string, string) {
Expand Down Expand Up @@ -167,7 +173,7 @@ func GetDomains(filter map[string]interface{}) (resp []model.Domain, err error)

domainResp.Config = make(map[string]interface{})
json.Unmarshal([]byte(domain.Config), &domainResp.Config)
for _, key := range DOMAIN_PASSWORD_KEYS {
for key := range DOMAIN_PASSWORD_KEYS {
if _, ok := domainResp.Config[key]; ok {
domainResp.Config[key] = common.DEFAULT_ENCRYPTION_PASSWORD
}
Expand Down Expand Up @@ -204,7 +210,7 @@ func maskDomainInfo(domainCreate model.DomainCreate) model.DomainCreate {
info := domainCreate
info.Config = map[string]interface{}{}
for k, v := range domainCreate.Config {
if common.Contains(DOMAIN_PASSWORD_KEYS, k) {
if _, ok := DOMAIN_PASSWORD_KEYS[k]; ok {
info.Config[k] = "******"
} else {
info.Config[k] = v
Expand Down Expand Up @@ -288,7 +294,7 @@ func CreateDomain(domainCreate model.DomainCreate, cfg *config.ControllerConfig)
domain.ControllerIP = controllerIP

// encrypt password/access_key
for _, key := range DOMAIN_PASSWORD_KEYS {
for key := range DOMAIN_PASSWORD_KEYS {
if _, ok := domainCreate.Config[key]; ok && cfg != nil {
serverIP, grpcServerPort := getGrpcServerAndPort(domain.ControllerIP, cfg)
encryptKey, err := common.GetEncryptKey(
Expand Down Expand Up @@ -410,7 +416,7 @@ func UpdateDomain(
}

// transfer password/access_key
for _, key := range DOMAIN_PASSWORD_KEYS {
for key := range DOMAIN_PASSWORD_KEYS {
if _, ok := configUpdate[key]; ok && cfg != nil {
if configUpdate[key] == common.DEFAULT_ENCRYPTION_PASSWORD {
configUpdate[key] = config[key]
Expand Down
3 changes: 3 additions & 0 deletions server/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ controller:
http:
# resource api redis cache refresh interval, unit:s
redis_refresh_interval: 3600
# additional domains
additional_domains:
# - eshore

# deepflow web service config
df-web-service:
Expand Down

0 comments on commit e3e93f0

Please sign in to comment.