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 82da654
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions controllers/imagerepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ 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 82da654

Please sign in to comment.