Skip to content

Commit bbb059f

Browse files
committed
feat: add projectSlug query to enable/disable spike protection endpoint
1 parent 90f2525 commit bbb059f

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

sentry/sentry.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net/http"
1211
"net/url"
1312
"reflect"
@@ -357,7 +356,7 @@ func CheckResponse(r *http.Response) error {
357356
}
358357

359358
errorResponse := &ErrorResponse{Response: r}
360-
data, err := ioutil.ReadAll(r.Body)
359+
data, err := io.ReadAll(r.Body)
361360
if err == nil && data != nil {
362361
apiError := new(APIError)
363362
json.Unmarshal(data, apiError)
@@ -368,7 +367,7 @@ func CheckResponse(r *http.Response) error {
368367
}
369368
}
370369
// Re-populate error response body.
371-
r.Body = ioutil.NopCloser(bytes.NewBuffer(data))
370+
r.Body = io.NopCloser(bytes.NewBuffer(data))
372371

373372
switch {
374373
case r.StatusCode == http.StatusTooManyRequests &&

sentry/sentry_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/httptest"
1010
"net/url"
@@ -272,7 +272,7 @@ func TestCheckResponse(t *testing.T) {
272272
res := &http.Response{
273273
Request: &http.Request{},
274274
StatusCode: http.StatusBadRequest,
275-
Body: ioutil.NopCloser(strings.NewReader(tc.body)),
275+
Body: io.NopCloser(strings.NewReader(tc.body)),
276276
}
277277

278278
err := CheckResponse(res)
@@ -313,7 +313,7 @@ func TestCheckResponse_rateLimit(t *testing.T) {
313313
Request: &http.Request{},
314314
StatusCode: http.StatusTooManyRequests,
315315
Header: http.Header{},
316-
Body: ioutil.NopCloser(strings.NewReader(`{"detail": "Rate limit exceeded"}`)),
316+
Body: io.NopCloser(strings.NewReader(`{"detail": "Rate limit exceeded"}`)),
317317
}
318318
tc.addHeaders(res)
319319

sentry/spike_protections.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ import (
99
type SpikeProtectionsService service
1010

1111
type SpikeProtectionParams struct {
12-
Projects []string `json:"projects"`
12+
ProjectSlug string `json:"-" url:"projectSlug,omitempty"`
13+
Projects []string `json:"projects" url:"-"`
1314
}
1415

1516
func (s *SpikeProtectionsService) Enable(ctx context.Context, organizationSlug string, params *SpikeProtectionParams) (*Response, error) {
1617
u := fmt.Sprintf("0/organizations/%v/spike-protections/", organizationSlug)
18+
u, err := addQuery(u, params)
19+
if err != nil {
20+
return nil, err
21+
}
22+
1723
req, err := s.client.NewRequest(http.MethodPost, u, params)
1824
if err != nil {
1925
return nil, err
@@ -24,6 +30,11 @@ func (s *SpikeProtectionsService) Enable(ctx context.Context, organizationSlug s
2430

2531
func (s *SpikeProtectionsService) Disable(ctx context.Context, organizationSlug string, params *SpikeProtectionParams) (*Response, error) {
2632
u := fmt.Sprintf("0/organizations/%v/spike-protections/", organizationSlug)
33+
u, err := addQuery(u, params)
34+
if err != nil {
35+
return nil, err
36+
}
37+
2738
req, err := s.client.NewRequest(http.MethodDelete, u, params)
2839
if err != nil {
2940
return nil, err

0 commit comments

Comments
 (0)