From e25d3e04a55d0aeb8d7ed4bfe1ab12c8c7d7d836 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Tue, 8 Sep 2020 15:52:52 -0400 Subject: [PATCH] config: Small LoadConfig() cleanup Just a small cleanup of the LoadConfig() code. The two return statements can be simplified to a single return. Signed-off-by: Prarit Bhargava --- internal/config/config.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index ec292841..f7a10843 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -230,14 +230,12 @@ func LoadConfig() (string, string, string, string, bool) { tlsSkipVerify := viper.GetBool("tls.skip_verify") ca_file := viper.GetString("tls.ca_file") - if host != "" && user != "" && token != "" { - return host, user, token, ca_file, tlsSkipVerify - } - - user = getUser(host, token, tlsSkipVerify) - if strings.TrimSpace(os.Getenv("LAB_CORE_TOKEN")) == "" && strings.TrimSpace(os.Getenv("LAB_CORE_HOST")) == "" { - viper.Set("core.user", user) - viper.WriteConfig() + if user == "" { + user = getUser(host, token, tlsSkipVerify) + if strings.TrimSpace(os.Getenv("LAB_CORE_TOKEN")) == "" && strings.TrimSpace(os.Getenv("LAB_CORE_HOST")) == "" { + viper.Set("core.user", user) + viper.WriteConfig() + } } return host, user, token, ca_file, tlsSkipVerify