From d3fc8c1f0369d285086c2878936ad49a25c2561c Mon Sep 17 00:00:00 2001 From: Seokho Son Date: Tue, 30 Apr 2024 22:32:13 +0900 Subject: [PATCH] Fix startup err from the new credential --- scripts/init/init.sh | 12 ++++++++++++ src/main.go | 31 +++++++++++++++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/scripts/init/init.sh b/scripts/init/init.sh index e1dc0cf2e..7b502f7de 100755 --- a/scripts/init/init.sh +++ b/scripts/init/init.sh @@ -2,6 +2,18 @@ SCRIPT_DIR=$(cd $(dirname "$0") && pwd) +# Check if python3-venv is installed +if ! dpkg -s python3-venv &> /dev/null; then + echo "python3-venv package is not installed. Installing..." + sudo apt-get update && sudo apt-get install python3-venv + if [ $? -ne 0 ]; then + echo "Failed to install python3-venv. Please install it manually." + exit 1 + fi +else + echo "python3-venv package is already installed." +fi + echo "Creating and activating the virtual environment..." python3 -m venv "$SCRIPT_DIR/initPyEnv" source "$SCRIPT_DIR/initPyEnv/bin/activate" diff --git a/src/main.go b/src/main.go index 8ab747622..5e6efecf2 100644 --- a/src/main.go +++ b/src/main.go @@ -20,6 +20,7 @@ import ( "flag" "fmt" "os" + "os/user" "strconv" "sync" "time" @@ -180,27 +181,29 @@ func setConfig() { } // Load credentials + usr, err := user.Current() + if err != nil { + log.Error().Err(err).Msg("") + } + credPath := usr.HomeDir + "/.cloud-barista" credViper := viper.New() - fileName = "cred" - credViper.AddConfigPath(".") - credViper.AddConfigPath("./conf/.cred/") - credViper.AddConfigPath("../conf/.cred/") + fileName = "credentials" + credViper.AddConfigPath(credPath) credViper.SetConfigName(fileName) credViper.SetConfigType("yaml") err = credViper.ReadInConfig() if err != nil { - panic(fmt.Errorf("fatal error reading credential file: %w", err)) - } - - log.Info().Msg(credViper.ConfigFileUsed()) - err = credViper.Unmarshal(&common.RuntimeCredential) - if err != nil { - log.Error().Err(err).Msg("") - panic(err) + log.Info().Err(err).Msg("") + } else { + log.Info().Msg(credViper.ConfigFileUsed()) + err = credViper.Unmarshal(&common.RuntimeCredential) + if err != nil { + log.Error().Err(err).Msg("") + panic(err) + } + common.PrintCredentialInfo(common.RuntimeCredential) } - common.PrintCredentialInfo(common.RuntimeCredential) - // err = common.RegisterAllCloudInfo() // if err != nil { // log.Error().Err(err).Msg("Failed to register credentials")