mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 20:26:13 +01:00
Merge pull request #2837 from ywk253100/170721_integration
Load absent property from env
This commit is contained in:
commit
45d583b171
@ -227,11 +227,22 @@ func initCfgStore() (err error) {
|
||||
}
|
||||
|
||||
// LoadFromEnv loads the configurations from allEnvs, if all is false, it just loads
|
||||
// the repeatLoadEnvs
|
||||
// the repeatLoadEnvs and the env which is absent in cfgs
|
||||
func LoadFromEnv(cfgs map[string]interface{}, all bool) error {
|
||||
envs := repeatLoadEnvs
|
||||
var envs map[string]interface{}
|
||||
|
||||
if all {
|
||||
envs = allEnvs
|
||||
} else {
|
||||
envs = make(map[string]interface{})
|
||||
for k, v := range repeatLoadEnvs {
|
||||
envs[k] = v
|
||||
}
|
||||
for k, v := range allEnvs {
|
||||
if _, exist := cfgs[k]; !exist {
|
||||
envs[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range envs {
|
||||
|
@ -94,5 +94,21 @@ func TestLoadFromEnv(t *testing.T) {
|
||||
err = LoadFromEnv(cfgs, false)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, extEndpoint, cfgs[common.ExtEndpoint])
|
||||
assert.Equal(t, nil, cfgs[common.LDAPURL])
|
||||
assert.Equal(t, ldapURL, cfgs[common.LDAPURL])
|
||||
|
||||
os.Clearenv()
|
||||
if err := os.Setenv("LDAP_URL", ldapURL); err != nil {
|
||||
t.Fatalf("failed to set env: %v", err)
|
||||
}
|
||||
if err := os.Setenv("EXT_ENDPOINT", extEndpoint); err != nil {
|
||||
t.Fatalf("failed to set env: %v", err)
|
||||
}
|
||||
|
||||
cfgs = map[string]interface{}{
|
||||
common.LDAPURL: "ldap_url",
|
||||
}
|
||||
err = LoadFromEnv(cfgs, false)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, extEndpoint, cfgs[common.ExtEndpoint])
|
||||
assert.Equal(t, "ldap_url", cfgs[common.LDAPURL])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user