Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
add override env configuration in home config file (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeckoSplinter authored and n0rad committed Nov 14, 2018
1 parent edcb5f3 commit fc804a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ggn/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ type Config struct {
WorkPath string `yaml:"workPath,omitempty"`
User string `yaml:"user,omitempty"`
EnvVarUser string `yaml:"envVarUser,omitempty"`

OverrideConfig map[string]struct {
Fleet struct {
Endpoint string `yaml:"endpoint,omitempty"`
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
Strict_host_key_checking *bool `yaml:"strict_host_key_checking,omitempty"`
Sudo *bool `yaml:"sudo,omitempty"`
Driver string `yaml:"driver,omitempty"`
} `yaml:"fleet,omitempty"`
} `yaml:"overrideConfig,omitempty"`
}

type HomeStruct struct {
Expand Down
32 changes: 32 additions & 0 deletions work/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,38 @@ func (e *Env) loadConfig() {
dest[v] = src[i]
}
e.config.Fleet.Endpoint = strings.Join(dest, ",")

if _, ok := ggn.Home.Config.OverrideConfig[e.config.EnvName]; ok {
e.overrideFleetEnv()
}
}

func (e *Env) overrideFleetEnv() {
overridedEnv := ggn.Home.Config.OverrideConfig[e.config.EnvName]
if overridedEnv.Fleet.Endpoint != "" {
src := strings.Split(overridedEnv.Fleet.Endpoint, ",")
dest := make([]string, len(src))
perm := rand.Perm(len(src))
for i, v := range perm {
dest[v] = src[i]
}
e.config.Fleet.Endpoint = strings.Join(dest, ",")
}
if overridedEnv.Fleet.Username != "" {
e.config.Fleet.Username = overridedEnv.Fleet.Username
}
if overridedEnv.Fleet.Driver != "" {
e.config.Fleet.Driver = overridedEnv.Fleet.Driver
}
if overridedEnv.Fleet.Password != "" {
e.config.Fleet.Password = overridedEnv.Fleet.Password
}
if overridedEnv.Fleet.Strict_host_key_checking != nil {
e.config.Fleet.Strict_host_key_checking = *overridedEnv.Fleet.Strict_host_key_checking
}
if overridedEnv.Fleet.Sudo != nil {
e.config.Fleet.Sudo = *overridedEnv.Fleet.Sudo
}
}

func (e *Env) loadPartials() {
Expand Down

0 comments on commit fc804a3

Please sign in to comment.