From 07c785e294e70494ae6016d59749a71af3f74920 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 21 Jun 2018 10:30:20 -0400 Subject: MM-10730 Added support for empty environment variables to viper (#8973) --- vendor/github.com/mattermost/viper/viper.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'vendor/github.com/mattermost/viper/viper.go') diff --git a/vendor/github.com/mattermost/viper/viper.go b/vendor/github.com/mattermost/viper/viper.go index b9e165695..bb605594b 100644 --- a/vendor/github.com/mattermost/viper/viper.go +++ b/vendor/github.com/mattermost/viper/viper.go @@ -334,14 +334,14 @@ func (v *Viper) mergeWithEnvPrefix(in string) string { // rewriting keys many things, Ex: Get('someKey') -> some_key // (camel case to snake case for JSON keys perhaps) -// getEnv is a wrapper around os.Getenv which replaces characters in the original +// getEnv is a wrapper around os.LookupEnv which replaces characters in the original // key. This allows env vars which have different keys than the config object // keys. -func (v *Viper) getEnv(key string) string { +func (v *Viper) getEnv(key string) (string, bool) { if v.envKeyReplacer != nil { key = v.envKeyReplacer.Replace(key) } - return os.Getenv(key) + return os.LookupEnv(key) } // ConfigFileUsed returns the file used to populate the config registry. @@ -568,10 +568,10 @@ func (v *Viper) isPathShadowedInFlatMap(path []string, mi interface{}) string { // "foo.bar.baz" in a lower-priority map func (v *Viper) isPathShadowedInAutoEnv(path []string) string { var parentKey string - var val string + var ok bool for i := 1; i < len(path); i++ { parentKey = strings.Join(path[0:i], v.keyDelim) - if val = v.getEnv(v.mergeWithEnvPrefix(parentKey)); val != "" { + if _, ok = v.getEnv(v.mergeWithEnvPrefix(parentKey)); ok { return parentKey } } @@ -934,7 +934,7 @@ func (v *Viper) find(lcaseKey string) interface{} { if v.automaticEnvApplied { // even if it hasn't been registered, if automaticEnv is used, // check any Get request - if val = v.getEnv(v.mergeWithEnvPrefix(lcaseKey)); val != "" { + if val, ok := v.getEnv(v.mergeWithEnvPrefix(lcaseKey)); ok { return val } if nested && v.isPathShadowedInAutoEnv(path) != "" { @@ -943,7 +943,7 @@ func (v *Viper) find(lcaseKey string) interface{} { } envkey, exists := v.env[lcaseKey] if exists { - if val = v.getEnv(envkey); val != "" { + if val, ok := v.getEnv(envkey); ok { return val } } @@ -1682,8 +1682,8 @@ func (v *Viper) EnvSettings() map[string]interface{} { m := map[string]interface{}{} // start from the list of keys, and construct the map one value at a time for _, k := range v.AllKeys() { - value := v.getEnv(v.mergeWithEnvPrefix(k)) - if value == "" { + _, ok := v.getEnv(v.mergeWithEnvPrefix(k)) + if !ok { continue } path := strings.Split(k, v.keyDelim) -- cgit v1.2.3-1-g7c22