From bd106408462ecef70debf51f1e6179de950c5812 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 11 Oct 2019 18:21:04 -0700 Subject: [PATCH] Fix logger and audit http endpoint config lookup --- cmd/logger/config.go | 36 ++++++++++++++++++------------------ pkg/env/env.go | 5 ++++- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/cmd/logger/config.go b/cmd/logger/config.go index 45a3afcf9..43a802ba2 100644 --- a/cmd/logger/config.go +++ b/cmd/logger/config.go @@ -77,32 +77,32 @@ func NewConfig() Config { // LookupConfig - lookup logger config, override with ENVs if set. func LookupConfig(cfg Config) (Config, error) { + if cfg.HTTP == nil { + cfg.HTTP = make(map[string]HTTP) + } + if cfg.Audit == nil { + cfg.Audit = make(map[string]HTTP) + } envs := env.List(EnvLoggerHTTPEndpoint) - for _, e := range envs { - target := strings.TrimPrefix(e, EnvLoggerHTTPEndpoint) - if target == "" { + for _, k := range envs { + target := strings.TrimPrefix(k, EnvLoggerHTTPEndpoint+defaultTarget) + if target == EnvLoggerHTTPEndpoint { target = defaultTarget } - _, ok := cfg.HTTP[target] - if ok { - cfg.HTTP[target] = HTTP{ - Enabled: true, - Endpoint: env.Get(e, cfg.HTTP[target].Endpoint), - } + cfg.HTTP[target] = HTTP{ + Enabled: true, + Endpoint: env.Get(k, cfg.HTTP[target].Endpoint), } } aenvs := env.List(EnvAuditLoggerHTTPEndpoint) - for _, e := range aenvs { - target := strings.TrimPrefix(e, EnvAuditLoggerHTTPEndpoint) - if target == "" { + for _, k := range aenvs { + target := strings.TrimPrefix(k, EnvAuditLoggerHTTPEndpoint+defaultTarget) + if target == EnvAuditLoggerHTTPEndpoint { target = defaultTarget } - _, ok := cfg.Audit[target] - if ok { - cfg.Audit[target] = HTTP{ - Enabled: true, - Endpoint: env.Get(e, cfg.Audit[target].Endpoint), - } + cfg.Audit[target] = HTTP{ + Enabled: true, + Endpoint: env.Get(k, cfg.Audit[target].Endpoint), } } diff --git a/pkg/env/env.go b/pkg/env/env.go index ed62309bb..1b3c7a56c 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -27,7 +27,10 @@ func Lookup(key string) (string, bool) { return os.LookupEnv(key) } func List(prefix string) (envs []string) { for _, env := range os.Environ() { if strings.HasPrefix(env, prefix) { - envs = append(envs, env) + values := strings.SplitN(env, "=", 2) + if len(values) == 2 { + envs = append(envs, values[0]) + } } } return envs