Skip to content

Commit 64a19ee

Browse files
committed
Remove OAuth scopes checking logic from ssh-key commands
Scopes checking is now handled on the HTTP client level for all commands.
1 parent 693193f commit 64a19ee

File tree

4 files changed

+2
-24
lines changed

4 files changed

+2
-24
lines changed

pkg/cmd/ssh-key/add/add.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ func runAdd(opts *AddOptions) error {
8585

8686
err = SSHKeyUpload(httpClient, hostname, keyReader, opts.Title)
8787
if err != nil {
88-
if errors.Is(err, scopesError) {
89-
cs := opts.IO.ColorScheme()
90-
fmt.Fprint(opts.IO.ErrOut, "Error: insufficient OAuth scopes to list SSH keys\n")
91-
fmt.Fprintf(opts.IO.ErrOut, "Run the following to grant scopes: %s\n", cs.Bold("gh auth refresh -s write:public_key"))
92-
return cmdutil.SilentError
93-
}
9488
return err
9589
}
9690

pkg/cmd/ssh-key/add/http.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"github.com/cli/cli/v2/internal/ghinstance"
1313
)
1414

15-
var scopesError = errors.New("insufficient OAuth scopes")
16-
1715
func SSHKeyUpload(httpClient *http.Client, hostname string, keyFile io.Reader, title string) error {
1816
url := ghinstance.RESTPrefix(hostname) + "user/keys"
1917

@@ -43,9 +41,7 @@ func SSHKeyUpload(httpClient *http.Client, hostname string, keyFile io.Reader, t
4341
}
4442
defer resp.Body.Close()
4543

46-
if resp.StatusCode == 404 {
47-
return scopesError
48-
} else if resp.StatusCode > 299 {
44+
if resp.StatusCode > 299 {
4945
var httpError api.HTTPError
5046
err := api.HandleHTTPError(resp)
5147
if errors.As(err, &httpError) && isDuplicateError(&httpError) {

pkg/cmd/ssh-key/list/http.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package list
22

33
import (
44
"encoding/json"
5-
"errors"
65
"fmt"
76
"io/ioutil"
87
"net/http"
@@ -12,8 +11,6 @@ import (
1211
"github.com/cli/cli/v2/internal/ghinstance"
1312
)
1413

15-
var scopesError = errors.New("insufficient OAuth scopes")
16-
1714
type sshKey struct {
1815
Key string
1916
Title string
@@ -37,9 +34,7 @@ func userKeys(httpClient *http.Client, host, userHandle string) ([]sshKey, error
3734
}
3835
defer resp.Body.Close()
3936

40-
if resp.StatusCode == 404 {
41-
return nil, scopesError
42-
} else if resp.StatusCode > 299 {
37+
if resp.StatusCode > 299 {
4338
return nil, api.HandleHTTPError(resp)
4439
}
4540

pkg/cmd/ssh-key/list/list.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package list
22

33
import (
4-
"errors"
54
"fmt"
65
"net/http"
76
"time"
@@ -59,12 +58,6 @@ func listRun(opts *ListOptions) error {
5958

6059
sshKeys, err := userKeys(apiClient, host, "")
6160
if err != nil {
62-
if errors.Is(err, scopesError) {
63-
cs := opts.IO.ColorScheme()
64-
fmt.Fprint(opts.IO.ErrOut, "Error: insufficient OAuth scopes to list SSH keys\n")
65-
fmt.Fprintf(opts.IO.ErrOut, "Run the following to grant scopes: %s\n", cs.Bold("gh auth refresh -s read:public_key"))
66-
return cmdutil.SilentError
67-
}
6861
return err
6962
}
7063

0 commit comments

Comments
 (0)