Skip to content

Commit

Permalink
config: Small LoadConfig() cleanup
Browse files Browse the repository at this point in the history
Just a small cleanup of the LoadConfig() code.  The two return statements
can be simplified to a single return.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Sep 8, 2020
1 parent 146904c commit e25d3e0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e25d3e0

Please sign in to comment.