From 80d6baff3c076a3fd1438cd5f91a2df68cc27b4c Mon Sep 17 00:00:00 2001 From: Yvonnick Esnault Date: Sat, 23 Sep 2017 19:43:30 +0200 Subject: [PATCH] fix (engine): load env for commented key too Load Environment value even if the key is commented in configuration. Signed-off-by: Yvonnick Esnault --- docker-compose.yml | 4 ++-- engine/config.go | 2 +- engine/main.go | 2 +- engine/types.go | 10 ++++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 46b6f11815..095176cbd7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: @@ -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 diff --git a/engine/config.go b/engine/config.go index 61ec4ae148..a997bba1c8 100644 --- a/engine/config.go +++ b/engine/config.go @@ -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) } diff --git a/engine/main.go b/engine/main.go index b57885a357..9c454b092a 100644 --- a/engine/main.go +++ b/engine/main.go @@ -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 { diff --git a/engine/types.go b/engine/types.go index 4e6b0c3255..872cb07edc 100644 --- a/engine/types.go +++ b/engine/types.go @@ -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 := "_" @@ -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 }