Skip to content

Commit

Permalink
Discard and close body regardless of status code
Browse files Browse the repository at this point in the history
Signed-off-by: Somtochi Onyekwere <[email protected]>
  • Loading branch information
somtochiama committed Jan 20, 2022
1 parent 4ca33b4 commit 51c97e2
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions controllers/imagerepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ func getGCRLoginAuth(ctx context.Context) (authn.AuthConfig, error) {
if err != nil {
return authConfig, err
}
defer io.Copy(io.Discard, response.Body)
defer response.Body.Close()

if response.StatusCode != http.StatusOK {
return authConfig, fmt.Errorf("unexpected status from metadata service: %s", response.Status)
Expand All @@ -291,14 +293,6 @@ func getGCRLoginAuth(ctx context.Context) (authn.AuthConfig, error) {
return authConfig, err
}

if _, err := io.Copy(io.Discard, response.Body); err != nil {
return authConfig, err
}

if err := response.Body.Close(); err != nil {
return authConfig, err
}

authConfig = authn.AuthConfig{
Username: "oauth2accesstoken",
Password: accessToken.AccessToken,
Expand Down

0 comments on commit 51c97e2

Please sign in to comment.