Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
change: some more error handling for fetching pubkeys from gh API (#2183
Browse files Browse the repository at this point in the history
)

- this will surface rate-limiting errors to the administrators via
  controller logs

Signed-off-by: Thorsten Klein <[email protected]>
  • Loading branch information
iwilltry42 authored Oct 12, 2023
1 parent 5ec8609 commit 08c68cf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cosign/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ type GitHubPublicKey struct {
func getGitHubPublicKeys(username string) ([]GitHubPublicKey, error) {
logrus.Debugf("Getting public keys for GitHub user %s", username)
url := fmt.Sprintf("https://api.github.com/users/%s/keys", username)
resp, err := http.Get(url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("unexpected status code %d (%s) from GitHub API: %s", resp.StatusCode, resp.Status, string(body))
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
Expand Down

0 comments on commit 08c68cf

Please sign in to comment.