Skip to content

Commit

Permalink
config: check mandatory options before allowing any action
Browse files Browse the repository at this point in the history
In case some of the config files are present (user or worktree) but without
any content, 'lab' fails while trying to get the user because 'host' is empty.
Another errors occur in case 'core.user' and 'core.token' are present, but
'core.host' is left empty: gitlab call to the API fails.

With this patch we make sure we have the minimal config options set before
lab tries to execute anything else: even if after all attempts to set the
mandatory options they still are empty: 'core.host' string is set to the
default GitLab host instead and for 'core.token' we error out the default
user authentication error message.

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Nov 14, 2020
1 parent 9bd0295 commit a922751
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,16 @@ func LoadMainConfig() (string, string, string, string, bool) {
}
}

host = MainConfig.GetString("core.host")
token = GetToken()
if !MainConfig.IsSet("core.host") {
host = defaultGitLabHost
} else {
host = MainConfig.GetString("core.host")
}

if token = GetToken(); token == "" {
UserConfigError()
}

caFile := MainConfig.GetString("tls.ca_file")
tlsSkipVerify := MainConfig.GetBool("tls.skip_verify")
user = getUser(host, token, tlsSkipVerify)
Expand Down

0 comments on commit a922751

Please sign in to comment.