diff --git a/pkg/config/config.go b/pkg/config/config.go index f76b7ed..bc89042 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -56,11 +56,6 @@ type Config struct { func (c *Config) GetConfigFolder(xdgPath string) string { configPath := xdgPath - log.WithFields(log.Fields{ - "prefix": "config.Config.GetProfilesFolder", - "path": configPath, - }).Debug("Using profiles file") - if configPath == "" { home, err := homedir.Dir() if err != nil { @@ -71,6 +66,11 @@ func (c *Config) GetConfigFolder(xdgPath string) string { configPath = filepath.Join(home, ".config") } + log.WithFields(log.Fields{ + "prefix": "config.Config.GetProfilesFolder", + "path": configPath, + }).Debug("Using profiles folder") + return filepath.Join(configPath, "hookdeck") } @@ -78,6 +78,20 @@ func (c *Config) GetConfigFolder(xdgPath string) string { func (c *Config) InitConfig() { c.Profile.Config = c + // Set log level + switch c.LogLevel { + case "debug": + log.SetLevel(log.DebugLevel) + case "info": + log.SetLevel(log.InfoLevel) + case "warn": + log.SetLevel(log.WarnLevel) + case "error": + log.SetLevel(log.ErrorLevel) + default: + log.Fatalf("Unrecognized log level value: %s. Expected one of debug, info, warn, error.", c.LogLevel) + } + logFormatter := &prefixed.TextFormatter{ FullTimestamp: true, TimestampFormat: time.RFC1123, @@ -102,7 +116,7 @@ func (c *Config) InitConfig() { log.WithFields(log.Fields{ "prefix": "config.Config.InitConfig", "path": c.GlobalConfig.ConfigFileUsed(), - }).Debug("Using profiles file") + }).Debug("Using global profiles file") } // Read local config @@ -127,7 +141,7 @@ func (c *Config) InitConfig() { log.WithFields(log.Fields{ "prefix": "config.Config.InitConfig", "path": c.LocalConfig.ConfigFileUsed(), - }).Debug("Using profiles file") + }).Debug("Using local profiles file") } // Construct the config struct @@ -155,20 +169,6 @@ func (c *Config) InitConfig() { } log.SetFormatter(logFormatter) - - // Set log level - switch c.LogLevel { - case "debug": - log.SetLevel(log.DebugLevel) - case "info": - log.SetLevel(log.InfoLevel) - case "warn": - log.SetLevel(log.WarnLevel) - case "error": - log.SetLevel(log.ErrorLevel) - default: - log.Fatalf("Unrecognized log level value: %s. Expected one of debug, info, warn, error.", c.LogLevel) - } } // EditConfig opens the configuration file in the default editor. @@ -250,6 +250,12 @@ func (c *Config) WriteGlobalConfig() error { if err := makePath(c.GlobalConfig.ConfigFileUsed()); err != nil { return err } + + log.WithFields(log.Fields{ + "prefix": "config.Config.WriteGlobalConfig", + "path": c.GlobalConfig.ConfigFileUsed(), + }).Debug("Writing global config") + return c.GlobalConfig.WriteConfig() } diff --git a/pkg/login/client_login.go b/pkg/login/client_login.go index 19152b8..00a2c5a 100644 --- a/pkg/login/client_login.go +++ b/pkg/login/client_login.go @@ -6,11 +6,12 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "net/url" "os" + log "github.com/sirupsen/logrus" + "github.com/briandowns/spinner" "github.com/hookdeck/hookdeck-cli/pkg/ansi" @@ -36,6 +37,11 @@ func Login(config *config.Config, input io.Reader) error { var s *spinner.Spinner if config.Profile.APIKey != "" { + log.WithFields(log.Fields{ + "prefix": "login.Login", + "APIKey": config.Profile.APIKey, + }).Debug("Logging in with API key") + s = ansi.StartNewSpinner("Verifying credentials...", os.Stdout) response, err := ValidateKey(config.APIBaseURL, config.Profile.APIKey, config.Profile.TeamID) if err != nil { @@ -45,6 +51,13 @@ func Login(config *config.Config, input io.Reader) error { message := SuccessMessage(response.UserName, response.UserEmail, response.OrganizationName, response.TeamName, response.TeamMode == "console") ansi.StopSpinner(s, message, os.Stdout) + if err = config.Profile.SaveProfile(false); err != nil { + return err + } + if err = config.Profile.UseProfile(); err != nil { + return err + } + return nil }