From b6b16cf5048dd79a2071f300f75ae99da4c956c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Sibiril?= <81782+aureliensibiril@users.noreply.github.com> Date: Sun, 12 Jul 2026 19:42:04 +0200 Subject: [PATCH] Check status before decoding Google Analytics accounts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ListGoogleAnalyticsOrganizations decoded the response body into the success struct before inspecting the HTTP status, unlike every other lister in the file. Check the status first so a non-2xx no longer wastes a decode against an error body and the ordering matches the sibling functions. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com> --- pkg/accessreview/drivers/organizations.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/accessreview/drivers/organizations.go b/pkg/accessreview/drivers/organizations.go index 93e883c5d..bf96c985f 100644 --- a/pkg/accessreview/drivers/organizations.go +++ b/pkg/accessreview/drivers/organizations.go @@ -508,6 +508,12 @@ func ListGoogleAnalyticsOrganizations(ctx context.Context, httpClient *http.Clie return nil, fmt.Errorf("cannot fetch google analytics accounts: %w", err) } + if resp.StatusCode != http.StatusOK { + _ = resp.Body.Close() + + return nil, fmt.Errorf("cannot fetch google analytics accounts: unexpected status %d", resp.StatusCode) + } + var out struct { Accounts []struct { Name string `json:"name"` @@ -517,13 +523,8 @@ func ListGoogleAnalyticsOrganizations(ctx context.Context, httpClient *http.Clie } decodeErr := json.NewDecoder(resp.Body).Decode(&out) - status := resp.StatusCode _ = resp.Body.Close() - if status != http.StatusOK { - return nil, fmt.Errorf("cannot fetch google analytics accounts: unexpected status %d", status) - } - if decodeErr != nil { return nil, fmt.Errorf("cannot decode google analytics accounts response: %w", decodeErr) }