From 0f1e8db4c53521c9dc5cb34e6aafe6e43592b187 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 6 Sep 2024 15:53:34 -0700 Subject: [PATCH] all 2xx status codes to be success for audit (#20394) --- .github/workflows/vulncheck.yml | 2 +- internal/event/target/webhook.go | 12 +++++++----- internal/logger/target/http/http.go | 8 +++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/vulncheck.yml b/.github/workflows/vulncheck.yml index 9189adc37..ebdea0ef3 100644 --- a/.github/workflows/vulncheck.yml +++ b/.github/workflows/vulncheck.yml @@ -21,7 +21,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.22.5 + go-version: 1.22.7 - name: Get official govulncheck run: go install golang.org/x/vuln/cmd/govulncheck@latest shell: bash diff --git a/internal/event/target/webhook.go b/internal/event/target/webhook.go index 31ca09d9b..4935b4061 100644 --- a/internal/event/target/webhook.go +++ b/internal/event/target/webhook.go @@ -196,13 +196,15 @@ func (target *WebhookTarget) send(eventData event.Event) error { if err != nil { return err } - defer xhttp.DrainBody(resp.Body) + xhttp.DrainBody(resp.Body) - if resp.StatusCode < 200 || resp.StatusCode > 299 { - return fmt.Errorf("sending event failed with %v", resp.Status) + if resp.StatusCode >= 200 && resp.StatusCode <= 299 { + // accepted HTTP status codes. + return nil + } else if resp.StatusCode == http.StatusForbidden { + return fmt.Errorf("%s returned '%s', please check if your auth token is correctly set", target.args.Endpoint, resp.Status) } - - return nil + return fmt.Errorf("%s returned '%s', please check your endpoint configuration", target.args.Endpoint, resp.Status) } // SendFromStore - reads an event from store and sends it to webhook. diff --git a/internal/logger/target/http/http.go b/internal/logger/target/http/http.go index 8e2a1e2f1..2b37db57e 100644 --- a/internal/logger/target/http/http.go +++ b/internal/logger/target/http/http.go @@ -266,15 +266,13 @@ func (h *Target) send(ctx context.Context, payload []byte, payloadCount int, pay // Drain any response. xhttp.DrainBody(resp.Body) - switch resp.StatusCode { - case http.StatusOK, http.StatusCreated, http.StatusAccepted, http.StatusNoContent: + if resp.StatusCode >= 200 && resp.StatusCode <= 299 { // accepted HTTP status codes. return nil - case http.StatusForbidden: + } else if resp.StatusCode == http.StatusForbidden { return fmt.Errorf("%s returned '%s', please check if your auth token is correctly set", h.Endpoint(), resp.Status) - default: - return fmt.Errorf("%s returned '%s', please check your endpoint configuration", h.Endpoint(), resp.Status) } + return fmt.Errorf("%s returned '%s', please check your endpoint configuration", h.Endpoint(), resp.Status) } func (h *Target) startQueueProcessor(ctx context.Context, mainWorker bool) {