From 593c56d91a7736944030f7c37e9cfe45531b8586 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Thu, 11 Nov 2021 16:18:42 -0800 Subject: [PATCH] Fix viper configurations --- cmd/lasso/cmd/root.go | 2 ++ cmd/lassoctl/cmd/root.go | 13 ++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cmd/lasso/cmd/root.go b/cmd/lasso/cmd/root.go index a973674..ee7d1de 100644 --- a/cmd/lasso/cmd/root.go +++ b/cmd/lasso/cmd/root.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" "net/http" + "strings" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -58,6 +59,7 @@ func initConfig() { viper.SetConfigName("lasso") } + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.SetEnvPrefix("lasso") viper.AutomaticEnv() // Read in environment variables that match diff --git a/cmd/lassoctl/cmd/root.go b/cmd/lassoctl/cmd/root.go index e60d2e4..bb2ba52 100644 --- a/cmd/lassoctl/cmd/root.go +++ b/cmd/lassoctl/cmd/root.go @@ -19,7 +19,7 @@ package cmd import ( "net" "net/http" - "os" + "strings" "github.com/abiosoft/ishell" "github.com/mitchellh/mapstructure" @@ -57,17 +57,12 @@ func initConfig() { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { - // Find home directory. - home, err := os.UserHomeDir() - cobra.CheckErr(err) - - // Search config in home directory with name ".lassoctl" (without extension). - viper.AddConfigPath(".") - viper.AddConfigPath(home) - viper.SetConfigType("toml") + viper.SetConfigType("/etc") viper.SetConfigName("lassoctl") } + viper.SetEnvPrefix("lassoctl") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in.