Skip to content

Commit

Permalink
more strict erroring around missing user/token
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Apr 20, 2020
1 parent b1d5264 commit 815f461
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
15 changes: 11 additions & 4 deletions command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,18 @@ func BasicClient() (*api.Client, error) {
opts = append(opts, apiVerboseLog())
}
opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", Version)))
if c, err := context.ParseDefaultConfig(); err == nil {
if token, err := c.Get(defaultHostname, "oauth_token"); err == nil {
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
}

c, err := context.ParseDefaultConfig()
if err != nil {
return nil, err
}

token, err := c.Get(defaultHostname, "oauth_token")
if token == "" || err != nil {
return nil, err
}

opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
return api.NewClient(opts...), nil
}

Expand Down
14 changes: 12 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ func (c *fsContext) AuthToken() (string, error) {
return "", err
}

return config.Get(defaultHostname, "oauth_token")
token, err := config.Get(defaultHostname, "token")
if token == "" || err != nil {
return "", err
}

return token, nil
}

func (c *fsContext) SetAuthToken(t string) {
Expand All @@ -203,7 +208,12 @@ func (c *fsContext) AuthLogin() (string, error) {
return "", err
}

return config.Get(defaultHostname, "user")
login, err := config.Get(defaultHostname, "user")
if login == "" || err != nil {
return "", err
}

return login, nil
}

func (c *fsContext) Branch() (string, error) {
Expand Down

0 comments on commit 815f461

Please sign in to comment.