diff --git a/api/client.go b/api/client.go index 2058eb44b..2556f6317 100644 --- a/api/client.go +++ b/api/client.go @@ -200,18 +200,18 @@ type MissingScopesError struct { error } -func (c Client) HasMinimumScopes(hostname string) (bool, error) { +func (c Client) HasMinimumScopes(hostname string) error { apiEndpoint := ghinstance.RESTPrefix(hostname) req, err := http.NewRequest("GET", apiEndpoint, nil) if err != nil { - return false, err + return err } req.Header.Set("Content-Type", "application/json; charset=utf-8") res, err := c.http.Do(req) if err != nil { - return false, err + return err } defer func() { @@ -222,7 +222,7 @@ func (c Client) HasMinimumScopes(hostname string) (bool, error) { }() if res.StatusCode != 200 { - return false, handleHTTPError(res) + return handleHTTPError(res) } hasScopes := strings.Split(res.Header.Get("X-Oauth-Scopes"), ",") @@ -247,10 +247,10 @@ func (c Client) HasMinimumScopes(hostname string) (bool, error) { } if len(errorMsgs) > 0 { - return false, &MissingScopesError{error: errors.New(strings.Join(errorMsgs, ";"))} + return &MissingScopesError{error: errors.New(strings.Join(errorMsgs, ";"))} } - return true, nil + return nil } // GraphQL performs a GraphQL request and parses the response diff --git a/pkg/cmd/auth/client/client.go b/pkg/cmd/auth/client/client.go index a3652e45d..bacde0b82 100644 --- a/pkg/cmd/auth/client/client.go +++ b/pkg/cmd/auth/client/client.go @@ -14,7 +14,7 @@ func ValidateHostCfg(hostname string, cfg config.Config) error { return err } - _, err = apiClient.HasMinimumScopes(hostname) + err = apiClient.HasMinimumScopes(hostname) if err != nil { return fmt.Errorf("could not validate token: %w", err) } diff --git a/pkg/cmd/auth/status/status.go b/pkg/cmd/auth/status/status.go index 95ba2d782..8a761fd32 100644 --- a/pkg/cmd/auth/status/status.go +++ b/pkg/cmd/auth/status/status.go @@ -84,7 +84,7 @@ func statusRun(opts *StatusOptions) error { return err } - _, err = apiClient.HasMinimumScopes(hostname) + err = apiClient.HasMinimumScopes(hostname) if err != nil { var missingScopes *api.MissingScopesError if errors.As(err, &missingScopes) { @@ -145,7 +145,7 @@ func statusRun(opts *StatusOptions) error { statusInfo[hostname] = append(statusInfo[hostname], fmt.Sprintf(x, ys...)) } - _, err = apiClient.HasMinimumScopes(hostname) + err = apiClient.HasMinimumScopes(hostname) if err != nil { var missingScopes *api.MissingScopesError if errors.As(err, &missingScopes) {