From 0a6b96cb40d9dd5acca7e366df9cd14fa4eff6a7 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 9 Apr 2018 12:16:11 -0400 Subject: MM-9849 Added tracking of which settings are set through environment variables (#8586) * MM-9849 Added tracking of which settings are set through environment variables * Removed old version of viper * Added forked version of viper * Fixed unit tests * Fixed more unit tests * Removed copy from App.GetEnvironmentConfig --- vendor/github.com/spf13/viper/nohup.out | 1 - vendor/github.com/spf13/viper/viper.go | 38 +++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) delete mode 100644 vendor/github.com/spf13/viper/nohup.out (limited to 'vendor') diff --git a/vendor/github.com/spf13/viper/nohup.out b/vendor/github.com/spf13/viper/nohup.out deleted file mode 100644 index 8973bf27b..000000000 --- a/vendor/github.com/spf13/viper/nohup.out +++ /dev/null @@ -1 +0,0 @@ -QProcess::start: Process is already running diff --git a/vendor/github.com/spf13/viper/viper.go b/vendor/github.com/spf13/viper/viper.go index ad8a03729..b9e165695 100644 --- a/vendor/github.com/spf13/viper/viper.go +++ b/vendor/github.com/spf13/viper/viper.go @@ -1675,6 +1675,26 @@ func (v *Viper) AllSettings() map[string]interface{} { return m } +// EnvSettings returns a map[string]interface{} containing all settings set +// through environment variables. +func EnvSettings() map[string]interface{} { return v.EnvSettings() } +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 == "" { + continue + } + path := strings.Split(k, v.keyDelim) + lastKey := strings.ToLower(path[len(path)-1]) + deepestMap := deepSearch(m, path[0:len(path)-1]) + // set innermost value + deepestMap[lastKey] = true + } + return m +} + // SetFs sets the filesystem to use to read configuration. func SetFs(fs afero.Fs) { v.SetFs(fs) } func (v *Viper) SetFs(fs afero.Fs) { @@ -1720,18 +1740,14 @@ func (v *Viper) getConfigType() string { } func (v *Viper) getConfigFile() (string, error) { - // if explicitly set, then use it - if v.configFile != "" { - return v.configFile, nil - } - - cf, err := v.findConfigFile() - if err != nil { - return "", err + if v.configFile == "" { + cf, err := v.findConfigFile() + if err != nil { + return "", err + } + v.configFile = cf } - - v.configFile = cf - return v.getConfigFile() + return v.configFile, nil } func (v *Viper) searchInPath(in string) (filename string) { -- cgit v1.2.3-1-g7c22