Skip to content

Commit

Permalink
fix (engine): load env for commented key too
Browse files Browse the repository at this point in the history
Load Environment value even if the key is commented in configuration.

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored and fsamin committed Sep 24, 2017
1 parent 52f1eb7 commit 80d6baf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:

cds-api:
image: ovhcom/cds-engine:latest
command: sh -c "mv cds-worker-linux-amd64 worker && ./cds-engine-linux-amd64 start api"
command: sh -c "/app/cds-engine-linux-amd64 start api"
volumes:
- cds-artifacts-volume:/app/artifacts
environment:
Expand Down Expand Up @@ -70,7 +70,7 @@ services:
image: ovhcom/cds-engine:latest
command: sh -c "wget http://cds-api:8081/download/cds-worker-linux-amd64 -O worker && chmod +x worker && PATH=$PATH:. cds-engine-linux-amd64 start hatchery:local"
environment:
CDS_HATCHERY_LOCAL_COMMONCONFIGURATION_TOKEN: changeitchangeitchangeitchangeitchangeitchangeitchangeitchangeit
CDS_HATCHERY_LOCAL_COMMONCONFIGURATION_API_TOKEN: changeitchangeitchangeitchangeitchangeitchangeitchangeitchangeit
CDS_HATCHERY_LOCAL_COMMONCONFIGURATION_API_HTTP_URL: http://cds-api:8081
links:
- cds-api
Expand Down
2 changes: 1 addition & 1 deletion engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// config reads in config file and ENV variables if set.
func config() {
for k := range AsEnvVariables(conf, "") {
for k := range AsEnvVariables(conf, "", false) {
viper.BindEnv(strings.ToLower(strings.Replace(k, "_", ".", -1)), "CDS_"+k)
}

Expand Down
2 changes: 1 addition & 1 deletion engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Comming soon...`,
}
fmt.Println(string(btes))
} else {
m := AsEnvVariables(conf, "cds")
m := AsEnvVariables(conf, "cds", true)
keys := []string{}

for k := range m {
Expand Down
10 changes: 6 additions & 4 deletions engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Service interface {
CheckConfiguration(cfg interface{}) error
}

func AsEnvVariables(o interface{}, prefix string) map[string]string {
func AsEnvVariables(o interface{}, prefix string, skipCommented bool) map[string]string {
r := map[string]string{}
prefix = strings.ToUpper(prefix)
delim := "_"
Expand All @@ -54,11 +54,13 @@ func AsEnvVariables(o interface{}, prefix string) map[string]string {
}
fields := structs.Fields(o)
for _, f := range fields {
if commented, _ := strconv.ParseBool(f.Tag("commented")); commented {
continue
if skipCommented {
if commented, _ := strconv.ParseBool(f.Tag("commented")); commented {
continue
}
}
if structs.IsStruct(f.Value()) {
rf := AsEnvVariables(f.Value(), prefix+delim+f.Name())
rf := AsEnvVariables(f.Value(), prefix+delim+f.Name(), skipCommented)
for k, v := range rf {
r[k] = v
}
Expand Down

0 comments on commit 80d6baf

Please sign in to comment.