Renamed vars and switched to use zerolog

This commit is contained in:
David Allen 2024-07-30 14:02:12 -06:00
parent 606a7b47cc
commit b27e6b6a73
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
7 changed files with 68 additions and 103 deletions

View file

@ -21,7 +21,7 @@ import (
"os/user"
magellan "github.com/OpenCHAMI/magellan/internal"
"github.com/OpenCHAMI/magellan/pkg/smd"
"github.com/OpenCHAMI/magellan/pkg/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -66,35 +66,6 @@ func Execute() {
}
}
// LoadAccessToken() tries to load a JWT string from an environment
// variable, file, or config in that order. If loading the token
// fails with one options, it will fallback to the next option until
// all options are exhausted.
//
// Returns a token as a string with no error if successful.
// Alternatively, returns an empty string with an error if a token is
// not able to be loaded.
func LoadAccessToken() (string, error) {
// try to load token from env var
testToken := os.Getenv("ACCESS_TOKEN")
if testToken != "" {
return testToken, nil
}
// try reading access token from a file
b, err := os.ReadFile(tokenPath)
if err == nil {
return string(b), nil
}
// TODO: try to load token from config
testToken = viper.GetString("access_token")
if testToken != "" {
return testToken, nil
}
return "", fmt.Errorf("failed toload token from environment variable, file, or config")
}
func init() {
currentUser, _ = user.Current()
cobra.OnInitialize(InitializeConfig)
@ -140,8 +111,8 @@ func SetDefaults() {
viper.SetDefault("scan.subnet-masks", []net.IP{})
viper.SetDefault("scan.disable-probing", false)
viper.SetDefault("collect.driver", []string{"redfish"})
viper.SetDefault("collect.host", smd.Host)
viper.SetDefault("collect.port", smd.Port)
viper.SetDefault("collect.host", client.Host)
viper.SetDefault("collect.port", client.Port)
viper.SetDefault("collect.user", "")
viper.SetDefault("collect.pass", "")
viper.SetDefault("collect.protocol", "https")