From 3d7e9c4b92c4cba173a9542b7bf4f4cb63f592dd Mon Sep 17 00:00:00 2001 From: Michal Wojcik Date: Thu, 3 Oct 2024 13:26:12 +0200 Subject: [PATCH 01/12] DXE-4233 Changelog boilerplate --- CHANGELOG.md | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eea76a86..d3bd456d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,102 @@ # RELEASE NOTES + +## X.X.X (X X, X) + +#### BREAKING CHANGES: + + + + + + + + + + + + + + + + + + + + + + + +#### FEATURES/ENHANCEMENTS: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#### BUG FIXES: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## 9.0.0 (Oct 3, 2024) From 906fbb62eb926e9291dc926525f99371c99dae23 Mon Sep 17 00:00:00 2001 From: Piotr Bartosik Date: Tue, 15 Oct 2024 12:08:24 +0000 Subject: [PATCH 02/12] DXE-4297 Use fixed version of build dependencies --- Makefile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b24fff07..feda883d 100644 --- a/Makefile +++ b/Makefile @@ -24,22 +24,19 @@ $(GOIMPORTS): | $(BIN) ; $(info $(M) Installing goimports $(GOIMPORTS_VERSION).. $(BIN): @mkdir -p $@ $(BIN)/%: | $(BIN) ; $(info $(M) Building $(PACKAGE)...) - $Q tmp=$$(mktemp -d); \ - env GO111MODULE=off GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(PACKAGE) \ - || ret=$$?; \ - rm -rf $$tmp ; exit $$ret + env GOBIN=$(BIN) $(GO) install $(PACKAGE) GOLINT = $(BIN)/golint $(BIN)/golint: PACKAGE=golang.org/x/lint/golint GOCOV = $(BIN)/gocov -$(BIN)/gocov: PACKAGE=github.com/axw/gocov/... +$(BIN)/gocov: PACKAGE=github.com/axw/gocov/gocov@v1.1.0 GOCOVXML = $(BIN)/gocov-xml -$(BIN)/gocov-xml: PACKAGE=github.com/AlekSi/gocov-xml +$(BIN)/gocov-xml: PACKAGE=github.com/AlekSi/gocov-xml@v1.1.0 GOJUNITREPORT = $(BIN)/go-junit-report -$(BIN)/go-junit-report: PACKAGE=github.com/jstemmer/go-junit-report +$(BIN)/go-junit-report: PACKAGE=github.com/jstemmer/go-junit-report/v2@v2.1.0 GOLANGCILINT = $(BIN)/golangci-lint $(BIN)/golangci-lint: ; $(info $(M) Installing golangci-lint...) @ From c3731e7fc3477bc4399ce0d445982dc514af4c16 Mon Sep 17 00:00:00 2001 From: Michal Mazur Date: Tue, 29 Oct 2024 11:49:36 +0000 Subject: [PATCH 03/12] DXE-4204 fix drift detection for deleted access key --- CHANGELOG.md | 3 +- pkg/cloudaccess/access_key_test.go | 18 +++++ pkg/cloudaccess/access_key_version_test.go | 86 +++++++++++++++++++++- pkg/cloudaccess/errors.go | 9 +++ pkg/cloudaccess/errors_test.go | 4 +- 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3bd456d..08f166ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,7 +66,8 @@ #### BUG FIXES: - +* Cloud Access + * Added custom error `ErrAccessKeyNotFound` to easier verify if provided access key does not exist. diff --git a/pkg/cloudaccess/access_key_test.go b/pkg/cloudaccess/access_key_test.go index 9ea15167..1563a973 100644 --- a/pkg/cloudaccess/access_key_test.go +++ b/pkg/cloudaccess/access_key_test.go @@ -253,6 +253,24 @@ func TestGetAccessKey(t *testing.T) { assert.Equal(t, "get an access key: struct validation: AccessKeyUID: cannot be blank", err.Error()) }, }, + "404 access key not found - custom error check": { + params: AccessKeyRequest{ + AccessKeyUID: 2, + }, + expectedPath: "/cam/v1/access-keys/2", + responseStatus: http.StatusNotFound, + responseBody: `{ + "type": "/cam/error-types/access-key-does-not-exist", + "title": "Domain Error", + "detail": "Access key with accessKeyUID '2' does not exist.", + "instance": "test-instance-123", + "status": 404, + "accessKeyUid": 2 + }`, + withError: func(t *testing.T, err error) { + assert.True(t, errors.Is(err, ErrAccessKeyNotFound)) + }, + }, "500 internal server error": { params: AccessKeyRequest{ AccessKeyUID: 1, diff --git a/pkg/cloudaccess/access_key_version_test.go b/pkg/cloudaccess/access_key_version_test.go index cbe0ec5a..6071b305 100644 --- a/pkg/cloudaccess/access_key_version_test.go +++ b/pkg/cloudaccess/access_key_version_test.go @@ -308,7 +308,35 @@ func TestGetAccessKeyVersion(t *testing.T) { assert.Equal(t, "get access key version: struct validation: AccessKeyUID: cannot be blank\nVersion: cannot be blank", err.Error()) }, }, - "404 error": { + "404 error - access key with specific uid not exists": { + params: GetAccessKeyVersionRequest{ + AccessKeyUID: 1, + Version: 1, + }, + responseStatus: http.StatusNotFound, + responseBody: ` + { + "accessKeyUid": 1, + "detail": "Access key with accessKeyUid '1' does not exist.", + "instance": "c111eff1-22ec-4d4e-99c9-55efb5d55f55", + "status": 404, + "title": "Domain Error", + "type": "/cam/error-types/access-key-does-not-exist" + }`, + expectedPath: "/cam/v1/access-keys/1/versions/1", + withError: func(t *testing.T, err error) { + want := &Error{ + AccessKeyUID: 1, + Type: "/cam/error-types/access-key-does-not-exist", + Title: "Domain Error", + Detail: "Access key with accessKeyUid '1' does not exist.", + Instance: "c111eff1-22ec-4d4e-99c9-55efb5d55f55", + Status: http.StatusNotFound, + } + assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err) + }, + }, + "404 error - wrap into custom error": { params: GetAccessKeyVersionRequest{ AccessKeyUID: 1, Version: 1, @@ -333,9 +361,65 @@ func TestGetAccessKeyVersion(t *testing.T) { Instance: "c111eff1-22ec-4d4e-99c9-55efb5d55f55", Status: http.StatusNotFound, } + assert.True(t, errors.Is(want, ErrAccessKeyNotFound)) + }, + }, + "404 error - access key version for specific access key not exists": { + params: GetAccessKeyVersionRequest{ + AccessKeyUID: 1, + Version: 2, + }, + responseStatus: http.StatusNotFound, + responseBody: ` + { + "accessKeyUid": 1, + "detail": "Version '2' for access key '1' does not exist.", + "instance": "12345-12345-12345-1234-12345678", + "status": 404, + "title": "Domain Error", + "type": "/cam/error-types/access-key-version-does-not-exist" + }`, + expectedPath: "/cam/v1/access-keys/1/versions/2", + withError: func(t *testing.T, err error) { + want := &Error{ + AccessKeyUID: 1, + Type: "/cam/error-types/access-key-version-does-not-exist", + Title: "Domain Error", + Detail: "Version '2' for access key '1' does not exist.", + Instance: "12345-12345-12345-1234-12345678", + Status: http.StatusNotFound, + } assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err) }, }, + "404 error - does not wrap into custom error": { + params: GetAccessKeyVersionRequest{ + AccessKeyUID: 1, + Version: 2, + }, + responseStatus: http.StatusNotFound, + responseBody: ` + { + "accessKeyUid": 1, + "detail": "Version '2' for access key '1' does not exist.", + "instance": "12345-12345-12345-1234-12345678", + "status": 404, + "title": "Domain Error", + "type": "/cam/error-types/access-key-version-does-not-exist" + }`, + expectedPath: "/cam/v1/access-keys/1/versions/2", + withError: func(t *testing.T, err error) { + want := &Error{ + AccessKeyUID: 1, + Type: "/cam/error-types/access-key-version-does-not-exist", + Title: "Domain Error", + Detail: "Version '2' for access key '1' does not exist.", + Instance: "12345-12345-12345-1234-12345678", + Status: http.StatusNotFound, + } + assert.False(t, errors.Is(want, ErrAccessKeyNotFound)) + }, + }, } for name, test := range tests { diff --git a/pkg/cloudaccess/errors.go b/pkg/cloudaccess/errors.go index 978afba4..237311d7 100644 --- a/pkg/cloudaccess/errors.go +++ b/pkg/cloudaccess/errors.go @@ -34,6 +34,11 @@ type ( } ) +const accessKeyNotFoundType = "/cam/error-types/access-key-does-not-exist" + +// ErrAccessKeyNotFound is returned when access key was not found +var ErrAccessKeyNotFound = errors.New("access key not found") + // Error parses an error from the response func (c *cloudaccess) Error(r *http.Response) error { var e Error @@ -68,6 +73,10 @@ func (e *Error) Error() string { // Is handles error comparisons func (e *Error) Is(target error) bool { + if errors.Is(target, ErrAccessKeyNotFound) { + return e.Status == http.StatusNotFound && e.Type == accessKeyNotFoundType + } + var t *Error if !errors.As(target, &t) { return false diff --git a/pkg/cloudaccess/errors_test.go b/pkg/cloudaccess/errors_test.go index 75ba4603..73281a48 100644 --- a/pkg/cloudaccess/errors_test.go +++ b/pkg/cloudaccess/errors_test.go @@ -97,7 +97,7 @@ func TestNewError(t *testing.T) { StatusCode: http.StatusNotFound, Body: ioutil.NopCloser(strings.NewReader( `{ - "type": "access-key-does-not-exists", + "type": "/cam/error-types/access-key-does-not-exist", "title": "Domain Error", "detail": "Access key with accessKeyUID '1' does not exist.", "instance": "test-instance-123", @@ -108,7 +108,7 @@ func TestNewError(t *testing.T) { Request: req, }, expected: &Error{ - Type: "access-key-does-not-exists", + Type: accessKeyNotFoundType, Title: "Domain Error", Detail: "Access key with accessKeyUID '1' does not exist.", Instance: "test-instance-123", From b8ffd93aed904818bd23a43089a0ab5f5e1711d8 Mon Sep 17 00:00:00 2001 From: Filip Antkowiak Date: Mon, 4 Nov 2024 13:17:25 +0000 Subject: [PATCH 04/12] DXE-4265 Add retries for GET requests Merge in DEVEXP/akamaiopen-edgegrid-golang from feature/DXE-4265 to develop --- CHANGELOG.md | 8 +- go.mod | 2 + go.sum | 14 ++ internal/test/test.go | 89 +++++++++ pkg/session/retries.go | 196 +++++++++++++++++++ pkg/session/retries_test.go | 378 ++++++++++++++++++++++++++++++++++++ pkg/session/session.go | 19 +- pkg/session/session_test.go | 2 +- 8 files changed, 704 insertions(+), 4 deletions(-) create mode 100644 pkg/session/retries.go create mode 100644 pkg/session/retries_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f166ec..7befa445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,8 +32,12 @@ - - +* General + * Added a configurable `WithRetries` option for creating new sessions with global GET retries. It can be configured with parameters: + * `retryMax` - The maximum number of API request retries. + * `retryWaitMin` - The minimum wait time in `time.Duration` between API requests retries. + * `retryWaitMax` - The maximum wait time in `time.Duration` between API requests retries. + * `excludedEndpoints` - List of path expressions defining endpoints which should be excluded from retry feature diff --git a/go.mod b/go.mod index af7a1d2b..514fc696 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,8 @@ require ( github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.7 github.com/kr/text v0.2.0 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index f829348e..e00c9992 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es= @@ -24,6 +26,12 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= +github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= @@ -37,8 +45,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -98,6 +110,8 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/internal/test/test.go b/internal/test/test.go index f091865f..c09e6d8b 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -2,10 +2,14 @@ package test import ( + "math/rand" + "net/http" + "sync" "testing" "time" "github.com/stretchr/testify/require" + "github.com/tj/assert" ) // NewTimeFromString returns a time value parsed from a string @@ -18,3 +22,88 @@ func NewTimeFromString(t *testing.T, s string) time.Time { require.NoError(t, err) return parsedTime } + +// XRateLimitHTTPHandler first returns status 429 with the X-RateLimit-Next header set to +// time.Now() plus a random value between 1 and 5 milliseconds. It keeps sending 429 until the +// X-RateLimit-Next point in time. Then it starts to return SuccessCode and SuccessBody +// indefinitely. +type XRateLimitHTTPHandler struct { + T *testing.T + SuccessCode int + SuccessBody string + + mutex sync.Mutex + availableAt time.Time + returnedCodes []int + returnTimes []time.Time +} + +func (h *XRateLimitHTTPHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) { + av := h.AvailableAt() + + if av.IsZero() { + busyInterval := time.Duration(1+rand.Intn(4)) * time.Millisecond + h.setAvailableAt(time.Now().Add(busyInterval)) + h.setTooManyRequests(w) + return + } + + now := time.Now() + if now.Before(av) { + h.setTooManyRequests(w) + } else { + h.setStatusCode(w, h.SuccessCode) + _, err := w.Write([]byte(h.SuccessBody)) + assert.NoError(h.T, err) + } +} + +// AvailableAt returns the point in time at which the handler stops returning status code 429 +func (h *XRateLimitHTTPHandler) AvailableAt() time.Time { + h.mutex.Lock() + defer h.mutex.Unlock() + return h.availableAt +} + +// ReturnedCodes returns a list of status codes from subsequent handler responses +func (h *XRateLimitHTTPHandler) ReturnedCodes() []int { + h.mutex.Lock() + defer h.mutex.Unlock() + res := make([]int, len(h.returnedCodes)) + copy(res, h.returnedCodes) + return res +} + +// ReturnTimes returns a list of times at which subsequent responses were written +func (h *XRateLimitHTTPHandler) ReturnTimes() []time.Time { + h.mutex.Lock() + defer h.mutex.Unlock() + res := make([]time.Time, len(h.returnTimes)) + copy(res, h.returnTimes) + return res +} + +func (h *XRateLimitHTTPHandler) setTooManyRequests(w http.ResponseWriter) { + // Do not use Add() to avoid canonicalization to X-Ratelimit-Next + nextStr := h.availableAt.Format(time.RFC3339Nano) + w.Header()["X-RateLimit-Next"] = []string{nextStr} + h.setStatusCode(w, http.StatusTooManyRequests) + body := "Your request did not succeed as this operation has reached the limit " + + "for your account. Please try after " + nextStr + _, err := w.Write([]byte(body)) + assert.NoError(h.T, err) +} + +func (h *XRateLimitHTTPHandler) setStatusCode(w http.ResponseWriter, statusCode int) { + w.WriteHeader(statusCode) + h.mutex.Lock() + defer h.mutex.Unlock() + h.returnedCodes = append(h.returnedCodes, statusCode) + h.returnTimes = append(h.returnTimes, time.Now()) +} + +func (h *XRateLimitHTTPHandler) setAvailableAt(availableAt time.Time) { + h.mutex.Lock() + defer h.mutex.Unlock() + h.availableAt = availableAt +} diff --git a/pkg/session/retries.go b/pkg/session/retries.go new file mode 100644 index 00000000..be8d4852 --- /dev/null +++ b/pkg/session/retries.go @@ -0,0 +1,196 @@ +package session + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "path" + "strings" + "time" + + "github.com/apex/log" + "github.com/hashicorp/go-retryablehttp" +) + +// RetryConfig struct contains http retry configuration. +// +// ExcludedEndpoints field is a list of shell patterns. +// The pattern syntax is: +// +// pattern: +// { term } +// term: +// '*' matches any sequence of non-/ characters +// '?' matches any single non-/ character +// '[' [ '^' ] { character-range } ']' +// character class (must be non-empty) +// c matches character c (c != '*', '?', '\\', '[') +// '\\' c matches character c +// +// character-range: +// c matches character c (c != '\\', '-', ']') +// '\\' c matches character c +// lo '-' hi matches character c for lo <= c <= hi +type RetryConfig struct { + RetryMax int + RetryWaitMin time.Duration + RetryWaitMax time.Duration + ExcludedEndpoints []string +} + +// NewRetryConfig creates a new retry config with default settings. +func NewRetryConfig() RetryConfig { + return RetryConfig{ + RetryMax: 10, + RetryWaitMin: 1 * time.Second, + RetryWaitMax: 30 * time.Second, + ExcludedEndpoints: []string{}, + } +} + +func configureRetryClient(conf RetryConfig, signFunc func(r *http.Request) error, log log.Interface) (*retryablehttp.Client, error) { + retryClient := retryablehttp.NewClient() + + err := validateRetryConf(conf) + if err != nil { + return nil, err + } + retryClient.RetryMax = conf.RetryMax + retryClient.RetryWaitMin = conf.RetryWaitMin + retryClient.RetryWaitMax = conf.RetryWaitMax + + retryClient.PrepareRetry = signFunc + retryClient.HTTPClient.CheckRedirect = func(r *http.Request, via []*http.Request) error { + return signFunc(r) + } + retryClient.CheckRetry = overrideRetryPolicy(retryablehttp.DefaultRetryPolicy, conf.ExcludedEndpoints) + retryClient.Backoff = overrideBackoff(retryablehttp.DefaultBackoff, log) + + return retryClient, err +} + +func validateRetryConf(conf RetryConfig) error { + errs := []error{} + + if conf.RetryMax < 0 { + errs = append(errs, errors.New("maximum number of retries cannot be negative")) + } + if conf.RetryWaitMin < 0 { + errs = append(errs, errors.New("minimum retry wait time cannot be negative")) + } + if conf.RetryWaitMax < 0 { + errs = append(errs, errors.New("maximum retry wait time cannot be negative")) + } + if conf.RetryWaitMax < conf.RetryWaitMin { + errs = append(errs, errors.New("maximum retry wait time cannot be shorter than minimum retry wait time")) + } + for _, pattern := range conf.ExcludedEndpoints { + if _, err := path.Match(pattern, ""); err != nil { + errs = append(errs, fmt.Errorf("malformed exclude endpoint pattern: %v: %s", err, pattern)) + } + } + if len(errs) > 0 { + return errors.Join(errs...) + } + return nil +} + +func overrideRetryPolicy(basePolicy retryablehttp.CheckRetry, excludedEndpoints []string) retryablehttp.CheckRetry { + return func(ctx context.Context, resp *http.Response, err error) (bool, error) { + // do not retry on context.Canceled or context.DeadlineExceeded + if ctx.Err() != nil { + return false, ctx.Err() + } + + if resp == nil || resp.Request.Method != http.MethodGet || + (resp.Request.URL != nil && isBlocked(resp.Request.URL.Path, excludedEndpoints)) { + var urlErr *url.Error + if resp == nil && errors.As(err, &urlErr) && strings.ToUpper(urlErr.Op) == http.MethodGet { + return basePolicy(ctx, resp, err) + } + return false, err + } + + // Retry all PAPI GET requests resulting status code 429 + // The backoff time is calculated in getXRateLimitBackoff + is429 := resp.StatusCode == http.StatusTooManyRequests + if is429 && (resp.Request.URL != nil && strings.HasPrefix(resp.Request.URL.Path, "/papi/")) { + return true, nil + } + if resp.StatusCode == http.StatusConflict { + return true, nil + } + return basePolicy(ctx, resp, err) + } +} + +func overrideBackoff(baseBackoff retryablehttp.Backoff, logger log.Interface) retryablehttp.Backoff { + return func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { + if resp != nil { + if resp.StatusCode == http.StatusTooManyRequests { + if wait, ok := getXRateLimitBackoff(resp, logger); ok { + return wait + } + } + } + return baseBackoff(min, max, attemptNum, resp) + } +} + +// Note that Date's resolution is seconds (e.g. Mon, 01 Jul 2024 14:32:14 GMT), +// while X-RateLimit-Next's resolution is milliseconds (2024-07-01T14:32:28.645Z). +// This may cause the wait time to be inflated by at most one second, like for the +// actual server response time around 2024-07-01T14:32:14.999Z. This is acceptable behavior +// as retry does not occur earlier than expected. +func getXRateLimitBackoff(resp *http.Response, logger log.Interface) (time.Duration, bool) { + nextHeader := resp.Header.Get("X-RateLimit-Next") + if nextHeader == "" { + return 0, false + } + next, err := time.Parse(time.RFC3339Nano, nextHeader) + if err != nil { + if logger != nil { + logger.WithError(err).Error("Could not parse X-RateLimit-Next header") + } + return 0, false + } + + dateHeader := resp.Header.Get("Date") + if dateHeader == "" { + if logger != nil { + logger.Warnf("No Date header for X-RateLimit-Next: %s", nextHeader) + } + return 0, false + } + date, err := time.Parse(time.RFC1123, dateHeader) + if err != nil { + if logger != nil { + logger.WithError(err).Error("Could not parse Date header") + } + return 0, false + } + + // Next in the past does not make sense + if next.Before(date) { + if logger != nil { + logger.Warnf("X-RateLimit-Next: %s before Date: %s", nextHeader, dateHeader) + } + return 0, false + } + return next.Sub(date), true +} + +func isBlocked(url string, disabledPatterns []string) bool { + for _, pattern := range disabledPatterns { + match, err := path.Match(pattern, url) + if err != nil { + return false + } + if match { + return true + } + } + return false +} diff --git a/pkg/session/retries_test.go b/pkg/session/retries_test.go new file mode 100644 index 00000000..b001f133 --- /dev/null +++ b/pkg/session/retries_test.go @@ -0,0 +1,378 @@ +package session + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/http/httptest" + "net/url" + "strings" + "testing" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/internal/test" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/apex/log" + "github.com/apex/log/handlers/discard" + "github.com/hashicorp/go-retryablehttp" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func newRequest(t *testing.T, method, url string) *http.Request { + r, err := http.NewRequest(method, url, nil) + assert.NoError(t, err) + return r +} + +func TestOverrideRetryPolicy(t *testing.T) { + basePolicy := func(ctx context.Context, resp *http.Response, err error) (bool, error) { + return false, errors.New("base policy: dummy, not implemented") + } + policy := overrideRetryPolicy(basePolicy, []string{"/excluded"}) + + tests := map[string]struct { + ctx context.Context + resp *http.Response + err error + expectedResult bool + expectedError string + }{ + "should retry for PAPI GET with status 429": { + ctx: context.Background(), + resp: &http.Response{ + Request: newRequest(t, http.MethodGet, "/papi/v1/sth"), + StatusCode: http.StatusTooManyRequests, + }, + expectedResult: true, + }, + "should retry for GET with status 409 conflict": { + ctx: context.Background(), + resp: &http.Response{ + Request: &http.Request{Method: http.MethodGet}, + StatusCode: http.StatusConflict, + }, + expectedResult: true, + }, + "should call base policy for other GETs": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodGet}}, + expectedError: "base policy: dummy, not implemented", + }, + "should forward context error when present": { + ctx: func() context.Context { + ctx, cancel := context.WithCancel(context.Background()) + cancel() + return ctx + }(), + resp: &http.Response{Request: &http.Request{Method: http.MethodGet}}, + expectedError: "context canceled", + }, + "should not retry for POST": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodPost}}, + expectedResult: false, + }, + "should not retry for PUT": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodPut}}, + expectedResult: false, + }, + "should not retry for PATCH": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodPatch}}, + expectedResult: false, + }, + "should not retry for HEAD": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodHead}}, + expectedResult: false, + }, + "should not retry for DELETE": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodDelete}}, + expectedResult: false, + }, + "should not retry excluded endpoints": { + ctx: context.Background(), + resp: &http.Response{Request: &http.Request{Method: http.MethodGet, URL: &url.URL{Path: "/excluded"}}}, + expectedResult: false, + }, + "nil request with error": { + ctx: context.Background(), + resp: nil, + err: errors.New("test error"), + expectedResult: false, + expectedError: "test error", + }, + "should call base policy for GET url.Error": { + ctx: context.Background(), + resp: nil, + err: &url.Error{ + Op: http.MethodGet, + URL: "", + Err: nil, + }, + expectedError: "base policy: dummy, not implemented", + }, + } + for name, tst := range tests { + t.Run(name, func(t *testing.T) { + shouldRetry, err := policy(tst.ctx, tst.resp, tst.err) + if len(tst.expectedError) > 0 { + assert.ErrorContains(t, err, tst.expectedError) + } else { + assert.NoError(t, err) + assert.Equal(t, tst.expectedResult, shouldRetry) + } + }) + } +} + +func stat429ResponseWaiting(wait time.Duration) *http.Response { + res := http.Response{ + StatusCode: http.StatusTooManyRequests, + Header: http.Header{}, + } + + now := time.Now().UTC().Round(time.Second) + date := strings.Replace(now.Format(time.RFC1123), "UTC", "GMT", 1) + res.Header.Add("Date", date) + if wait != 0 { + // Add: allow to canonicalize to X-Ratelimit-Next or the header won't be recognized + res.Header.Add("X-RateLimit-Next", now.Add(wait).Format(time.RFC3339Nano)) + } + return &res +} + +func Test_overrideBackoff(t *testing.T) { + baseWait := time.Duration(24) * time.Hour + baseBackoff := func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { + return baseWait + } + backoff := overrideBackoff(baseBackoff, nil) + + tests := map[string]struct { + resp *http.Response + expectedResult time.Duration + }{ + "correctly calculates backoff from X-RateLimit-Next": { + resp: stat429ResponseWaiting(time.Duration(5729) * time.Millisecond), + expectedResult: time.Duration(5729) * time.Millisecond, + }, + "falls back for next in the past": { + resp: stat429ResponseWaiting(-time.Duration(5729) * time.Millisecond), + expectedResult: baseWait, + }, + "falls back for no X-RateLimit-Next header": { + resp: stat429ResponseWaiting(0), + expectedResult: baseWait, + }, + "falls back for invalid X-RateLimit-Next header": { + resp: func() *http.Response { + r := stat429ResponseWaiting(time.Duration(5729) * time.Millisecond) + r.Header.Set("X-RateLimit-Next", "2024-07-01T14:32:28.645???") + return r + }(), + expectedResult: baseWait, + }, + "falls back for no Date header": { + resp: func() *http.Response { + r := stat429ResponseWaiting(time.Duration(5729) * time.Millisecond) + r.Header.Del("Date") + return r + }(), + expectedResult: baseWait, + }, + "falls back for invalid Date header": { + resp: func() *http.Response { + r := stat429ResponseWaiting(time.Duration(5729) * time.Millisecond) + r.Header.Set("Date", "Mon, 01 Jul 2024 99:99:99 GMT") + return r + }(), + expectedResult: baseWait, + }, + } + for name, tst := range tests { + t.Run(name, func(t *testing.T) { + wait := backoff(1, 30, 1, tst.resp) + assert.Equal(t, tst.expectedResult, wait) + }) + } +} + +func TestXRateLimitGet(t *testing.T) { + xrlHandler := test.XRateLimitHTTPHandler{ + T: t, + SuccessCode: http.StatusOK, + } + + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "/papi/test", r.URL.String()) + assert.Equal(t, http.MethodGet, r.Method) + xrlHandler.ServeHTTP(w, r) + })) + defer mockServer.Close() + + mockSession := mockRetrySession(t, mockServer) + client := mockSession.Client() + _, err := client.Get(fmt.Sprintf("%s/papi/test", mockServer.URL)) + assert.NoError(t, err) + + // We expect exactly two requests to the server: + // - the first resulting in code 429 + // - the second after a proper backoff, resulting in status 200 + assert.Equal(t, []int{http.StatusTooManyRequests, http.StatusOK}, xrlHandler.ReturnedCodes()) + assert.Less(t, + xrlHandler.ReturnTimes()[1], + xrlHandler.AvailableAt().Add(time.Duration(time.Millisecond)*1100)) +} + +func mockRetrySession(t *testing.T, mockServer *httptest.Server) Session { + + serverURL, err := url.Parse(mockServer.URL) + require.NoError(t, err) + config := edgegrid.Config{Host: serverURL.Host} + retryConf := NewRetryConfig() + + retrySession, err := New(WithRetries(retryConf), WithSigner(&config)) + assert.NoError(t, err) + + return retrySession +} + +func Test_configureRetryClient(t *testing.T) { + tests := map[string]struct { + retryMax int + retryWaitMin time.Duration + retryWaitMax time.Duration + excludedEndpoints []string + expected *retryablehttp.Client + expectedError string + }{ + "happy path": { + retryMax: 5, + retryWaitMin: 5 * time.Second, + retryWaitMax: 31 * time.Second, + excludedEndpoints: []string{"aaa/bbb/ccc", "aaa/*/ccc"}, + expected: &retryablehttp.Client{ + RetryWaitMin: 5 * time.Second, + RetryWaitMax: 31 * time.Second, + RetryMax: 5, + }, + }, + "negative number of retries": { + retryMax: -5, + retryWaitMin: 5 * time.Second, + retryWaitMax: 30 * time.Second, + expected: nil, + expectedError: `maximum number of retries cannot be negative`, + }, + "negative wait times": { + retryMax: 5, + retryWaitMin: -5 * time.Second, + retryWaitMax: -5 * time.Second, + expected: nil, + expectedError: `minimum retry wait time cannot be negative +maximum retry wait time cannot be negative`, + }, + "minimum wait time higher that maximum wait time": { + retryMax: 5, + retryWaitMin: 30 * time.Second, + retryWaitMax: 5 * time.Second, + expected: nil, + expectedError: `maximum retry wait time cannot be shorter than minimum retry wait time`, + }, + "malformed excluded endpoint pattern": { + excludedEndpoints: []string{"[-]"}, + expected: nil, + expectedError: "malformed exclude endpoint pattern: syntax error in pattern: [-]", + }, + "test error formation": { + retryMax: -5, + retryWaitMin: -3 * time.Second, + retryWaitMax: -7 * time.Second, + excludedEndpoints: []string{"[-]"}, + expected: nil, + expectedError: `maximum number of retries cannot be negative +minimum retry wait time cannot be negative +maximum retry wait time cannot be negative +maximum retry wait time cannot be shorter than minimum retry wait time +malformed exclude endpoint pattern: syntax error in pattern: [-]`, + }, + } + sessionLogger := &log.Logger{ + Handler: discard.New(), + Level: 1, + } + testSession := &session{log: sessionLogger} + for name, test := range tests { + t.Run(name, func(t *testing.T) { + + conf := RetryConfig{ + RetryMax: test.retryMax, + RetryWaitMin: test.retryWaitMin, + RetryWaitMax: test.retryWaitMax, + ExcludedEndpoints: test.excludedEndpoints, + } + got, err := configureRetryClient(conf, testSession.Sign, testSession.log) + + if len(test.expectedError) > 0 { + assert.ErrorContains(t, err, test.expectedError) + } else { + assert.NoError(t, err) + } + if test.expected != nil { + assert.Equal(t, test.expected.RetryMax, got.RetryMax) + assert.Equal(t, test.expected.RetryWaitMax, got.RetryWaitMax) + assert.Equal(t, test.expected.RetryWaitMin, got.RetryWaitMin) + } else { + assert.Nil(t, got) + } + + }) + } +} + +func Test_isBlocked(t *testing.T) { + tests := map[string]struct { + url string + blocked []string + expected bool + }{ + "blocked - no wildcards": { + url: "/api/blocked", + blocked: []string{"/api/blocked"}, + expected: true, + }, + "blocked - with wildcard": { + url: "/api/blocked/123", + blocked: []string{"/api/blocked/*"}, + expected: true, + }, + "allowed - all": { + url: "/api/not-blocked/123/data", + blocked: []string{}, + expected: false, + }, + "allowed - with wildcard": { + url: "/api/not-blocked/123/data", + blocked: []string{"/api/not-blocked/*"}, + expected: false, + }, + "allowed - wildcard does not match beginning of url": { + url: "/api/not-blocked/123/data", + blocked: []string{"/not-blocked/*/data"}, + expected: false, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + got := isBlocked(test.url, test.blocked) + assert.Equal(t, test.expected, got) + + }) + } +} diff --git a/pkg/session/session.go b/pkg/session/session.go index f35920c9..0024e42a 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -94,7 +94,7 @@ func New(opts ...Option) (Session, error) { return s, nil } -// Must is a helper tthat will result in a panic if an error is returned +// Must is a helper that will result in a panic if an error is returned // ex. sess := Must(New()) func Must(sess Session, err error) Session { if err != nil { @@ -111,6 +111,23 @@ func WithClient(client *http.Client) Option { } } +// WithRetries configures the HTTP client to automatically retry failed GET requests +func WithRetries(conf RetryConfig) Option { + return func(s *session) { + retryClient, err := configureRetryClient(conf, s.Sign, s.log) + if err != nil { + s.log.Error(err.Error()) + defaultConfig := NewRetryConfig() + retryClient, err = configureRetryClient(defaultConfig, s.Sign, s.log) + if err != nil { + s.log.Errorf("retry configuration failed, disabling retries: %v", err.Error()) + return + } + } + s.client = retryClient.StandardClient() + } +} + // WithLog sets the log interface for the client func WithLog(l log.Interface) Option { return func(s *session) { diff --git a/pkg/session/session_test.go b/pkg/session/session_test.go index ac498e02..ffe7c95a 100644 --- a/pkg/session/session_test.go +++ b/pkg/session/session_test.go @@ -10,8 +10,8 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" "github.com/apex/log" "github.com/apex/log/handlers/discard" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tj/assert" ) func TestNew(t *testing.T) { From 2844291863fa586bfc7e9c65ea6e5d7dcaed7489 Mon Sep 17 00:00:00 2001 From: Jakub Bilski Date: Fri, 8 Nov 2024 08:14:28 +0000 Subject: [PATCH 05/12] DXE-3660 Add response body close --- CHANGELOG.md | 9 +++++++++ pkg/appsec/activations.go | 9 +++++++++ .../advanced_settings_attack_payload_logging.go | 4 ++++ .../advanced_settings_evasive_path_match.go | 3 +++ pkg/appsec/advanced_settings_logging.go | 4 ++++ pkg/appsec/advanced_settings_pii_learning.go | 3 +++ pkg/appsec/advanced_settings_pragma_header.go | 3 +++ pkg/appsec/advanced_settings_prefetch.go | 3 +++ pkg/appsec/advanced_settings_request_body.go | 4 ++++ pkg/appsec/api_constraints_protection.go | 3 +++ pkg/appsec/api_endpoints.go | 3 +++ pkg/appsec/api_hostname_coverage.go | 4 ++++ .../api_hostname_coverage_match_targets.go | 3 +++ pkg/appsec/api_hostname_coverage_overlapping.go | 3 +++ pkg/appsec/api_request_constraints.go | 5 +++++ pkg/appsec/attack_group.go | 6 ++++++ pkg/appsec/configuration.go | 6 ++++++ pkg/appsec/configuration_clone.go | 5 +++++ pkg/appsec/configuration_version.go | 4 ++++ pkg/appsec/configuration_version_clone.go | 8 +++++++- pkg/appsec/contracts_groups.go | 4 ++++ pkg/appsec/custom_deny.go | 11 +++++++++++ pkg/appsec/custom_rule.go | 11 +++++++++++ pkg/appsec/custom_rule_action.go | 5 +++++ pkg/appsec/eval.go | 9 +++++++++ pkg/appsec/eval_group.go | 8 ++++++++ pkg/appsec/eval_penalty_box.go | 6 ++++++ pkg/appsec/eval_penalty_box_conditions.go | 6 ++++++ pkg/appsec/eval_rule.go | 7 +++++++ pkg/appsec/export_configuration.go | 6 +++++- pkg/appsec/failover_hostnames.go | 4 ++++ pkg/appsec/ip_geo.go | 5 +++++ pkg/appsec/ip_geo_protection.go | 7 +++++++ pkg/appsec/malware_content_types.go | 3 +++ pkg/appsec/malware_policy.go | 11 +++++++++++ pkg/appsec/malware_policy_action.go | 7 +++++++ pkg/appsec/malware_protection.go | 7 +++++++ pkg/appsec/match_target.go | 14 ++++++++++++-- pkg/appsec/match_target_sequence.go | 5 +++++ pkg/appsec/network_layer_protection.go | 9 +++++++++ pkg/appsec/penalty_box.go | 7 +++++++ pkg/appsec/penalty_box_conditions.go | 5 +++++ pkg/appsec/rate_policy.go | 11 +++++++++++ pkg/appsec/rate_policy_action.go | 7 +++++++ pkg/appsec/rate_protection.go | 7 +++++++ pkg/appsec/reputation_analysis.go | 7 +++++++ pkg/appsec/reputation_profile.go | 11 +++++++++++ pkg/appsec/reputation_profile_action.go | 7 +++++++ pkg/appsec/reputation_protection.go | 9 +++++++++ pkg/appsec/rule.go | 9 +++++++++ pkg/appsec/rule_upgrade.go | 5 +++++ pkg/appsec/security_policy.go | 13 +++++++++++++ pkg/appsec/security_policy_clone.go | 7 +++++++ pkg/appsec/security_policy_protections.go | 7 +++++++ pkg/appsec/selectable_hostnames.go | 4 ++++ pkg/appsec/selected_hostname.go | 9 +++++++++ pkg/appsec/siem_definitions.go | 4 ++++ pkg/appsec/siem_settings.go | 7 +++++++ pkg/appsec/slow_post_protection_setting.go | 7 +++++++ pkg/appsec/slowpost_protection.go | 7 +++++++ pkg/appsec/threat_intel.go | 5 +++++ pkg/appsec/tuning_recommendations.go | 7 +++++++ pkg/appsec/version_notes.go | 5 +++++ pkg/appsec/waf_mode.go | 7 +++++++ pkg/appsec/waf_protection.go | 7 +++++++ pkg/appsec/wap_bypass_network_lists.go | 7 +++++++ pkg/appsec/wap_selected_hostnames.go | 5 +++++ pkg/botman/akamai_bot_category.go | 3 +++ pkg/botman/akamai_bot_category_action.go | 4 ++++ pkg/botman/akamai_defined_bot.go | 3 +++ pkg/botman/bot_analytics_cookie.go | 3 +++ pkg/botman/bot_analytics_cookie_values.go | 3 +++ pkg/botman/bot_category_exception.go | 3 +++ pkg/botman/bot_detection.go | 3 +++ pkg/botman/bot_detection_action.go | 4 ++++ pkg/botman/bot_endpoint_coverage_report.go | 2 ++ pkg/botman/bot_management_setting.go | 3 +++ pkg/botman/challenge_action.go | 7 +++++++ pkg/botman/challenge_injection_rules.go | 3 +++ pkg/botman/challenge_interception_rules.go | 3 +++ pkg/botman/client_side_security.go | 3 +++ pkg/botman/conditional_action.go | 6 ++++++ ...ntent_protection_javascript_injection_rule.go | 6 ++++++ pkg/botman/content_protection_rule.go | 6 ++++++ pkg/botman/content_protection_rule_sequence.go | 3 +++ pkg/botman/custom_bot_category.go | 6 ++++++ pkg/botman/custom_bot_category_action.go | 4 ++++ pkg/botman/custom_bot_category_item_sequence.go | 3 +++ pkg/botman/custom_bot_category_sequence.go | 3 +++ pkg/botman/custom_client.go | 6 ++++++ pkg/botman/custom_client_sequence.go | 3 +++ pkg/botman/custom_code.go | 3 +++ pkg/botman/custom_defined_bot.go | 6 ++++++ pkg/botman/custom_deny_action.go | 6 ++++++ pkg/botman/javascript_injection.go | 3 +++ pkg/botman/recategorized_akamai_defined_bot.go | 6 ++++++ pkg/botman/response_action.go | 2 ++ pkg/botman/serve_alternate_action.go | 6 ++++++ pkg/botman/transactional_endpoint.go | 6 ++++++ pkg/botman/transactional_endpoint_protection.go | 3 +++ pkg/clientlists/client_list.go | 7 +++++++ pkg/clientlists/client_list_activation.go | 4 ++++ pkg/cloudaccess/access_key.go | 7 +++++++ pkg/cloudaccess/access_key_version.go | 6 ++++++ pkg/cloudaccess/properties.go | 4 ++++ pkg/cloudlets/loadbalancer.go | 6 +++++- pkg/cloudlets/loadbalancer_activation.go | 4 +++- pkg/cloudlets/loadbalancer_version.go | 6 +++++- pkg/cloudlets/policy.go | 6 ++++++ pkg/cloudlets/policy_property.go | 4 +++- pkg/cloudlets/policy_version.go | 7 ++++++- pkg/cloudlets/policy_version_activation.go | 16 +++++++++------- pkg/cloudlets/v3/list_cloudlets.go | 3 +++ pkg/cloudlets/v3/policy.go | 7 +++++++ pkg/cloudlets/v3/policy_activation.go | 5 +++++ pkg/cloudlets/v3/policy_property.go | 2 ++ pkg/cloudlets/v3/policy_version.go | 7 ++++++- pkg/cloudwrapper/capacity.go | 3 +++ pkg/cloudwrapper/configurations.go | 7 +++++++ pkg/cloudwrapper/locations.go | 3 +++ pkg/cloudwrapper/multi_cdn.go | 3 +++ pkg/cloudwrapper/properties.go | 3 +++ pkg/cps/change_management_info.go | 5 +++++ pkg/cps/changes.go | 4 ++++ pkg/cps/deployment_schedules.go | 3 +++ pkg/cps/deployments.go | 4 ++++ pkg/cps/dv_challenges.go | 4 ++++ pkg/cps/enrollments.go | 6 ++++++ pkg/cps/history.go | 4 ++++ pkg/cps/post_verification_warnings.go | 4 ++++ pkg/cps/pre_verification_warnings.go | 4 ++++ pkg/cps/third_party_csr.go | 3 +++ pkg/datastream/properties.go | 3 +++ pkg/datastream/stream.go | 6 ++++++ pkg/datastream/stream_activation.go | 4 ++++ pkg/dns/authorities.go | 2 ++ pkg/dns/data.go | 3 +++ pkg/dns/record.go | 4 ++++ pkg/dns/record_lookup.go | 3 +++ pkg/dns/recordsets.go | 4 ++++ pkg/dns/tsig.go | 8 ++++++++ pkg/dns/zone.go | 13 +++++++++++++ pkg/dns/zonebulk.go | 7 +++++++ pkg/edgeworkers/activations.go | 5 +++++ pkg/edgeworkers/contracts.go | 3 +++ pkg/edgeworkers/deactivations.go | 4 ++++ pkg/edgeworkers/edgekv_access_tokens.go | 5 +++++ pkg/edgeworkers/edgekv_groups.go | 3 ++- pkg/edgeworkers/edgekv_initialize.go | 4 ++++ pkg/edgeworkers/edgekv_items.go | 5 +++++ pkg/edgeworkers/edgekv_namespaces.go | 5 +++++ pkg/edgeworkers/edgeworker_id.go | 7 +++++++ pkg/edgeworkers/edgeworker_version.go | 6 ++++++ pkg/edgeworkers/permission_group.go | 3 +++ pkg/edgeworkers/properties.go | 2 ++ pkg/edgeworkers/report.go | 4 ++++ pkg/edgeworkers/resource_tier.go | 3 +++ pkg/edgeworkers/secure_tokens.go | 2 ++ pkg/edgeworkers/validations.go | 2 ++ pkg/gtm/asmap.go | 6 ++++++ pkg/gtm/cidrmap.go | 6 ++++++ pkg/gtm/datacenter.go | 11 +++++++++++ pkg/gtm/domain.go | 8 ++++++++ pkg/gtm/geomap.go | 6 ++++++ pkg/gtm/property.go | 6 ++++++ pkg/gtm/resource.go | 6 ++++++ pkg/hapi/change_requests.go | 3 +++ pkg/hapi/edgehostname.go | 6 +++++- pkg/iam/api_clients.go | 9 ++++++++- pkg/iam/api_clients_credentials.go | 8 ++++++++ pkg/iam/blocked_properties.go | 3 +++ pkg/iam/cidr.go | 7 +++++++ pkg/iam/groups.go | 8 ++++++++ pkg/iam/helper.go | 5 +++++ pkg/iam/ip_allowlist.go | 5 +++++ pkg/iam/properties.go | 6 ++++++ pkg/iam/roles.go | 7 +++++++ pkg/iam/support.go | 10 ++++++++++ pkg/iam/user.go | 11 +++++++++++ pkg/iam/user_lock.go | 3 +++ pkg/iam/user_password.go | 3 +++ pkg/imaging/policy.go | 8 +++++++- pkg/imaging/policyset.go | 7 ++++++- pkg/networklists/activations.go | 5 +++++ pkg/networklists/network_list.go | 6 ++++++ pkg/networklists/network_list_description.go | 3 +++ pkg/networklists/network_list_subscription.go | 5 +++++ pkg/papi/activation.go | 5 +++++ pkg/papi/clientsettings.go | 4 ++++ pkg/papi/contract.go | 3 +++ pkg/papi/cpcode.go | 7 +++++++ pkg/papi/edgehostname.go | 5 +++++ pkg/papi/group.go | 3 +++ pkg/papi/include.go | 7 ++++++- pkg/papi/include_activations.go | 6 ++++++ pkg/papi/include_rule.go | 4 ++++ pkg/papi/include_versions.go | 6 ++++++ pkg/papi/products.go | 2 ++ pkg/papi/property.go | 5 +++++ pkg/papi/propertyhostname.go | 4 ++++ pkg/papi/propertyversion.go | 9 +++++++++ pkg/papi/response_link.go | 2 +- pkg/papi/rule.go | 4 ++++ pkg/papi/ruleformats.go | 3 +++ pkg/papi/search.go | 2 ++ pkg/session/session.go | 5 +++++ 206 files changed, 1084 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7befa445..bce62952 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,15 @@ +* General + * Added logic responsible for closing the response body in each method. + + + + + + + diff --git a/pkg/appsec/activations.go b/pkg/appsec/activations.go index 456660db..89871e77 100644 --- a/pkg/appsec/activations.go +++ b/pkg/appsec/activations.go @@ -8,6 +8,7 @@ import ( "strconv" "time" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -189,6 +190,7 @@ func (p *appsec) GetActivations(ctx context.Context, params GetActivationsReques if errp != nil { return nil, fmt.Errorf("get activations request failed: %w", errp) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -219,6 +221,7 @@ func (p *appsec) GetActivationHistory(ctx context.Context, params GetActivationH if err != nil { return nil, fmt.Errorf("get activation history request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -243,6 +246,8 @@ func (p *appsec) CreateActivations(ctx context.Context, params CreateActivations if err != nil { return nil, fmt.Errorf("create activations request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -261,6 +266,8 @@ func (p *appsec) CreateActivations(ctx context.Context, params CreateActivations if err != nil { return nil, fmt.Errorf("get activation request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -284,6 +291,8 @@ func (p *appsec) RemoveActivations(ctx context.Context, params RemoveActivations if errp != nil { return nil, fmt.Errorf("remove activations request failed: %w", errp) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/advanced_settings_attack_payload_logging.go b/pkg/appsec/advanced_settings_attack_payload_logging.go index b72bad52..f5a61fec 100644 --- a/pkg/appsec/advanced_settings_attack_payload_logging.go +++ b/pkg/appsec/advanced_settings_attack_payload_logging.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -151,6 +152,7 @@ func (a *appsec) GetAdvancedSettingsAttackPayloadLogging(ctx context.Context, pa if err != nil { return nil, fmt.Errorf("get advanced settings attack payload logging request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, a.Error(resp) @@ -179,6 +181,7 @@ func (a *appsec) UpdateAdvancedSettingsAttackPayloadLogging(ctx context.Context, if err != nil { return nil, fmt.Errorf("update advanced settings attack payload logging request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, a.Error(resp) @@ -205,6 +208,7 @@ func (a *appsec) RemoveAdvancedSettingsAttackPayloadLogging(ctx context.Context, if err != nil { return nil, fmt.Errorf("remove advanced settings attack payload logging request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, a.Error(resp) diff --git a/pkg/appsec/advanced_settings_evasive_path_match.go b/pkg/appsec/advanced_settings_evasive_path_match.go index 6837f5cf..d2194340 100644 --- a/pkg/appsec/advanced_settings_evasive_path_match.go +++ b/pkg/appsec/advanced_settings_evasive_path_match.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -125,6 +126,7 @@ func (p *appsec) GetAdvancedSettingsEvasivePathMatch(ctx context.Context, params if err != nil { return nil, fmt.Errorf("get advanced settings evasive path match request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -166,6 +168,7 @@ func (p *appsec) UpdateAdvancedSettingsEvasivePathMatch(ctx context.Context, par if err != nil { return nil, fmt.Errorf("update advanced settings evasive path match request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/advanced_settings_logging.go b/pkg/appsec/advanced_settings_logging.go index c3564d02..039609fc 100644 --- a/pkg/appsec/advanced_settings_logging.go +++ b/pkg/appsec/advanced_settings_logging.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -176,6 +177,7 @@ func (p *appsec) GetAdvancedSettingsLogging(ctx context.Context, params GetAdvan if err != nil { return nil, fmt.Errorf("get advanced settings logging request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -217,6 +219,7 @@ func (p *appsec) UpdateAdvancedSettingsLogging(ctx context.Context, params Updat if err != nil { return nil, fmt.Errorf("update advanced settings logging request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -258,6 +261,7 @@ func (p *appsec) RemoveAdvancedSettingsLogging(ctx context.Context, params Remov if err != nil { return nil, fmt.Errorf("remove advanced settings logging request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/advanced_settings_pii_learning.go b/pkg/appsec/advanced_settings_pii_learning.go index f4b9e5f7..3ced745d 100644 --- a/pkg/appsec/advanced_settings_pii_learning.go +++ b/pkg/appsec/advanced_settings_pii_learning.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -85,6 +86,7 @@ func (p *appsec) GetAdvancedSettingsPIILearning(ctx context.Context, params GetA if err != nil { return nil, fmt.Errorf("%w: %s", ErrAPICallFailure, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -119,6 +121,7 @@ func (p *appsec) UpdateAdvancedSettingsPIILearning(ctx context.Context, params U if err != nil { return nil, fmt.Errorf("%w: %s", ErrAPICallFailure, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/advanced_settings_pragma_header.go b/pkg/appsec/advanced_settings_pragma_header.go index df442c57..1d4c4146 100644 --- a/pkg/appsec/advanced_settings_pragma_header.go +++ b/pkg/appsec/advanced_settings_pragma_header.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -116,6 +117,7 @@ func (p *appsec) GetAdvancedSettingsPragma(ctx context.Context, params GetAdvanc if err != nil { return nil, fmt.Errorf("get advanced settings pragma request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -156,6 +158,7 @@ func (p *appsec) UpdateAdvancedSettingsPragma(ctx context.Context, params Update if err != nil { return nil, fmt.Errorf("update advanced settings pragma request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/advanced_settings_prefetch.go b/pkg/appsec/advanced_settings_prefetch.go index f6377dc4..c396f7bf 100644 --- a/pkg/appsec/advanced_settings_prefetch.go +++ b/pkg/appsec/advanced_settings_prefetch.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -111,6 +112,7 @@ func (p *appsec) GetAdvancedSettingsPrefetch(ctx context.Context, params GetAdva if err != nil { return nil, fmt.Errorf("get advanced settings prefetch request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -143,6 +145,7 @@ func (p *appsec) UpdateAdvancedSettingsPrefetch(ctx context.Context, params Upda if err != nil { return nil, fmt.Errorf("update advanced settings prefetch request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/advanced_settings_request_body.go b/pkg/appsec/advanced_settings_request_body.go index 68be4b02..5ae2a476 100644 --- a/pkg/appsec/advanced_settings_request_body.go +++ b/pkg/appsec/advanced_settings_request_body.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -137,6 +138,7 @@ func (a *appsec) GetAdvancedSettingsRequestBody(ctx context.Context, params GetA if err != nil { return nil, fmt.Errorf("get advanced settings request body request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, a.Error(resp) @@ -165,6 +167,7 @@ func (a *appsec) UpdateAdvancedSettingsRequestBody(ctx context.Context, params U if err != nil { return nil, fmt.Errorf("update advanced settings request body request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, a.Error(resp) @@ -193,6 +196,7 @@ func (a *appsec) RemoveAdvancedSettingsRequestBody(ctx context.Context, params R if err != nil { return nil, fmt.Errorf("remove advanced settings request body request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, a.Error(resp) diff --git a/pkg/appsec/api_constraints_protection.go b/pkg/appsec/api_constraints_protection.go index 98777a56..9dcc0f68 100644 --- a/pkg/appsec/api_constraints_protection.go +++ b/pkg/appsec/api_constraints_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -102,6 +103,7 @@ func (p *appsec) GetAPIConstraintsProtection(ctx context.Context, params GetAPIC if err != nil { return nil, fmt.Errorf("get API constraints protection request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -135,6 +137,7 @@ func (p *appsec) UpdateAPIConstraintsProtection(ctx context.Context, params Upda if err != nil { return nil, fmt.Errorf("update API constraints protection request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/api_endpoints.go b/pkg/appsec/api_endpoints.go index d5963fd2..4c24ef3f 100644 --- a/pkg/appsec/api_endpoints.go +++ b/pkg/appsec/api_endpoints.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -87,6 +88,8 @@ func (p *appsec) GetApiEndpoints(ctx context.Context, params GetApiEndpointsRequ if err != nil { return nil, fmt.Errorf("get API endpoints request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/api_hostname_coverage.go b/pkg/appsec/api_hostname_coverage.go index fd4e9d88..e445d3e3 100644 --- a/pkg/appsec/api_hostname_coverage.go +++ b/pkg/appsec/api_hostname_coverage.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -57,6 +59,8 @@ func (p *appsec) GetApiHostnameCoverage(ctx context.Context, _ GetApiHostnameCov if err != nil { return nil, fmt.Errorf("get API hostname coverage request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/api_hostname_coverage_match_targets.go b/pkg/appsec/api_hostname_coverage_match_targets.go index 8326e6ab..9dc10ab8 100644 --- a/pkg/appsec/api_hostname_coverage_match_targets.go +++ b/pkg/appsec/api_hostname_coverage_match_targets.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -98,6 +99,8 @@ func (p *appsec) GetApiHostnameCoverageMatchTargets(ctx context.Context, params if err != nil { return nil, fmt.Errorf("get API hostname coverage match targets request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/api_hostname_coverage_overlapping.go b/pkg/appsec/api_hostname_coverage_overlapping.go index 6eebcc85..3ceb6278 100644 --- a/pkg/appsec/api_hostname_coverage_overlapping.go +++ b/pkg/appsec/api_hostname_coverage_overlapping.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -71,6 +72,8 @@ func (p *appsec) GetApiHostnameCoverageOverlapping(ctx context.Context, params G if err != nil { return nil, fmt.Errorf("get API hostname coverage overlapping request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/api_request_constraints.go b/pkg/appsec/api_request_constraints.go index f8de51bc..ffb4e943 100644 --- a/pkg/appsec/api_request_constraints.go +++ b/pkg/appsec/api_request_constraints.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -128,6 +129,8 @@ func (p *appsec) GetApiRequestConstraints(ctx context.Context, params GetApiRequ if err != nil { return nil, fmt.Errorf("get API request constraints request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -181,6 +184,7 @@ func (p *appsec) UpdateApiRequestConstraints(ctx context.Context, params UpdateA if err != nil { return nil, fmt.Errorf("update API request constraints request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -225,6 +229,7 @@ func (p *appsec) RemoveApiRequestConstraints(ctx context.Context, params RemoveA if err != nil { return nil, fmt.Errorf("remove API request constraints request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/attack_group.go b/pkg/appsec/attack_group.go index 2647b167..d07b9a12 100644 --- a/pkg/appsec/attack_group.go +++ b/pkg/appsec/attack_group.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -218,6 +219,8 @@ func (p *appsec) GetAttackGroup(ctx context.Context, params GetAttackGroupReques if err != nil { return nil, fmt.Errorf("get attack group request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -249,6 +252,8 @@ func (p *appsec) GetAttackGroups(ctx context.Context, params GetAttackGroupsRequ if err != nil { return nil, fmt.Errorf("get attack groups request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -293,6 +298,7 @@ func (p *appsec) UpdateAttackGroup(ctx context.Context, params UpdateAttackGroup if err != nil { return nil, fmt.Errorf("update attack group request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) diff --git a/pkg/appsec/configuration.go b/pkg/appsec/configuration.go index 979827f6..abf27f6e 100644 --- a/pkg/appsec/configuration.go +++ b/pkg/appsec/configuration.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -167,6 +168,7 @@ func (p *appsec) GetConfiguration(ctx context.Context, params GetConfigurationRe if err != nil { return nil, fmt.Errorf("get configuration request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -193,6 +195,7 @@ func (p *appsec) GetConfigurations(ctx context.Context, _ GetConfigurationsReque if err != nil { return nil, fmt.Errorf("get configurations request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -224,6 +227,7 @@ func (p *appsec) UpdateConfiguration(ctx context.Context, params UpdateConfigura if err != nil { return nil, fmt.Errorf("update configuration request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -249,6 +253,7 @@ func (p *appsec) CreateConfiguration(ctx context.Context, params CreateConfigura if err != nil { return nil, fmt.Errorf("create configuration request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -276,6 +281,7 @@ func (p *appsec) RemoveConfiguration(ctx context.Context, params RemoveConfigura if err != nil { return nil, fmt.Errorf("remove configuration request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) diff --git a/pkg/appsec/configuration_clone.go b/pkg/appsec/configuration_clone.go index 7a4e2b46..125f8216 100644 --- a/pkg/appsec/configuration_clone.go +++ b/pkg/appsec/configuration_clone.go @@ -6,6 +6,7 @@ import ( "net/http" "time" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -119,6 +120,8 @@ func (p *appsec) GetConfigurationClone(ctx context.Context, params GetConfigurat if err != nil { return nil, fmt.Errorf("get configuration clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -146,6 +149,8 @@ func (p *appsec) CreateConfigurationClone(ctx context.Context, params CreateConf if err != nil { return nil, fmt.Errorf("create configuration clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/configuration_version.go b/pkg/appsec/configuration_version.go index bf54f76b..48212d9a 100644 --- a/pkg/appsec/configuration_version.go +++ b/pkg/appsec/configuration_version.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -61,6 +63,8 @@ func (p *appsec) GetConfigurationVersions(ctx context.Context, params GetConfigu if err != nil { return nil, fmt.Errorf("get configuration versions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/configuration_version_clone.go b/pkg/appsec/configuration_version_clone.go index c7228997..7560ea2e 100644 --- a/pkg/appsec/configuration_version_clone.go +++ b/pkg/appsec/configuration_version_clone.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "time" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -150,6 +150,8 @@ func (p *appsec) GetConfigurationVersionClone(ctx context.Context, params GetCon if err != nil { return nil, fmt.Errorf("get configuration version clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -177,6 +179,8 @@ func (p *appsec) CreateConfigurationVersionClone(ctx context.Context, params Cre if err != nil { return nil, fmt.Errorf("create configuration version clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -203,6 +207,8 @@ func (p *appsec) RemoveConfigurationVersionClone(ctx context.Context, params Rem if err != nil { return nil, fmt.Errorf("remove configuration version clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/contracts_groups.go b/pkg/appsec/contracts_groups.go index 874c5ffb..f0e939bc 100644 --- a/pkg/appsec/contracts_groups.go +++ b/pkg/appsec/contracts_groups.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -53,6 +55,8 @@ func (p *appsec) GetContractsGroups(ctx context.Context, params GetContractsGrou if err != nil { return nil, fmt.Errorf("get contracts groups request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/custom_deny.go b/pkg/appsec/custom_deny.go index 4a3203f5..43332557 100644 --- a/pkg/appsec/custom_deny.go +++ b/pkg/appsec/custom_deny.go @@ -8,6 +8,7 @@ import ( "reflect" "strconv" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -222,6 +223,8 @@ func (p *appsec) GetCustomDeny(ctx context.Context, params GetCustomDenyRequest) if err != nil { return nil, fmt.Errorf("get custom deny request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -253,6 +256,8 @@ func (p *appsec) GetCustomDenyList(ctx context.Context, params GetCustomDenyList if err != nil { return nil, fmt.Errorf("get custom deny list request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -296,6 +301,8 @@ func (p *appsec) UpdateCustomDeny(ctx context.Context, params UpdateCustomDenyRe if err != nil { return nil, fmt.Errorf("update custom deny request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -328,6 +335,8 @@ func (p *appsec) CreateCustomDeny(ctx context.Context, params CreateCustomDenyRe if err != nil { return nil, fmt.Errorf("create custom deny request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -354,6 +363,8 @@ func (p *appsec) RemoveCustomDeny(ctx context.Context, params RemoveCustomDenyRe if err != nil { return nil, fmt.Errorf("remove custom deny request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/custom_rule.go b/pkg/appsec/custom_rule.go index 8c759986..d537a0ec 100644 --- a/pkg/appsec/custom_rule.go +++ b/pkg/appsec/custom_rule.go @@ -7,6 +7,7 @@ import ( "net/http" "reflect" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -286,6 +287,8 @@ func (p *appsec) GetCustomRule(ctx context.Context, params GetCustomRuleRequest) if err != nil { return nil, fmt.Errorf("get custom rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -316,6 +319,8 @@ func (p *appsec) GetCustomRules(ctx context.Context, params GetCustomRulesReques if err != nil { return nil, fmt.Errorf("get custom rules request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -358,6 +363,8 @@ func (p *appsec) UpdateCustomRule(ctx context.Context, params UpdateCustomRuleRe if err != nil { return nil, fmt.Errorf("update custom rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -389,6 +396,8 @@ func (p *appsec) CreateCustomRule(ctx context.Context, params CreateCustomRuleRe if err != nil { return nil, fmt.Errorf("create custom rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -415,6 +424,8 @@ func (p *appsec) RemoveCustomRule(ctx context.Context, params RemoveCustomRuleRe if err != nil { return nil, fmt.Errorf("remove custom rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { return nil, p.Error(resp) } diff --git a/pkg/appsec/custom_rule_action.go b/pkg/appsec/custom_rule_action.go index cf927e94..27e70976 100644 --- a/pkg/appsec/custom_rule_action.go +++ b/pkg/appsec/custom_rule_action.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -136,6 +137,7 @@ func (p *appsec) GetCustomRuleAction(ctx context.Context, params GetCustomRuleAc if err != nil { return nil, fmt.Errorf("get custom rule action request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -175,6 +177,8 @@ func (p *appsec) GetCustomRuleActions(ctx context.Context, params GetCustomRuleA if err != nil { return nil, fmt.Errorf("get custom rule actions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -218,6 +222,7 @@ func (p *appsec) UpdateCustomRuleAction(ctx context.Context, params UpdateCustom if err != nil { return nil, fmt.Errorf("update custom rule action request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { return nil, p.Error(resp) diff --git a/pkg/appsec/eval.go b/pkg/appsec/eval.go index 1c4d992f..861ec730 100644 --- a/pkg/appsec/eval.go +++ b/pkg/appsec/eval.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -169,6 +170,8 @@ func (p *appsec) GetEval(ctx context.Context, params GetEvalRequest) (*GetEvalRe if err != nil { return nil, fmt.Errorf("get eval request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -201,6 +204,8 @@ func (p *appsec) GetEvals(ctx context.Context, params GetEvalsRequest) (*GetEval if err != nil { return nil, fmt.Errorf("get evals request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -233,6 +238,8 @@ func (p *appsec) UpdateEval(ctx context.Context, params UpdateEvalRequest) (*Upd if err != nil { return nil, fmt.Errorf("update eval request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -265,6 +272,8 @@ func (p *appsec) RemoveEval(ctx context.Context, params RemoveEvalRequest) (*Rem if err != nil { return nil, fmt.Errorf("remove eval request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/eval_group.go b/pkg/appsec/eval_group.go index e55145d9..3af2ed5e 100644 --- a/pkg/appsec/eval_group.go +++ b/pkg/appsec/eval_group.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -51,6 +53,8 @@ func (p *appsec) GetEvalGroup(ctx context.Context, params GetAttackGroupRequest) if err != nil { return nil, fmt.Errorf("get eval group request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -82,6 +86,8 @@ func (p *appsec) GetEvalGroups(ctx context.Context, params GetAttackGroupsReques if err != nil { return nil, fmt.Errorf("get eval groups request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -125,6 +131,8 @@ func (p *appsec) UpdateEvalGroup(ctx context.Context, params UpdateAttackGroupRe if err != nil { return nil, fmt.Errorf("update eval group request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/eval_penalty_box.go b/pkg/appsec/eval_penalty_box.go index 95f218d3..2fd71dfd 100644 --- a/pkg/appsec/eval_penalty_box.go +++ b/pkg/appsec/eval_penalty_box.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -46,6 +48,8 @@ func (p *appsec) GetEvalPenaltyBox(ctx context.Context, params GetPenaltyBoxRequ if err != nil { return nil, fmt.Errorf("get eval penalty box request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -78,6 +82,8 @@ func (p *appsec) UpdateEvalPenaltyBox(ctx context.Context, params UpdatePenaltyB if err != nil { return nil, fmt.Errorf("update eval penalty box request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/eval_penalty_box_conditions.go b/pkg/appsec/eval_penalty_box_conditions.go index 529e9f38..4da6dbe1 100644 --- a/pkg/appsec/eval_penalty_box_conditions.go +++ b/pkg/appsec/eval_penalty_box_conditions.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -42,6 +44,8 @@ func (p *appsec) GetEvalPenaltyBoxConditions(ctx context.Context, params GetPena if err != nil { return nil, fmt.Errorf("get eval penalty box conditions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -74,6 +78,8 @@ func (p *appsec) UpdateEvalPenaltyBoxConditions(ctx context.Context, params Upda if err != nil { return nil, fmt.Errorf("update eval penalty box conditions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/eval_rule.go b/pkg/appsec/eval_rule.go index 42b5decc..646c200f 100644 --- a/pkg/appsec/eval_rule.go +++ b/pkg/appsec/eval_rule.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -136,6 +137,8 @@ func (p *appsec) GetEvalRule(ctx context.Context, params GetEvalRuleRequest) (*G if err != nil { return nil, fmt.Errorf("get eval rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -167,6 +170,8 @@ func (p *appsec) GetEvalRules(ctx context.Context, params GetEvalRulesRequest) ( if err != nil { return nil, fmt.Errorf("get eval rules request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -211,6 +216,8 @@ func (p *appsec) UpdateEvalRule(ctx context.Context, params UpdateEvalRuleReques if err != nil { return nil, fmt.Errorf("update eval rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/export_configuration.go b/pkg/appsec/export_configuration.go index 98cde722..a5a4db86 100644 --- a/pkg/appsec/export_configuration.go +++ b/pkg/appsec/export_configuration.go @@ -8,10 +8,10 @@ import ( "net/http" "net/url" "reflect" - "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -893,6 +893,8 @@ func (p *appsec) GetExportConfiguration(ctx context.Context, params GetExportCon if err != nil { return nil, fmt.Errorf("get export configuration request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -920,6 +922,8 @@ func (p *appsec) GetExportConfigurations(ctx context.Context, params GetExportCo if err != nil { return nil, fmt.Errorf("get export configurations request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/failover_hostnames.go b/pkg/appsec/failover_hostnames.go index 339af5d7..83ff7861 100644 --- a/pkg/appsec/failover_hostnames.go +++ b/pkg/appsec/failover_hostnames.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -49,6 +51,8 @@ func (p *appsec) GetFailoverHostnames(ctx context.Context, params GetFailoverHos if err != nil { return nil, fmt.Errorf("get failover hostnames request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/ip_geo.go b/pkg/appsec/ip_geo.go index 1dc33a7c..29b65059 100644 --- a/pkg/appsec/ip_geo.go +++ b/pkg/appsec/ip_geo.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -126,6 +127,8 @@ func (p *appsec) GetIPGeo(ctx context.Context, params GetIPGeoRequest) (*GetIPGe if err != nil { return nil, fmt.Errorf("get IPGeo request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -158,6 +161,8 @@ func (p *appsec) UpdateIPGeo(ctx context.Context, params UpdateIPGeoRequest) (*U if err != nil { return nil, fmt.Errorf("update IPGeo request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/ip_geo_protection.go b/pkg/appsec/ip_geo_protection.go index 51f6bd35..69803c65 100644 --- a/pkg/appsec/ip_geo_protection.go +++ b/pkg/appsec/ip_geo_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -118,6 +119,8 @@ func (p *appsec) GetIPGeoProtection(ctx context.Context, params GetIPGeoProtecti if err != nil { return nil, fmt.Errorf("get IPGeo protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -149,6 +152,8 @@ func (p *appsec) GetIPGeoProtections(ctx context.Context, params GetIPGeoProtect if err != nil { return nil, fmt.Errorf("get IPGeo protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -181,6 +186,8 @@ func (p *appsec) UpdateIPGeoProtection(ctx context.Context, params UpdateIPGeoPr if err != nil { return nil, fmt.Errorf("update IPGeo protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/malware_content_types.go b/pkg/appsec/malware_content_types.go index f6431196..13653ac1 100644 --- a/pkg/appsec/malware_content_types.go +++ b/pkg/appsec/malware_content_types.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -61,6 +62,8 @@ func (p *appsec) GetMalwareContentTypes(ctx context.Context, params GetMalwareCo if err != nil { return nil, fmt.Errorf("get malware content types request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/malware_policy.go b/pkg/appsec/malware_policy.go index c687ca8a..30655a6c 100644 --- a/pkg/appsec/malware_policy.go +++ b/pkg/appsec/malware_policy.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -186,6 +187,8 @@ func (p *appsec) CreateMalwarePolicy(ctx context.Context, params CreateMalwarePo if err != nil { return nil, fmt.Errorf("create malware policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -217,6 +220,8 @@ func (p *appsec) GetMalwarePolicy(ctx context.Context, params GetMalwarePolicyRe if err != nil { return nil, fmt.Errorf("get malware policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -248,6 +253,8 @@ func (p *appsec) GetMalwarePolicies(ctx context.Context, params GetMalwarePolici if err != nil { return nil, fmt.Errorf("get malware policies request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -291,6 +298,8 @@ func (p *appsec) UpdateMalwarePolicy(ctx context.Context, params UpdateMalwarePo if err != nil { return nil, fmt.Errorf("update malware policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -316,6 +325,8 @@ func (p *appsec) RemoveMalwarePolicy(ctx context.Context, params RemoveMalwarePo if err != nil { return fmt.Errorf("remove malware policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return p.Error(resp) } diff --git a/pkg/appsec/malware_policy_action.go b/pkg/appsec/malware_policy_action.go index 5fdaf0cb..338fe1d4 100644 --- a/pkg/appsec/malware_policy_action.go +++ b/pkg/appsec/malware_policy_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -130,6 +131,8 @@ func (p *appsec) GetMalwarePolicyActions(ctx context.Context, params GetMalwareP if err != nil { return nil, fmt.Errorf("get malware policy actions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -173,6 +176,8 @@ func (p *appsec) UpdateMalwarePolicyAction(ctx context.Context, params UpdateMal if err != nil { return nil, fmt.Errorf("update malware policy action request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -205,6 +210,8 @@ func (p *appsec) UpdateMalwarePolicyActions(ctx context.Context, params UpdateMa if err != nil { return nil, fmt.Errorf("update malware policy actions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/malware_protection.go b/pkg/appsec/malware_protection.go index 8ec6ceac..41192a71 100644 --- a/pkg/appsec/malware_protection.go +++ b/pkg/appsec/malware_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -110,6 +111,8 @@ func (p *appsec) GetMalwareProtection(ctx context.Context, params GetMalwareProt if err != nil { return nil, fmt.Errorf("get malware protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -141,6 +144,8 @@ func (p *appsec) GetMalwareProtections(ctx context.Context, params GetMalwarePro if err != nil { return nil, fmt.Errorf("get malware protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -173,6 +178,8 @@ func (p *appsec) UpdateMalwareProtection(ctx context.Context, params UpdateMalwa if err != nil { return nil, fmt.Errorf("update malware protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/match_target.go b/pkg/appsec/match_target.go index 5c0e62f1..bfb262fd 100644 --- a/pkg/appsec/match_target.go +++ b/pkg/appsec/match_target.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -313,6 +314,8 @@ func (p *appsec) GetMatchTarget(ctx context.Context, params GetMatchTargetReques if err != nil { return nil, fmt.Errorf("get match target request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -344,6 +347,8 @@ func (p *appsec) GetMatchTargets(ctx context.Context, params GetMatchTargetsRequ if err != nil { return nil, fmt.Errorf("get match targets request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -392,6 +397,8 @@ func (p *appsec) UpdateMatchTarget(ctx context.Context, params UpdateMatchTarget if err != nil { return nil, fmt.Errorf("update match target request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -424,6 +431,8 @@ func (p *appsec) CreateMatchTarget(ctx context.Context, params CreateMatchTarget if err != nil { return nil, fmt.Errorf("create match target request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -446,10 +455,11 @@ func (p *appsec) RemoveMatchTarget(ctx context.Context, params RemoveMatchTarget } var result RemoveMatchTargetResponse - resp, errd := p.Exec(req, nil) - if errd != nil { + resp, err := p.Exec(req, nil) + if err != nil { return nil, fmt.Errorf("remove match target request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) diff --git a/pkg/appsec/match_target_sequence.go b/pkg/appsec/match_target_sequence.go index 65e266f8..6950f47d 100644 --- a/pkg/appsec/match_target_sequence.go +++ b/pkg/appsec/match_target_sequence.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -99,6 +100,8 @@ func (p *appsec) GetMatchTargetSequence(ctx context.Context, params GetMatchTarg if err != nil { return nil, fmt.Errorf("get match target sequence request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -130,6 +133,8 @@ func (p *appsec) UpdateMatchTargetSequence(ctx context.Context, params UpdateMat if err != nil { return nil, fmt.Errorf("update match target sequence request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/network_layer_protection.go b/pkg/appsec/network_layer_protection.go index d5fc813f..5d2b6520 100644 --- a/pkg/appsec/network_layer_protection.go +++ b/pkg/appsec/network_layer_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -146,6 +147,8 @@ func (p *appsec) GetNetworkLayerProtection(ctx context.Context, params GetNetwor if err != nil { return nil, fmt.Errorf("get network layer protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -177,6 +180,8 @@ func (p *appsec) GetNetworkLayerProtections(ctx context.Context, params GetNetwo if err != nil { return nil, fmt.Errorf("get network layer protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -209,6 +214,8 @@ func (p *appsec) UpdateNetworkLayerProtection(ctx context.Context, params Update if err != nil { return nil, fmt.Errorf("update network layer protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -241,6 +248,8 @@ func (p *appsec) RemoveNetworkLayerProtection(ctx context.Context, params Remove if err != nil { return nil, fmt.Errorf("remove network layer protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/penalty_box.go b/pkg/appsec/penalty_box.go index 33a810ea..7fe581bf 100644 --- a/pkg/appsec/penalty_box.go +++ b/pkg/appsec/penalty_box.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -132,6 +133,8 @@ func (p *appsec) GetPenaltyBox(ctx context.Context, params GetPenaltyBoxRequest) if err != nil { return nil, fmt.Errorf("get penalty box request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -165,6 +168,8 @@ func (p *appsec) GetPenaltyBoxes(ctx context.Context, params GetPenaltyBoxesRequ if err != nil { return nil, fmt.Errorf("get penalty boxes request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -197,6 +202,8 @@ func (p *appsec) UpdatePenaltyBox(ctx context.Context, params UpdatePenaltyBoxRe if err != nil { return nil, fmt.Errorf("update penalty box request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/penalty_box_conditions.go b/pkg/appsec/penalty_box_conditions.go index 849d6c3c..7588dc7f 100644 --- a/pkg/appsec/penalty_box_conditions.go +++ b/pkg/appsec/penalty_box_conditions.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -99,6 +100,8 @@ func (p *appsec) GetPenaltyBoxConditions(ctx context.Context, params GetPenaltyB if err != nil { return nil, fmt.Errorf("get penalty box condition request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -131,6 +134,8 @@ func (p *appsec) UpdatePenaltyBoxConditions(ctx context.Context, params UpdatePe if err != nil { return nil, fmt.Errorf("update penalty box condition request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/rate_policy.go b/pkg/appsec/rate_policy.go index 6c73a1b4..71e56958 100644 --- a/pkg/appsec/rate_policy.go +++ b/pkg/appsec/rate_policy.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -400,6 +401,8 @@ func (p *appsec) GetRatePolicy(ctx context.Context, params GetRatePolicyRequest) if err != nil { return nil, fmt.Errorf("get rate policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -431,6 +434,8 @@ func (p *appsec) GetRatePolicies(ctx context.Context, params GetRatePoliciesRequ if err != nil { return nil, fmt.Errorf("get rate policies request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -474,6 +479,8 @@ func (p *appsec) UpdateRatePolicy(ctx context.Context, params UpdateRatePolicyRe if err != nil { return nil, fmt.Errorf("update rate policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -506,6 +513,8 @@ func (p *appsec) CreateRatePolicy(ctx context.Context, params CreateRatePolicyRe if err != nil { return nil, fmt.Errorf("create rate policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -532,6 +541,8 @@ func (p *appsec) RemoveRatePolicy(ctx context.Context, params RemoveRatePolicyRe if err != nil { return nil, fmt.Errorf("remove rate policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/rate_policy_action.go b/pkg/appsec/rate_policy_action.go index 8e0ad080..8e77a863 100644 --- a/pkg/appsec/rate_policy_action.go +++ b/pkg/appsec/rate_policy_action.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -148,6 +149,8 @@ func (p *appsec) GetRatePolicyAction(ctx context.Context, params GetRatePolicyAc if err != nil { return nil, fmt.Errorf("get rate policy action request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -179,6 +182,8 @@ func (p *appsec) GetRatePolicyActions(ctx context.Context, params GetRatePolicyA if err != nil { return nil, fmt.Errorf("get rate policy actions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -222,6 +227,8 @@ func (p *appsec) UpdateRatePolicyAction(ctx context.Context, params UpdateRatePo if err != nil { return nil, fmt.Errorf("update rate policy action request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/rate_protection.go b/pkg/appsec/rate_protection.go index ddaebd4a..72642a00 100644 --- a/pkg/appsec/rate_protection.go +++ b/pkg/appsec/rate_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -118,6 +119,8 @@ func (p *appsec) GetRateProtection(ctx context.Context, params GetRateProtection if err != nil { return nil, fmt.Errorf("get rate protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -149,6 +152,8 @@ func (p *appsec) GetRateProtections(ctx context.Context, params GetRateProtectio if err != nil { return nil, fmt.Errorf("get rate protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -181,6 +186,8 @@ func (p *appsec) UpdateRateProtection(ctx context.Context, params UpdateRateProt if err != nil { return nil, fmt.Errorf("update rate protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/reputation_analysis.go b/pkg/appsec/reputation_analysis.go index f1571bae..2fdb634c 100644 --- a/pkg/appsec/reputation_analysis.go +++ b/pkg/appsec/reputation_analysis.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -126,6 +127,8 @@ func (p *appsec) GetReputationAnalysis(ctx context.Context, params GetReputation if err != nil { return nil, fmt.Errorf("get reputation analysis request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -158,6 +161,8 @@ func (p *appsec) UpdateReputationAnalysis(ctx context.Context, params UpdateRepu if err != nil { return nil, fmt.Errorf("update reputation analysis request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -186,6 +191,8 @@ func (p *appsec) RemoveReputationAnalysis(ctx context.Context, params RemoveRepu if err != nil { return nil, fmt.Errorf("remove reputation analysis request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/reputation_profile.go b/pkg/appsec/reputation_profile.go index 019646a4..c1d1b249 100644 --- a/pkg/appsec/reputation_profile.go +++ b/pkg/appsec/reputation_profile.go @@ -7,6 +7,7 @@ import ( "net/http" "reflect" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -348,6 +349,8 @@ func (p *appsec) GetReputationProfile(ctx context.Context, params GetReputationP if err != nil { return nil, fmt.Errorf("get reputation profile request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -379,6 +382,8 @@ func (p *appsec) GetReputationProfiles(ctx context.Context, params GetReputation if err != nil { return nil, fmt.Errorf("get reputation profiles request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -422,6 +427,8 @@ func (p *appsec) UpdateReputationProfile(ctx context.Context, params UpdateReput if err != nil { return nil, fmt.Errorf("update reputation profile request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -454,6 +461,8 @@ func (p *appsec) CreateReputationProfile(ctx context.Context, params CreateReput if err != nil { return nil, fmt.Errorf("create reputation profile request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -480,6 +489,8 @@ func (p *appsec) RemoveReputationProfile(ctx context.Context, params RemoveReput if err != nil { return nil, fmt.Errorf("remove reputation profile request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/reputation_profile_action.go b/pkg/appsec/reputation_profile_action.go index a34044f1..d9d3dde5 100644 --- a/pkg/appsec/reputation_profile_action.go +++ b/pkg/appsec/reputation_profile_action.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -132,6 +133,8 @@ func (p *appsec) GetReputationProfileAction(ctx context.Context, params GetReput if err != nil { return nil, fmt.Errorf("get reputation profile action request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -163,6 +166,8 @@ func (p *appsec) GetReputationProfileActions(ctx context.Context, params GetRepu if err != nil { return nil, fmt.Errorf("get reputation profile actions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -206,6 +211,8 @@ func (p *appsec) UpdateReputationProfileAction(ctx context.Context, params Updat if err != nil { return nil, fmt.Errorf("update reputation profile action request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/reputation_protection.go b/pkg/appsec/reputation_protection.go index 353eb78c..d33a0cf8 100644 --- a/pkg/appsec/reputation_protection.go +++ b/pkg/appsec/reputation_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -147,6 +148,8 @@ func (p *appsec) GetReputationProtection(ctx context.Context, params GetReputati if err != nil { return nil, fmt.Errorf("get reputation protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -178,6 +181,8 @@ func (p *appsec) GetReputationProtections(ctx context.Context, params GetReputat if err != nil { return nil, fmt.Errorf("get reputation protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -210,6 +215,8 @@ func (p *appsec) UpdateReputationProtection(ctx context.Context, params UpdateRe if err != nil { return nil, fmt.Errorf("update reputation protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -242,6 +249,8 @@ func (p *appsec) RemoveReputationProtection(ctx context.Context, params RemoveRe if err != nil { return nil, fmt.Errorf("remove reputation protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/rule.go b/pkg/appsec/rule.go index 30d7bb04..92f59402 100644 --- a/pkg/appsec/rule.go +++ b/pkg/appsec/rule.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -230,6 +231,8 @@ func (p *appsec) GetRule(ctx context.Context, params GetRuleRequest) (*GetRuleRe if err != nil { return nil, fmt.Errorf("get rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -261,6 +264,8 @@ func (p *appsec) GetRules(ctx context.Context, params GetRulesRequest) (*GetRule if err != nil { return nil, fmt.Errorf("get rules request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -304,6 +309,8 @@ func (p *appsec) UpdateRule(ctx context.Context, params UpdateRuleRequest) (*Upd if err != nil { return nil, fmt.Errorf("update rule request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -337,6 +344,8 @@ func (p *appsec) UpdateRuleConditionException(ctx context.Context, params Update if err != nil { return nil, fmt.Errorf("update rule condition exception request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/rule_upgrade.go b/pkg/appsec/rule_upgrade.go index 9bb47ba6..ca1fa378 100644 --- a/pkg/appsec/rule_upgrade.go +++ b/pkg/appsec/rule_upgrade.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -122,6 +123,8 @@ func (p *appsec) GetRuleUpgrade(ctx context.Context, params GetRuleUpgradeReques if err != nil { return nil, fmt.Errorf("get rule upgrade request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -154,6 +157,8 @@ func (p *appsec) UpdateRuleUpgrade(ctx context.Context, params UpdateRuleUpgrade if err != nil { return nil, fmt.Errorf("update rule upgrade request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/security_policy.go b/pkg/appsec/security_policy.go index 56546423..09b0e5dd 100644 --- a/pkg/appsec/security_policy.go +++ b/pkg/appsec/security_policy.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -228,6 +229,8 @@ func (p *appsec) GetSecurityPolicies(ctx context.Context, params GetSecurityPoli if err != nil { return nil, fmt.Errorf("get security policies request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -265,6 +268,8 @@ func (p *appsec) GetSecurityPolicy(ctx context.Context, params GetSecurityPolicy if err != nil { return nil, fmt.Errorf("get security policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -297,6 +302,8 @@ func (p *appsec) UpdateSecurityPolicy(ctx context.Context, params UpdateSecurity if err != nil { return nil, fmt.Errorf("update security policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -327,6 +334,8 @@ func (p *appsec) CreateSecurityPolicy(ctx context.Context, params CreateSecurity if err != nil { return nil, fmt.Errorf("create security policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -357,6 +366,8 @@ func (p *appsec) CreateSecurityPolicyWithDefaultProtections(ctx context.Context, if err != nil { return nil, fmt.Errorf("create security policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -383,6 +394,8 @@ func (p *appsec) RemoveSecurityPolicy(ctx context.Context, params RemoveSecurity if err != nil { return nil, fmt.Errorf("remove security policy request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/security_policy_clone.go b/pkg/appsec/security_policy_clone.go index 20ca7779..413a8db6 100644 --- a/pkg/appsec/security_policy_clone.go +++ b/pkg/appsec/security_policy_clone.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -200,6 +201,8 @@ func (p *appsec) GetSecurityPolicyClone(ctx context.Context, params GetSecurityP if err != nil { return nil, fmt.Errorf("get security policy clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -230,6 +233,8 @@ func (p *appsec) GetSecurityPolicyClones(ctx context.Context, params GetSecurity if err != nil { return nil, fmt.Errorf("get security policy clones request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -260,6 +265,8 @@ func (p *appsec) CreateSecurityPolicyClone(ctx context.Context, params CreateSec if err != nil { return nil, fmt.Errorf("create security policy clone request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/security_policy_protections.go b/pkg/appsec/security_policy_protections.go index 11ff4bf9..2944f7aa 100644 --- a/pkg/appsec/security_policy_protections.go +++ b/pkg/appsec/security_policy_protections.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -130,6 +131,8 @@ func (p *appsec) GetPolicyProtections(ctx context.Context, params GetPolicyProte if err != nil { return nil, fmt.Errorf("get policy protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -162,6 +165,8 @@ func (p *appsec) UpdatePolicyProtections(ctx context.Context, params UpdatePolic if err != nil { return nil, fmt.Errorf("update policy protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -194,6 +199,8 @@ func (p *appsec) RemovePolicyProtections(ctx context.Context, params UpdatePolic if err != nil { return nil, fmt.Errorf("remove policy protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/selectable_hostnames.go b/pkg/appsec/selectable_hostnames.go index d8703612..cca0b10c 100644 --- a/pkg/appsec/selectable_hostnames.go +++ b/pkg/appsec/selectable_hostnames.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -69,6 +71,8 @@ func (p *appsec) GetSelectableHostnames(ctx context.Context, params GetSelectabl if err != nil { return nil, fmt.Errorf("get selectable hostnames request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/selected_hostname.go b/pkg/appsec/selected_hostname.go index a3c6c4f3..c0c7fbbe 100644 --- a/pkg/appsec/selected_hostname.go +++ b/pkg/appsec/selected_hostname.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -156,6 +157,8 @@ func (p *appsec) GetSelectedHostname(ctx context.Context, params GetSelectedHost if err != nil { return nil, fmt.Errorf("get selected hostname request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -186,6 +189,8 @@ func (p *appsec) GetSelectedHostnames(ctx context.Context, params GetSelectedHos if err != nil { return nil, fmt.Errorf("get selected hostnames request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -217,6 +222,8 @@ func (p *appsec) UpdateSelectedHostnames(ctx context.Context, params UpdateSelec if err != nil { return nil, fmt.Errorf("update selected hostnames request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -249,6 +256,8 @@ func (p *appsec) UpdateSelectedHostname(ctx context.Context, params UpdateSelect if err != nil { return nil, fmt.Errorf("update selected hostname request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/siem_definitions.go b/pkg/appsec/siem_definitions.go index e534dd62..3520666e 100644 --- a/pkg/appsec/siem_definitions.go +++ b/pkg/appsec/siem_definitions.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -46,6 +48,8 @@ func (p *appsec) GetSiemDefinitions(ctx context.Context, params GetSiemDefinitio if err != nil { return nil, fmt.Errorf("get siem definitions request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/siem_settings.go b/pkg/appsec/siem_settings.go index ec6b4eb6..eec7c5fd 100644 --- a/pkg/appsec/siem_settings.go +++ b/pkg/appsec/siem_settings.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -170,6 +171,8 @@ func (p *appsec) GetSiemSettings(ctx context.Context, params GetSiemSettingsRequ if err != nil { return nil, fmt.Errorf("get siem settings request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -201,6 +204,8 @@ func (p *appsec) UpdateSiemSettings(ctx context.Context, params UpdateSiemSettin if err != nil { return nil, fmt.Errorf("update siem settings request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -233,6 +238,8 @@ func (p *appsec) RemoveSiemSettings(ctx context.Context, params RemoveSiemSettin if err != nil { return nil, fmt.Errorf("remove siem settings request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/slow_post_protection_setting.go b/pkg/appsec/slow_post_protection_setting.go index 7ca63f0d..b9c55716 100644 --- a/pkg/appsec/slow_post_protection_setting.go +++ b/pkg/appsec/slow_post_protection_setting.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -163,6 +164,8 @@ func (p *appsec) GetSlowPostProtectionSetting(ctx context.Context, params GetSlo if err != nil { return nil, fmt.Errorf("get slow post protection setting request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -194,6 +197,8 @@ func (p *appsec) GetSlowPostProtectionSettings(ctx context.Context, params GetSl if err != nil { return nil, fmt.Errorf("get slow post protection settings request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -226,6 +231,8 @@ func (p *appsec) UpdateSlowPostProtectionSetting(ctx context.Context, params Upd if err != nil { return nil, fmt.Errorf("update slow post protection setting request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/slowpost_protection.go b/pkg/appsec/slowpost_protection.go index f04335eb..219ce221 100644 --- a/pkg/appsec/slowpost_protection.go +++ b/pkg/appsec/slowpost_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -118,6 +119,8 @@ func (p *appsec) GetSlowPostProtection(ctx context.Context, params GetSlowPostPr if err != nil { return nil, fmt.Errorf("get slow post protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -149,6 +152,8 @@ func (p *appsec) GetSlowPostProtections(ctx context.Context, params GetSlowPostP if err != nil { return nil, fmt.Errorf("get slow post protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -181,6 +186,8 @@ func (p *appsec) UpdateSlowPostProtection(ctx context.Context, params UpdateSlow if err != nil { return nil, fmt.Errorf("update slow post protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/threat_intel.go b/pkg/appsec/threat_intel.go index 0776d17a..9de08650 100644 --- a/pkg/appsec/threat_intel.go +++ b/pkg/appsec/threat_intel.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -90,6 +91,8 @@ func (p *appsec) GetThreatIntel(ctx context.Context, params GetThreatIntelReques if err != nil { return nil, fmt.Errorf("get threat intel request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -122,6 +125,8 @@ func (p *appsec) UpdateThreatIntel(ctx context.Context, params UpdateThreatIntel if err != nil { return nil, fmt.Errorf("update threat intel request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/tuning_recommendations.go b/pkg/appsec/tuning_recommendations.go index 194cc443..254db235 100644 --- a/pkg/appsec/tuning_recommendations.go +++ b/pkg/appsec/tuning_recommendations.go @@ -6,6 +6,7 @@ import ( "net/http" "time" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -152,6 +153,8 @@ func (p *appsec) GetTuningRecommendations(ctx context.Context, params GetTuningR if err != nil { return nil, fmt.Errorf("get tuning recommendations request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -188,6 +191,8 @@ func (p *appsec) GetAttackGroupRecommendations(ctx context.Context, params GetAt if err != nil { return nil, fmt.Errorf("get attack group recommendations request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -224,6 +229,8 @@ func (p *appsec) GetRuleRecommendations(ctx context.Context, params GetRuleRecom if err != nil { return nil, fmt.Errorf("get rule recommendations request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } diff --git a/pkg/appsec/version_notes.go b/pkg/appsec/version_notes.go index 4c391135..6bc53e0f 100644 --- a/pkg/appsec/version_notes.go +++ b/pkg/appsec/version_notes.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -87,6 +88,8 @@ func (p *appsec) GetVersionNotes(ctx context.Context, params GetVersionNotesRequ if err != nil { return nil, fmt.Errorf("get version notes request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -118,6 +121,8 @@ func (p *appsec) UpdateVersionNotes(ctx context.Context, params UpdateVersionNot if err != nil { return nil, fmt.Errorf("update version notes request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/waf_mode.go b/pkg/appsec/waf_mode.go index c2f08dc6..05e67357 100644 --- a/pkg/appsec/waf_mode.go +++ b/pkg/appsec/waf_mode.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -138,6 +139,8 @@ func (p *appsec) GetWAFMode(ctx context.Context, params GetWAFModeRequest) (*Get if err != nil { return nil, fmt.Errorf("get WAF mode request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -170,6 +173,8 @@ func (p *appsec) GetWAFModes(ctx context.Context, params GetWAFModesRequest) (*G if err != nil { return nil, fmt.Errorf("get WAF modes request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -202,6 +207,8 @@ func (p *appsec) UpdateWAFMode(ctx context.Context, params UpdateWAFModeRequest) if err != nil { return nil, fmt.Errorf("update WAF mode request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/waf_protection.go b/pkg/appsec/waf_protection.go index 5d724857..814cd27a 100644 --- a/pkg/appsec/waf_protection.go +++ b/pkg/appsec/waf_protection.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -118,6 +119,8 @@ func (p *appsec) GetWAFProtection(ctx context.Context, params GetWAFProtectionRe if err != nil { return nil, fmt.Errorf("get WAF protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -149,6 +152,8 @@ func (p *appsec) GetWAFProtections(ctx context.Context, params GetWAFProtections if err != nil { return nil, fmt.Errorf("get WAF protections request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -181,6 +186,8 @@ func (p *appsec) UpdateWAFProtection(ctx context.Context, params UpdateWAFProtec if err != nil { return nil, fmt.Errorf("update WAF protection request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/wap_bypass_network_lists.go b/pkg/appsec/wap_bypass_network_lists.go index 2621c79c..6ebb3485 100644 --- a/pkg/appsec/wap_bypass_network_lists.go +++ b/pkg/appsec/wap_bypass_network_lists.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -146,6 +147,8 @@ func (p *appsec) GetWAPBypassNetworkLists(ctx context.Context, params GetWAPBypa if err != nil { return nil, fmt.Errorf("get WAP bypass network lists request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -178,6 +181,8 @@ func (p *appsec) UpdateWAPBypassNetworkLists(ctx context.Context, params UpdateW if err != nil { return nil, fmt.Errorf("update WAP bypass network lists request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } @@ -211,6 +216,8 @@ func (p *appsec) RemoveWAPBypassNetworkLists(ctx context.Context, params RemoveW if err != nil { return nil, fmt.Errorf("remove WAP bypass network lists request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/appsec/wap_selected_hostnames.go b/pkg/appsec/wap_selected_hostnames.go index c339b1be..c42d81e9 100644 --- a/pkg/appsec/wap_selected_hostnames.go +++ b/pkg/appsec/wap_selected_hostnames.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -87,6 +88,8 @@ func (p *appsec) GetWAPSelectedHostnames(ctx context.Context, params GetWAPSelec if err != nil { return nil, fmt.Errorf("get WAP selected hostnames request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) } @@ -119,6 +122,8 @@ func (p *appsec) UpdateWAPSelectedHostnames(ctx context.Context, params UpdateWA if err != nil { return nil, fmt.Errorf("update WAP selected hostnames request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) } diff --git a/pkg/botman/akamai_bot_category.go b/pkg/botman/akamai_bot_category.go index 10419990..dad082cc 100644 --- a/pkg/botman/akamai_bot_category.go +++ b/pkg/botman/akamai_bot_category.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -40,6 +42,7 @@ func (b *botman) GetAkamaiBotCategoryList(ctx context.Context, params GetAkamaiB if err != nil { return nil, fmt.Errorf("GetAkamaiBotCategoryList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/akamai_bot_category_action.go b/pkg/botman/akamai_bot_category_action.go index f733ebcb..a0ee5e9a 100644 --- a/pkg/botman/akamai_bot_category_action.go +++ b/pkg/botman/akamai_bot_category_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -109,6 +110,7 @@ func (b *botman) GetAkamaiBotCategoryAction(ctx context.Context, params GetAkama if err != nil { return nil, fmt.Errorf("GetAkamaiBotCategoryAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -141,6 +143,7 @@ func (b *botman) GetAkamaiBotCategoryActionList(ctx context.Context, params GetA if err != nil { return nil, fmt.Errorf("GetAkamaiBotCategoryActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -185,6 +188,7 @@ func (b *botman) UpdateAkamaiBotCategoryAction(ctx context.Context, params Updat if err != nil { return nil, fmt.Errorf("UpdateAkamaiBotCategoryAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/akamai_defined_bot.go b/pkg/botman/akamai_defined_bot.go index 65e87d66..27ed3b8e 100644 --- a/pkg/botman/akamai_defined_bot.go +++ b/pkg/botman/akamai_defined_bot.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -41,6 +43,7 @@ func (b *botman) GetAkamaiDefinedBotList(ctx context.Context, params GetAkamaiDe if err != nil { return nil, fmt.Errorf("GetAkamaiDefinedBotList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_analytics_cookie.go b/pkg/botman/bot_analytics_cookie.go index a400f498..b7cf5e1b 100644 --- a/pkg/botman/bot_analytics_cookie.go +++ b/pkg/botman/bot_analytics_cookie.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -74,6 +75,7 @@ func (b *botman) GetBotAnalyticsCookie(ctx context.Context, params GetBotAnalyti if err != nil { return nil, fmt.Errorf("GetBotAnalyticsCookie request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -106,6 +108,7 @@ func (b *botman) UpdateBotAnalyticsCookie(ctx context.Context, params UpdateBotA if err != nil { return nil, fmt.Errorf("UpdateBotAnalyticsCookie request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_analytics_cookie_values.go b/pkg/botman/bot_analytics_cookie_values.go index cfa20e72..aabe2673 100644 --- a/pkg/botman/bot_analytics_cookie_values.go +++ b/pkg/botman/bot_analytics_cookie_values.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -31,6 +33,7 @@ func (b *botman) GetBotAnalyticsCookieValues(ctx context.Context) (map[string]in if err != nil { return nil, fmt.Errorf("GetBotAnalyticsCookieValues request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_category_exception.go b/pkg/botman/bot_category_exception.go index 6c5f3fae..6e4bca01 100644 --- a/pkg/botman/bot_category_exception.go +++ b/pkg/botman/bot_category_exception.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -79,6 +80,7 @@ func (b *botman) GetBotCategoryException(ctx context.Context, params GetBotCateg if err != nil { return nil, fmt.Errorf("GetBotCategoryException request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -112,6 +114,7 @@ func (b *botman) UpdateBotCategoryException(ctx context.Context, params UpdateBo if err != nil { return nil, fmt.Errorf("UpdateBotCategoryException request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_detection.go b/pkg/botman/bot_detection.go index 6f871a85..512d7f0b 100644 --- a/pkg/botman/bot_detection.go +++ b/pkg/botman/bot_detection.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -41,6 +43,7 @@ func (b *botman) GetBotDetectionList(ctx context.Context, params GetBotDetection if err != nil { return nil, fmt.Errorf("GetBotDetectionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_detection_action.go b/pkg/botman/bot_detection_action.go index 71f755a3..14952bba 100644 --- a/pkg/botman/bot_detection_action.go +++ b/pkg/botman/bot_detection_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -107,6 +108,7 @@ func (b *botman) GetBotDetectionAction(ctx context.Context, params GetBotDetecti if err != nil { return nil, fmt.Errorf("GetBotDetectionAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -139,6 +141,7 @@ func (b *botman) GetBotDetectionActionList(ctx context.Context, params GetBotDet if err != nil { return nil, fmt.Errorf("GetBotDetectionActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -183,6 +186,7 @@ func (b *botman) UpdateBotDetectionAction(ctx context.Context, params UpdateBotD if err != nil { return nil, fmt.Errorf("UpdateBotDetectionAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_endpoint_coverage_report.go b/pkg/botman/bot_endpoint_coverage_report.go index e2158ff3..40bf2391 100644 --- a/pkg/botman/bot_endpoint_coverage_report.go +++ b/pkg/botman/bot_endpoint_coverage_report.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -61,6 +62,7 @@ func (b *botman) GetBotEndpointCoverageReport(ctx context.Context, params GetBot if err != nil { return nil, fmt.Errorf("GetBotEndpointCoverageReport request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/bot_management_setting.go b/pkg/botman/bot_management_setting.go index dfaeb0e6..f0737608 100644 --- a/pkg/botman/bot_management_setting.go +++ b/pkg/botman/bot_management_setting.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -79,6 +80,7 @@ func (b *botman) GetBotManagementSetting(ctx context.Context, params GetBotManag if err != nil { return nil, fmt.Errorf("GetBotManagementSetting request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -112,6 +114,7 @@ func (b *botman) UpdateBotManagementSetting(ctx context.Context, params UpdateBo if err != nil { return nil, fmt.Errorf("UpdateBotManagementSetting request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/challenge_action.go b/pkg/botman/challenge_action.go index 7ed9605f..53a278cc 100644 --- a/pkg/botman/challenge_action.go +++ b/pkg/botman/challenge_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -161,6 +162,7 @@ func (b *botman) GetChallengeAction(ctx context.Context, params GetChallengeActi if err != nil { return nil, fmt.Errorf("GetChallengeAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -193,6 +195,7 @@ func (b *botman) GetChallengeActionList(ctx context.Context, params GetChallenge if err != nil { return nil, fmt.Errorf("GetChallengeActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -236,6 +239,7 @@ func (b *botman) UpdateChallengeAction(ctx context.Context, params UpdateChallen if err != nil { return nil, fmt.Errorf("UpdateChallengeAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -268,6 +272,7 @@ func (b *botman) CreateChallengeAction(ctx context.Context, params CreateChallen if err != nil { return nil, fmt.Errorf("CreateChallengeAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -299,6 +304,7 @@ func (b *botman) RemoveChallengeAction(ctx context.Context, params RemoveChallen if err != nil { return fmt.Errorf("RemoveChallengeAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) @@ -332,6 +338,7 @@ func (b *botman) UpdateGoogleReCaptchaSecretKey(ctx context.Context, params Upda if err != nil { return fmt.Errorf("UpdateGoogleReCaptchaSecretKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/challenge_injection_rules.go b/pkg/botman/challenge_injection_rules.go index 019b5785..f52e532d 100644 --- a/pkg/botman/challenge_injection_rules.go +++ b/pkg/botman/challenge_injection_rules.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -73,6 +74,7 @@ func (b *botman) GetChallengeInjectionRules(ctx context.Context, params GetChall if err != nil { return nil, fmt.Errorf("GetChallengeInjectionRules request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -105,6 +107,7 @@ func (b *botman) UpdateChallengeInjectionRules(ctx context.Context, params Updat if err != nil { return nil, fmt.Errorf("UpdateChallengeInjectionRules request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/challenge_interception_rules.go b/pkg/botman/challenge_interception_rules.go index 34e64a21..03834ba9 100644 --- a/pkg/botman/challenge_interception_rules.go +++ b/pkg/botman/challenge_interception_rules.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -78,6 +79,7 @@ func (b *botman) GetChallengeInterceptionRules(ctx context.Context, params GetCh if err != nil { return nil, fmt.Errorf("GetChallengeInterceptionRules request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -110,6 +112,7 @@ func (b *botman) UpdateChallengeInterceptionRules(ctx context.Context, params Up if err != nil { return nil, fmt.Errorf("UpdateChallengeInterceptionRules request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/client_side_security.go b/pkg/botman/client_side_security.go index b1534925..63937a04 100644 --- a/pkg/botman/client_side_security.go +++ b/pkg/botman/client_side_security.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -74,6 +75,7 @@ func (b *botman) GetClientSideSecurity(ctx context.Context, params GetClientSide if err != nil { return nil, fmt.Errorf("GetClientSideSecurity request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -106,6 +108,7 @@ func (b *botman) UpdateClientSideSecurity(ctx context.Context, params UpdateClie if err != nil { return nil, fmt.Errorf("UpdateClientSideSecurity request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { return nil, b.Error(resp) diff --git a/pkg/botman/conditional_action.go b/pkg/botman/conditional_action.go index 42dac6be..66ad5b06 100644 --- a/pkg/botman/conditional_action.go +++ b/pkg/botman/conditional_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -140,6 +141,7 @@ func (b *botman) GetConditionalAction(ctx context.Context, params GetConditional if err != nil { return nil, fmt.Errorf("GetConditionalAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -172,6 +174,7 @@ func (b *botman) GetConditionalActionList(ctx context.Context, params GetConditi if err != nil { return nil, fmt.Errorf("GetConditionalActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -215,6 +218,7 @@ func (b *botman) UpdateConditionalAction(ctx context.Context, params UpdateCondi if err != nil { return nil, fmt.Errorf("UpdateConditionalAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -247,6 +251,7 @@ func (b *botman) CreateConditionalAction(ctx context.Context, params CreateCondi if err != nil { return nil, fmt.Errorf("CreateConditionalAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -278,6 +283,7 @@ func (b *botman) RemoveConditionalAction(ctx context.Context, params RemoveCondi if err != nil { return fmt.Errorf("RemoveConditionalAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/content_protection_javascript_injection_rule.go b/pkg/botman/content_protection_javascript_injection_rule.go index 96428d31..0e7ba1e9 100644 --- a/pkg/botman/content_protection_javascript_injection_rule.go +++ b/pkg/botman/content_protection_javascript_injection_rule.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -151,6 +152,7 @@ func (b *botman) GetContentProtectionJavaScriptInjectionRule(ctx context.Context if err != nil { return nil, fmt.Errorf("GetContentProtectionJavaScriptInjectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -184,6 +186,7 @@ func (b *botman) GetContentProtectionJavaScriptInjectionRuleList(ctx context.Con if err != nil { return nil, fmt.Errorf("GetContentProtectionJavaScriptInjectionRuleList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -228,6 +231,7 @@ func (b *botman) UpdateContentProtectionJavaScriptInjectionRule(ctx context.Cont if err != nil { return nil, fmt.Errorf("UpdateContentProtectionJavaScriptInjectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -261,6 +265,7 @@ func (b *botman) CreateContentProtectionJavaScriptInjectionRule(ctx context.Cont if err != nil { return nil, fmt.Errorf("CreateContentProtectionJavaScriptInjectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -293,6 +298,7 @@ func (b *botman) RemoveContentProtectionJavaScriptInjectionRule(ctx context.Cont if err != nil { return fmt.Errorf("RemoveContentProtectionJavaScriptInjectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/content_protection_rule.go b/pkg/botman/content_protection_rule.go index 21a177d0..06d073a9 100644 --- a/pkg/botman/content_protection_rule.go +++ b/pkg/botman/content_protection_rule.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -151,6 +152,7 @@ func (b *botman) GetContentProtectionRule(ctx context.Context, params GetContent if err != nil { return nil, fmt.Errorf("GetContentProtectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -184,6 +186,7 @@ func (b *botman) GetContentProtectionRuleList(ctx context.Context, params GetCon if err != nil { return nil, fmt.Errorf("GetContentProtectionRuleList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -228,6 +231,7 @@ func (b *botman) UpdateContentProtectionRule(ctx context.Context, params UpdateC if err != nil { return nil, fmt.Errorf("UpdateContentProtectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -261,6 +265,7 @@ func (b *botman) CreateContentProtectionRule(ctx context.Context, params CreateC if err != nil { return nil, fmt.Errorf("CreateContentProtectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -293,6 +298,7 @@ func (b *botman) RemoveContentProtectionRule(ctx context.Context, params RemoveC if err != nil { return fmt.Errorf("RemoveContentProtectionRule request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/content_protection_rule_sequence.go b/pkg/botman/content_protection_rule_sequence.go index 47f09811..ec1d1ef9 100644 --- a/pkg/botman/content_protection_rule_sequence.go +++ b/pkg/botman/content_protection_rule_sequence.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -88,6 +89,7 @@ func (b *botman) GetContentProtectionRuleSequence(ctx context.Context, params Ge if err != nil { return nil, fmt.Errorf("GetContentProtectionRuleSequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -120,6 +122,7 @@ func (b *botman) UpdateContentProtectionRuleSequence(ctx context.Context, params if err != nil { return nil, fmt.Errorf("UpdateContentProtectionRuleSequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/custom_bot_category.go b/pkg/botman/custom_bot_category.go index efe32aa9..db2d3391 100644 --- a/pkg/botman/custom_bot_category.go +++ b/pkg/botman/custom_bot_category.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -140,6 +141,7 @@ func (b *botman) GetCustomBotCategory(ctx context.Context, params GetCustomBotCa if err != nil { return nil, fmt.Errorf("GetCustomBotCategory request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -172,6 +174,7 @@ func (b *botman) GetCustomBotCategoryList(ctx context.Context, params GetCustomB if err != nil { return nil, fmt.Errorf("GetCustomBotCategoryList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -215,6 +218,7 @@ func (b *botman) UpdateCustomBotCategory(ctx context.Context, params UpdateCusto if err != nil { return nil, fmt.Errorf("UpdateCustomBotCategory request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -247,6 +251,7 @@ func (b *botman) CreateCustomBotCategory(ctx context.Context, params CreateCusto if err != nil { return nil, fmt.Errorf("CreateCustomBotCategory request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -278,6 +283,7 @@ func (b *botman) RemoveCustomBotCategory(ctx context.Context, params RemoveCusto if err != nil { return fmt.Errorf("RemoveCustomBotCategory request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/custom_bot_category_action.go b/pkg/botman/custom_bot_category_action.go index 34e3207f..930691b2 100644 --- a/pkg/botman/custom_bot_category_action.go +++ b/pkg/botman/custom_bot_category_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -109,6 +110,7 @@ func (b *botman) GetCustomBotCategoryAction(ctx context.Context, params GetCusto if err != nil { return nil, fmt.Errorf("GetCustomBotCategoryAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -141,6 +143,7 @@ func (b *botman) GetCustomBotCategoryActionList(ctx context.Context, params GetC if err != nil { return nil, fmt.Errorf("GetCustomBotCategoryActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -185,6 +188,7 @@ func (b *botman) UpdateCustomBotCategoryAction(ctx context.Context, params Updat if err != nil { return nil, fmt.Errorf("UpdateCustomBotCategoryAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/custom_bot_category_item_sequence.go b/pkg/botman/custom_bot_category_item_sequence.go index fef932d6..ee35e9dc 100644 --- a/pkg/botman/custom_bot_category_item_sequence.go +++ b/pkg/botman/custom_bot_category_item_sequence.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -88,6 +89,7 @@ func (b *botman) GetCustomBotCategoryItemSequence(ctx context.Context, params Ge if err != nil { return nil, fmt.Errorf("GetCustomBotCategoryItemSequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -120,6 +122,7 @@ func (b *botman) UpdateCustomBotCategoryItemSequence(ctx context.Context, params if err != nil { return nil, fmt.Errorf("UpdateCustomBotCategoryItemSequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/custom_bot_category_sequence.go b/pkg/botman/custom_bot_category_sequence.go index 17266b62..5632517c 100644 --- a/pkg/botman/custom_bot_category_sequence.go +++ b/pkg/botman/custom_bot_category_sequence.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -77,6 +78,7 @@ func (b *botman) GetCustomBotCategorySequence(ctx context.Context, params GetCus if err != nil { return nil, fmt.Errorf("GetCustomBotCategorySequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -108,6 +110,7 @@ func (b *botman) UpdateCustomBotCategorySequence(ctx context.Context, params Upd if err != nil { return nil, fmt.Errorf("UpdateCustomBotCategorySequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/custom_client.go b/pkg/botman/custom_client.go index efbc99bf..43391d95 100644 --- a/pkg/botman/custom_client.go +++ b/pkg/botman/custom_client.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -139,6 +140,7 @@ func (b *botman) GetCustomClient(ctx context.Context, params GetCustomClientRequ if err != nil { return nil, fmt.Errorf("GetCustomClient request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -171,6 +173,7 @@ func (b *botman) GetCustomClientList(ctx context.Context, params GetCustomClient if err != nil { return nil, fmt.Errorf("GetCustomClientList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -214,6 +217,7 @@ func (b *botman) UpdateCustomClient(ctx context.Context, params UpdateCustomClie if err != nil { return nil, fmt.Errorf("UpdateCustomClient request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -246,6 +250,7 @@ func (b *botman) CreateCustomClient(ctx context.Context, params CreateCustomClie if err != nil { return nil, fmt.Errorf("CreateCustomClient request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -277,6 +282,7 @@ func (b *botman) RemoveCustomClient(ctx context.Context, params RemoveCustomClie if err != nil { return fmt.Errorf("RemoveCustomClient request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/custom_client_sequence.go b/pkg/botman/custom_client_sequence.go index 1a383453..c1cbb208 100644 --- a/pkg/botman/custom_client_sequence.go +++ b/pkg/botman/custom_client_sequence.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -81,6 +82,7 @@ func (b *botman) GetCustomClientSequence(ctx context.Context, params GetCustomCl if err != nil { return nil, fmt.Errorf("GetCustomClientSequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -112,6 +114,7 @@ func (b *botman) UpdateCustomClientSequence(ctx context.Context, params UpdateCu if err != nil { return nil, fmt.Errorf("UpdateCustomClientSequence request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/custom_code.go b/pkg/botman/custom_code.go index 02dfa46f..e81947f1 100644 --- a/pkg/botman/custom_code.go +++ b/pkg/botman/custom_code.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -71,6 +72,7 @@ func (b *botman) GetCustomCode(ctx context.Context, params GetCustomCodeRequest) if err != nil { return nil, fmt.Errorf("GetCustomCode request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -103,6 +105,7 @@ func (b *botman) UpdateCustomCode(ctx context.Context, params UpdateCustomCodeRe if err != nil { return nil, fmt.Errorf("UpdateCustomCode request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { return nil, b.Error(resp) diff --git a/pkg/botman/custom_defined_bot.go b/pkg/botman/custom_defined_bot.go index 296b5591..e8d385e1 100644 --- a/pkg/botman/custom_defined_bot.go +++ b/pkg/botman/custom_defined_bot.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -140,6 +141,7 @@ func (b *botman) GetCustomDefinedBot(ctx context.Context, params GetCustomDefine if err != nil { return nil, fmt.Errorf("GetCustomDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -172,6 +174,7 @@ func (b *botman) GetCustomDefinedBotList(ctx context.Context, params GetCustomDe if err != nil { return nil, fmt.Errorf("GetCustomDefinedBotList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -215,6 +218,7 @@ func (b *botman) UpdateCustomDefinedBot(ctx context.Context, params UpdateCustom if err != nil { return nil, fmt.Errorf("UpdateCustomDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -247,6 +251,7 @@ func (b *botman) CreateCustomDefinedBot(ctx context.Context, params CreateCustom if err != nil { return nil, fmt.Errorf("CreateCustomDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -278,6 +283,7 @@ func (b *botman) RemoveCustomDefinedBot(ctx context.Context, params RemoveCustom if err != nil { return fmt.Errorf("RemoveCustomDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/custom_deny_action.go b/pkg/botman/custom_deny_action.go index 7121d9df..ed630e7d 100644 --- a/pkg/botman/custom_deny_action.go +++ b/pkg/botman/custom_deny_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -140,6 +141,7 @@ func (b *botman) GetCustomDenyAction(ctx context.Context, params GetCustomDenyAc if err != nil { return nil, fmt.Errorf("GetCustomDenyAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -172,6 +174,7 @@ func (b *botman) GetCustomDenyActionList(ctx context.Context, params GetCustomDe if err != nil { return nil, fmt.Errorf("GetCustomDenyActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -215,6 +218,7 @@ func (b *botman) UpdateCustomDenyAction(ctx context.Context, params UpdateCustom if err != nil { return nil, fmt.Errorf("UpdateCustomDenyAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -247,6 +251,7 @@ func (b *botman) CreateCustomDenyAction(ctx context.Context, params CreateCustom if err != nil { return nil, fmt.Errorf("CreateCustomDenyAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -279,6 +284,7 @@ func (b *botman) RemoveCustomDenyAction(ctx context.Context, params RemoveCustom if err != nil { return fmt.Errorf("RemoveCustomDenyAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/javascript_injection.go b/pkg/botman/javascript_injection.go index b93cf3f0..2a6a65ba 100644 --- a/pkg/botman/javascript_injection.go +++ b/pkg/botman/javascript_injection.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -78,6 +79,7 @@ func (b *botman) GetJavascriptInjection(ctx context.Context, params GetJavascrip if err != nil { return nil, fmt.Errorf("GetJavascriptInjection request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -111,6 +113,7 @@ func (b *botman) UpdateJavascriptInjection(ctx context.Context, params UpdateJav if err != nil { return nil, fmt.Errorf("UpdateJavascriptInjection request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/recategorized_akamai_defined_bot.go b/pkg/botman/recategorized_akamai_defined_bot.go index eb355b96..b62a957a 100644 --- a/pkg/botman/recategorized_akamai_defined_bot.go +++ b/pkg/botman/recategorized_akamai_defined_bot.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -146,6 +147,7 @@ func (b *botman) GetRecategorizedAkamaiDefinedBot(ctx context.Context, params Ge if err != nil { return nil, fmt.Errorf("GetRecategorizedAkamaiDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -178,6 +180,7 @@ func (b *botman) GetRecategorizedAkamaiDefinedBotList(ctx context.Context, param if err != nil { return nil, fmt.Errorf("GetRecategorizedAkamaiDefinedBotList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -221,6 +224,7 @@ func (b *botman) UpdateRecategorizedAkamaiDefinedBot(ctx context.Context, params if err != nil { return nil, fmt.Errorf("UpdateRecategorizedAkamaiDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -253,6 +257,7 @@ func (b *botman) CreateRecategorizedAkamaiDefinedBot(ctx context.Context, params if err != nil { return nil, fmt.Errorf("CreateRecategorizedAkamaiDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -284,6 +289,7 @@ func (b *botman) RemoveRecategorizedAkamaiDefinedBot(ctx context.Context, params if err != nil { return fmt.Errorf("RemoveRecategorizedAkamaiDefinedBot request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/response_action.go b/pkg/botman/response_action.go index 4a265572..bb97266a 100644 --- a/pkg/botman/response_action.go +++ b/pkg/botman/response_action.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -60,6 +61,7 @@ func (b *botman) GetResponseActionList(ctx context.Context, params GetResponseAc if err != nil { return nil, fmt.Errorf("GetResponseActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/botman/serve_alternate_action.go b/pkg/botman/serve_alternate_action.go index d9c53d4c..4afb63da 100644 --- a/pkg/botman/serve_alternate_action.go +++ b/pkg/botman/serve_alternate_action.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -140,6 +141,7 @@ func (b *botman) GetServeAlternateAction(ctx context.Context, params GetServeAlt if err != nil { return nil, fmt.Errorf("GetServeAlternateAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -172,6 +174,7 @@ func (b *botman) GetServeAlternateActionList(ctx context.Context, params GetServ if err != nil { return nil, fmt.Errorf("GetServeAlternateActionList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -215,6 +218,7 @@ func (b *botman) UpdateServeAlternateAction(ctx context.Context, params UpdateSe if err != nil { return nil, fmt.Errorf("UpdateServeAlternateAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -247,6 +251,7 @@ func (b *botman) CreateServeAlternateAction(ctx context.Context, params CreateSe if err != nil { return nil, fmt.Errorf("CreateServeAlternateAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -278,6 +283,7 @@ func (b *botman) RemoveServeAlternateAction(ctx context.Context, params RemoveSe if err != nil { return fmt.Errorf("RemoveServeAlternateAction request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/transactional_endpoint.go b/pkg/botman/transactional_endpoint.go index 9a60e616..6d6e15d6 100644 --- a/pkg/botman/transactional_endpoint.go +++ b/pkg/botman/transactional_endpoint.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -151,6 +152,7 @@ func (b *botman) GetTransactionalEndpoint(ctx context.Context, params GetTransac if err != nil { return nil, fmt.Errorf("GetTransactionalEndpoint request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -184,6 +186,7 @@ func (b *botman) GetTransactionalEndpointList(ctx context.Context, params GetTra if err != nil { return nil, fmt.Errorf("GetTransactionalEndpointList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -228,6 +231,7 @@ func (b *botman) UpdateTransactionalEndpoint(ctx context.Context, params UpdateT if err != nil { return nil, fmt.Errorf("UpdateTransactionalEndpoint request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -261,6 +265,7 @@ func (b *botman) CreateTransactionalEndpoint(ctx context.Context, params CreateT if err != nil { return nil, fmt.Errorf("CreateTransactionalEndpoint request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, b.Error(resp) @@ -293,6 +298,7 @@ func (b *botman) RemoveTransactionalEndpoint(ctx context.Context, params RemoveT if err != nil { return fmt.Errorf("RemoveTransactionalEndpoint request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return b.Error(resp) diff --git a/pkg/botman/transactional_endpoint_protection.go b/pkg/botman/transactional_endpoint_protection.go index 99ca9b09..621c2c7d 100644 --- a/pkg/botman/transactional_endpoint_protection.go +++ b/pkg/botman/transactional_endpoint_protection.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -74,6 +75,7 @@ func (b *botman) GetTransactionalEndpointProtection(ctx context.Context, params if err != nil { return nil, fmt.Errorf("GetTransactionalEndpointProtection request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) @@ -106,6 +108,7 @@ func (b *botman) UpdateTransactionalEndpointProtection(ctx context.Context, para if err != nil { return nil, fmt.Errorf("UpdateTransactionalEndpointProtection request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, b.Error(resp) diff --git a/pkg/clientlists/client_list.go b/pkg/clientlists/client_list.go index f972a790..5dd349ed 100644 --- a/pkg/clientlists/client_list.go +++ b/pkg/clientlists/client_list.go @@ -8,6 +8,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -220,6 +221,7 @@ func (p *clientlists) GetClientLists(ctx context.Context, params GetClientListsR if err != nil { return nil, fmt.Errorf("getClientLists request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -257,6 +259,7 @@ func (p *clientlists) GetClientList(ctx context.Context, params GetClientListReq if err != nil { return nil, fmt.Errorf("getClientList request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -285,6 +288,7 @@ func (p *clientlists) UpdateClientList(ctx context.Context, params UpdateClientL if err != nil { return nil, fmt.Errorf("updateClientList request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -313,6 +317,7 @@ func (p *clientlists) UpdateClientListItems(ctx context.Context, params UpdateCl if err != nil { return nil, fmt.Errorf("UpdateClientListItems request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -339,6 +344,7 @@ func (p *clientlists) CreateClientList(ctx context.Context, params CreateClientL if err != nil { return nil, fmt.Errorf("createClientList request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -365,6 +371,7 @@ func (p *clientlists) DeleteClientList(ctx context.Context, params DeleteClientL if err != nil { return fmt.Errorf("deleteClientList request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return p.Error(resp) diff --git a/pkg/clientlists/client_list_activation.go b/pkg/clientlists/client_list_activation.go index 40f5ddfa..b0c3e9e8 100644 --- a/pkg/clientlists/client_list_activation.go +++ b/pkg/clientlists/client_list_activation.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -147,6 +148,7 @@ func (p *clientlists) CreateActivation(ctx context.Context, params CreateActivat if err != nil { return nil, fmt.Errorf("create activation request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -176,6 +178,7 @@ func (p *clientlists) GetActivationStatus(ctx context.Context, params GetActivat if err != nil { return nil, fmt.Errorf("get activation status request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -205,6 +208,7 @@ func (p *clientlists) GetActivation(ctx context.Context, params GetActivationReq if err != nil { return nil, fmt.Errorf("get activation request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) diff --git a/pkg/cloudaccess/access_key.go b/pkg/cloudaccess/access_key.go index f46d864e..30608325 100644 --- a/pkg/cloudaccess/access_key.go +++ b/pkg/cloudaccess/access_key.go @@ -9,6 +9,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -171,6 +172,7 @@ func (c *cloudaccess) GetAccessKeyStatus(ctx context.Context, params GetAccessKe if err != nil { return nil, fmt.Errorf("GetAccessKeyStatus request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, c.Error(resp) @@ -202,6 +204,7 @@ func (c *cloudaccess) CreateAccessKey(ctx context.Context, accessKey CreateAcces if err != nil { return nil, fmt.Errorf("CreateAccessKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, c.Error(resp) @@ -236,6 +239,7 @@ func (c *cloudaccess) GetAccessKey(ctx context.Context, params AccessKeyRequest) return nil, fmt.Errorf("GetAccessKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, c.Error(resp) @@ -268,6 +272,7 @@ func (c *cloudaccess) ListAccessKeys(ctx context.Context, params ListAccessKeysR if err != nil { return nil, fmt.Errorf("ListAccessKeys request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, c.Error(resp) @@ -298,6 +303,7 @@ func (c *cloudaccess) DeleteAccessKey(ctx context.Context, params AccessKeyReque if err != nil { return fmt.Errorf("DeleteAccessKey request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return c.Error(resp) @@ -332,6 +338,7 @@ func (c *cloudaccess) UpdateAccessKey(ctx context.Context, accessKey UpdateAcces if err != nil { return nil, fmt.Errorf("UpdateAccessKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, c.Error(resp) diff --git a/pkg/cloudaccess/access_key_version.go b/pkg/cloudaccess/access_key_version.go index a796d161..4d711039 100644 --- a/pkg/cloudaccess/access_key_version.go +++ b/pkg/cloudaccess/access_key_version.go @@ -8,6 +8,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -173,6 +174,7 @@ func (c *cloudaccess) GetAccessKeyVersionStatus(ctx context.Context, params GetA if err != nil { return nil, fmt.Errorf("%w: request failed: %w", ErrGetAccessKeyVersionStatus, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetAccessKeyVersionStatus, c.Error(resp)) @@ -201,6 +203,7 @@ func (c *cloudaccess) CreateAccessKeyVersion(ctx context.Context, params CreateA if err != nil { return nil, fmt.Errorf("%w: request failed: %w", ErrCreateAccessKeyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrCreateAccessKeyVersion, c.Error(resp)) @@ -229,6 +232,7 @@ func (c *cloudaccess) GetAccessKeyVersion(ctx context.Context, params GetAccessK if err != nil { return nil, fmt.Errorf("%w: request failed: %w", ErrGetAccessKeyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetAccessKeyVersion, c.Error(resp)) @@ -257,6 +261,7 @@ func (c *cloudaccess) ListAccessKeyVersions(ctx context.Context, params ListAcce if err != nil { return nil, fmt.Errorf("%w: request failed: %w", ErrListAccessKeyVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAccessKeyVersions, c.Error(resp)) @@ -285,6 +290,7 @@ func (c *cloudaccess) DeleteAccessKeyVersion(ctx context.Context, params DeleteA if err != nil { return nil, fmt.Errorf("%w: request failed: %w", ErrDeleteAccessKeyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrDeleteAccessKeyVersion, c.Error(resp)) diff --git a/pkg/cloudaccess/properties.go b/pkg/cloudaccess/properties.go index b189e05d..453c95d5 100644 --- a/pkg/cloudaccess/properties.go +++ b/pkg/cloudaccess/properties.go @@ -8,6 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -129,6 +130,7 @@ func (c *cloudaccess) LookupProperties(ctx context.Context, params LookupPropert if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrLookupProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrLookupProperties, c.Error(resp)) @@ -160,6 +162,7 @@ func (c *cloudaccess) GetAsyncPropertiesLookupID(ctx context.Context, params Get if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetAsyncLookupIDProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrGetAsyncLookupIDProperties, c.Error(resp)) @@ -191,6 +194,7 @@ func (c *cloudaccess) PerformAsyncPropertiesLookup(ctx context.Context, params P if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrPerformAsyncLookupProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrPerformAsyncLookupProperties, c.Error(resp)) diff --git a/pkg/cloudlets/loadbalancer.go b/pkg/cloudlets/loadbalancer.go index c59b2ade..e547b956 100644 --- a/pkg/cloudlets/loadbalancer.go +++ b/pkg/cloudlets/loadbalancer.go @@ -8,7 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -136,6 +136,7 @@ func (c *cloudlets) ListOrigins(ctx context.Context, params ListOriginsRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListOrigins, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListOrigins, c.Error(resp)) @@ -163,6 +164,7 @@ func (c *cloudlets) GetOrigin(ctx context.Context, params GetOriginRequest) (*Or if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetOrigin, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetOrigin, c.Error(resp)) @@ -195,6 +197,7 @@ func (c *cloudlets) CreateOrigin(ctx context.Context, params CreateOriginRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateOrigin, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateOrigin, c.Error(resp)) @@ -227,6 +230,7 @@ func (c *cloudlets) UpdateOrigin(ctx context.Context, params UpdateOriginRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateOrigin, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateOrigin, c.Error(resp)) diff --git a/pkg/cloudlets/loadbalancer_activation.go b/pkg/cloudlets/loadbalancer_activation.go index 93db45d9..87021ca9 100644 --- a/pkg/cloudlets/loadbalancer_activation.go +++ b/pkg/cloudlets/loadbalancer_activation.go @@ -9,7 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -151,6 +151,7 @@ func (c *cloudlets) ListLoadBalancerActivations(ctx context.Context, params List if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListLoadBalancerActivations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListLoadBalancerActivations, c.Error(resp)) @@ -187,6 +188,7 @@ func (c *cloudlets) ActivateLoadBalancerVersion(ctx context.Context, params Acti if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrActivateLoadBalancerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrActivateLoadBalancerVersion, c.Error(resp)) diff --git a/pkg/cloudlets/loadbalancer_version.go b/pkg/cloudlets/loadbalancer_version.go index 24e1c9a4..c2750188 100644 --- a/pkg/cloudlets/loadbalancer_version.go +++ b/pkg/cloudlets/loadbalancer_version.go @@ -10,7 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -247,6 +247,7 @@ func (c *cloudlets) CreateLoadBalancerVersion(ctx context.Context, params Create if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateLoadBalancerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateLoadBalancerVersion, c.Error(resp)) @@ -284,6 +285,7 @@ func (c *cloudlets) GetLoadBalancerVersion(ctx context.Context, params GetLoadBa if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetLoadBalancerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetLoadBalancerVersion, c.Error(resp)) @@ -321,6 +323,7 @@ func (c *cloudlets) UpdateLoadBalancerVersion(ctx context.Context, params Update if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateLoadBalancerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateLoadBalancerVersion, c.Error(resp)) @@ -352,6 +355,7 @@ func (c *cloudlets) ListLoadBalancerVersions(ctx context.Context, params ListLoa if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListLoadBalancerVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListLoadBalancerVersions, c.Error(resp)) diff --git a/pkg/cloudlets/policy.go b/pkg/cloudlets/policy.go index b508638d..335ebdd1 100644 --- a/pkg/cloudlets/policy.go +++ b/pkg/cloudlets/policy.go @@ -9,6 +9,7 @@ import ( "regexp" "strconv" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -187,6 +188,7 @@ func (c *cloudlets) ListPolicies(ctx context.Context, params ListPoliciesRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicies, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicies, c.Error(resp)) @@ -215,6 +217,7 @@ func (c *cloudlets) GetPolicy(ctx context.Context, params GetPolicyRequest) (*Po if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicy, c.Error(resp)) @@ -247,6 +250,7 @@ func (c *cloudlets) CreatePolicy(ctx context.Context, params CreatePolicyRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreatePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreatePolicy, c.Error(resp)) @@ -273,6 +277,7 @@ func (c *cloudlets) RemovePolicy(ctx context.Context, params RemovePolicyRequest if err != nil { return fmt.Errorf("%w: request failed: %s", ErrRemovePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrRemovePolicy, c.Error(resp)) @@ -308,6 +313,7 @@ func (c *cloudlets) UpdatePolicy(ctx context.Context, params UpdatePolicyRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdatePolicy, c.Error(resp)) diff --git a/pkg/cloudlets/policy_property.go b/pkg/cloudlets/policy_property.go index 3cc89568..a403b99d 100644 --- a/pkg/cloudlets/policy_property.go +++ b/pkg/cloudlets/policy_property.go @@ -8,7 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -90,6 +90,7 @@ func (c *cloudlets) GetPolicyProperties(ctx context.Context, params GetPolicyPro if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicyProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicyProperties, c.Error(resp)) @@ -126,6 +127,7 @@ func (c *cloudlets) DeletePolicyProperty(ctx context.Context, params DeletePolic if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeletePolicyProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%w: %d", ErrDeletePolicyProperty, resp.StatusCode) diff --git a/pkg/cloudlets/policy_version.go b/pkg/cloudlets/policy_version.go index 5efb9865..21bfba3a 100644 --- a/pkg/cloudlets/policy_version.go +++ b/pkg/cloudlets/policy_version.go @@ -9,7 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -162,6 +162,7 @@ func (c *cloudlets) ListPolicyVersions(ctx context.Context, params ListPolicyVer if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicyVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicyVersions, c.Error(resp)) @@ -197,6 +198,7 @@ func (c *cloudlets) GetPolicyVersion(ctx context.Context, params GetPolicyVersio if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicyVersion, c.Error(resp)) @@ -229,6 +231,7 @@ func (c *cloudlets) CreatePolicyVersion(ctx context.Context, params CreatePolicy if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreatePolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreatePolicyVersion, c.Error(resp)) @@ -255,6 +258,7 @@ func (c *cloudlets) DeletePolicyVersion(ctx context.Context, params DeletePolicy if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeletePolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeletePolicyVersion, c.Error(resp)) @@ -287,6 +291,7 @@ func (c *cloudlets) UpdatePolicyVersion(ctx context.Context, params UpdatePolicy if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdatePolicyVersion, c.Error(resp)) diff --git a/pkg/cloudlets/policy_version_activation.go b/pkg/cloudlets/policy_version_activation.go index 453e9a74..03f0d99c 100644 --- a/pkg/cloudlets/policy_version_activation.go +++ b/pkg/cloudlets/policy_version_activation.go @@ -9,7 +9,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -124,13 +124,14 @@ func (c *cloudlets) ListPolicyActivations(ctx context.Context, params ListPolicy } var result []PolicyActivation - response, err := c.Exec(req, &result) + resp, err := c.Exec(req, &result) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicyActivations, err) } + defer session.CloseResponseBody(resp) - if response.StatusCode != http.StatusOK { - return nil, fmt.Errorf("%s: %w", ErrListPolicyActivations, c.Error(response)) + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("%s: %w", ErrListPolicyActivations, c.Error(resp)) } return result, nil @@ -156,13 +157,14 @@ func (c *cloudlets) ActivatePolicyVersion(ctx context.Context, params ActivatePo } var result []PolicyActivation - response, err := c.Exec(req, &result, params.PolicyVersionActivation) + resp, err := c.Exec(req, &result, params.PolicyVersionActivation) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrActivatePolicyVersion, err) } + defer session.CloseResponseBody(resp) - if response.StatusCode >= http.StatusBadRequest { - return nil, fmt.Errorf("%w: %s", ErrActivatePolicyVersion, c.Error(response)) + if resp.StatusCode >= http.StatusBadRequest { + return nil, fmt.Errorf("%w: %s", ErrActivatePolicyVersion, c.Error(resp)) } return result, nil diff --git a/pkg/cloudlets/v3/list_cloudlets.go b/pkg/cloudlets/v3/list_cloudlets.go index b0460e22..e5bef9a4 100644 --- a/pkg/cloudlets/v3/list_cloudlets.go +++ b/pkg/cloudlets/v3/list_cloudlets.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -36,6 +38,7 @@ func (c *cloudlets) ListCloudlets(ctx context.Context) ([]ListCloudletsItem, err if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListCloudlets, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListCloudlets, c.Error(resp)) diff --git a/pkg/cloudlets/v3/policy.go b/pkg/cloudlets/v3/policy.go index 441808e6..10d06f3c 100644 --- a/pkg/cloudlets/v3/policy.go +++ b/pkg/cloudlets/v3/policy.go @@ -11,6 +11,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -241,6 +242,7 @@ func (c *cloudlets) ListPolicies(ctx context.Context, params ListPoliciesRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicies, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicies, c.Error(resp)) @@ -269,6 +271,7 @@ func (c *cloudlets) CreatePolicy(ctx context.Context, params CreatePolicyRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreatePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreatePolicy, c.Error(resp)) @@ -296,6 +299,7 @@ func (c *cloudlets) DeletePolicy(ctx context.Context, params DeletePolicyRequest if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeletePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeletePolicy, c.Error(resp)) @@ -324,6 +328,7 @@ func (c *cloudlets) GetPolicy(ctx context.Context, params GetPolicyRequest) (*Po if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode == http.StatusNotFound { return nil, fmt.Errorf("%s: %w: %s", ErrGetPolicy, ErrPolicyNotFound, c.Error(resp)) @@ -356,6 +361,7 @@ func (c *cloudlets) UpdatePolicy(ctx context.Context, params UpdatePolicyRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdatePolicy, c.Error(resp)) @@ -384,6 +390,7 @@ func (c *cloudlets) ClonePolicy(ctx context.Context, params ClonePolicyRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrClonePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrClonePolicy, c.Error(resp)) diff --git a/pkg/cloudlets/v3/policy_activation.go b/pkg/cloudlets/v3/policy_activation.go index 42c34182..65777260 100644 --- a/pkg/cloudlets/v3/policy_activation.go +++ b/pkg/cloudlets/v3/policy_activation.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -179,6 +180,7 @@ func (c *cloudlets) ListPolicyActivations(ctx context.Context, params ListPolicy if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicyActivations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicyActivations, c.Error(resp)) @@ -211,6 +213,7 @@ func (c *cloudlets) ActivatePolicy(ctx context.Context, params ActivatePolicyReq if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrActivatePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrActivatePolicy, c.Error(resp)) @@ -243,6 +246,7 @@ func (c *cloudlets) DeactivatePolicy(ctx context.Context, params DeactivatePolic if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeactivatePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrDeactivatePolicy, c.Error(resp)) @@ -269,6 +273,7 @@ func (c *cloudlets) GetPolicyActivation(ctx context.Context, params GetPolicyAct if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicyActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicyActivation, c.Error(resp)) diff --git a/pkg/cloudlets/v3/policy_property.go b/pkg/cloudlets/v3/policy_property.go index 185a36c2..2880393c 100644 --- a/pkg/cloudlets/v3/policy_property.go +++ b/pkg/cloudlets/v3/policy_property.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -97,6 +98,7 @@ func (c *cloudlets) ListActivePolicyProperties(ctx context.Context, params ListA if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListActivePolicyProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListActivePolicyProperties, c.Error(resp)) diff --git a/pkg/cloudlets/v3/policy_version.go b/pkg/cloudlets/v3/policy_version.go index d1a449f7..5087a568 100644 --- a/pkg/cloudlets/v3/policy_version.go +++ b/pkg/cloudlets/v3/policy_version.go @@ -9,7 +9,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -183,6 +183,7 @@ func (c *cloudlets) ListPolicyVersions(ctx context.Context, params ListPolicyVer if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicyVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicyVersions, c.Error(resp)) @@ -208,6 +209,7 @@ func (c *cloudlets) GetPolicyVersion(ctx context.Context, params GetPolicyVersio if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicyVersion, c.Error(resp)) @@ -237,6 +239,7 @@ func (c *cloudlets) CreatePolicyVersion(ctx context.Context, params CreatePolicy if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreatePolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreatePolicyVersion, c.Error(resp)) @@ -264,6 +267,7 @@ func (c *cloudlets) DeletePolicyVersion(ctx context.Context, params DeletePolicy if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeletePolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeletePolicyVersion, c.Error(resp)) @@ -293,6 +297,7 @@ func (c *cloudlets) UpdatePolicyVersion(ctx context.Context, params UpdatePolicy if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePolicyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdatePolicyVersion, c.Error(resp)) diff --git a/pkg/cloudwrapper/capacity.go b/pkg/cloudwrapper/capacity.go index 66a04523..7bd41626 100644 --- a/pkg/cloudwrapper/capacity.go +++ b/pkg/cloudwrapper/capacity.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -89,6 +91,7 @@ func (c *cloudwrapper) ListCapacities(ctx context.Context, params ListCapacities if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListCapacities, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListCapacities, c.Error(resp)) diff --git a/pkg/cloudwrapper/configurations.go b/pkg/cloudwrapper/configurations.go index 6e585e1c..96bb79e0 100644 --- a/pkg/cloudwrapper/configurations.go +++ b/pkg/cloudwrapper/configurations.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -385,6 +386,7 @@ func (c *cloudwrapper) GetConfiguration(ctx context.Context, params GetConfigura if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetConfiguration, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetConfiguration, c.Error(resp)) @@ -408,6 +410,7 @@ func (c *cloudwrapper) ListConfigurations(ctx context.Context) (*ListConfigurati if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListConfigurations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListConfigurations, c.Error(resp)) @@ -443,6 +446,7 @@ func (c *cloudwrapper) CreateConfiguration(ctx context.Context, params CreateCon if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateConfiguration, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateConfiguration, c.Error(resp)) @@ -478,6 +482,7 @@ func (c *cloudwrapper) UpdateConfiguration(ctx context.Context, params UpdateCon if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateConfiguration, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateConfiguration, c.Error(resp)) @@ -505,6 +510,7 @@ func (c *cloudwrapper) DeleteConfiguration(ctx context.Context, params DeleteCon if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteConfiguration, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return fmt.Errorf("%s: %w", ErrDeleteConfiguration, c.Error(resp)) @@ -531,6 +537,7 @@ func (c *cloudwrapper) ActivateConfiguration(ctx context.Context, params Activat if err != nil { return fmt.Errorf("%w: request failed: %s", ErrActivateConfiguration, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrActivateConfiguration, c.Error(resp)) diff --git a/pkg/cloudwrapper/locations.go b/pkg/cloudwrapper/locations.go index 53f6f986..26291196 100644 --- a/pkg/cloudwrapper/locations.go +++ b/pkg/cloudwrapper/locations.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -46,6 +48,7 @@ func (c *cloudwrapper) ListLocations(ctx context.Context) (*ListLocationResponse if err != nil { return nil, fmt.Errorf("%w: request failed:\n%s", ErrListLocations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListLocations, c.Error(resp)) diff --git a/pkg/cloudwrapper/multi_cdn.go b/pkg/cloudwrapper/multi_cdn.go index 6b61b034..31e71ded 100644 --- a/pkg/cloudwrapper/multi_cdn.go +++ b/pkg/cloudwrapper/multi_cdn.go @@ -8,6 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -84,6 +85,7 @@ func (c *cloudwrapper) ListAuthKeys(ctx context.Context, params ListAuthKeysRequ if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAuthKeys, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAuthKeys, c.Error(resp)) @@ -108,6 +110,7 @@ func (c *cloudwrapper) ListCDNProviders(ctx context.Context) (*ListCDNProvidersR if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListCDNProviders, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListCDNProviders, c.Error(resp)) diff --git a/pkg/cloudwrapper/properties.go b/pkg/cloudwrapper/properties.go index 9dec3dcb..e132000d 100644 --- a/pkg/cloudwrapper/properties.go +++ b/pkg/cloudwrapper/properties.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -118,6 +119,7 @@ func (c *cloudwrapper) ListProperties(ctx context.Context, params ListProperties if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListProperties, c.Error(resp)) @@ -154,6 +156,7 @@ func (c *cloudwrapper) ListOrigins(ctx context.Context, params ListOriginsReques if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListOrigins, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListOrigins, c.Error(resp)) diff --git a/pkg/cps/change_management_info.go b/pkg/cps/change_management_info.go index ad44f800..a4763226 100644 --- a/pkg/cps/change_management_info.go +++ b/pkg/cps/change_management_info.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -90,6 +92,7 @@ func (c *cps) GetChangeManagementInfo(ctx context.Context, params GetChangeReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeManagementInfo, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeManagementInfo, c.Error(resp)) @@ -119,6 +122,7 @@ func (c *cps) GetChangeDeploymentInfo(ctx context.Context, params GetChangeReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeDeploymentInfo, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeDeploymentInfo, c.Error(resp)) @@ -148,6 +152,7 @@ func (c *cps) AcknowledgeChangeManagement(ctx context.Context, params Acknowledg if err != nil { return fmt.Errorf("%w: request failed: %s", ErrAcknowledgeChangeManagement, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return fmt.Errorf("%s: %w", ErrAcknowledgeChangeManagement, c.Error(resp)) diff --git a/pkg/cps/changes.go b/pkg/cps/changes.go index 161c3b4b..9c8286ce 100644 --- a/pkg/cps/changes.go +++ b/pkg/cps/changes.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -230,6 +231,7 @@ func (c *cps) GetChangeStatus(ctx context.Context, params GetChangeStatusRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeStatus, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeStatus, c.Error(resp)) @@ -267,6 +269,7 @@ func (c *cps) CancelChange(ctx context.Context, params CancelChangeRequest) (*Ca if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCancelChange, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCancelChange, c.Error(resp)) @@ -306,6 +309,7 @@ func (c *cps) UpdateChange(ctx context.Context, params UpdateChangeRequest) (*Up if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateChange, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateChange, c.Error(resp)) diff --git a/pkg/cps/deployment_schedules.go b/pkg/cps/deployment_schedules.go index 1c622e69..8252e3f6 100644 --- a/pkg/cps/deployment_schedules.go +++ b/pkg/cps/deployment_schedules.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -79,6 +80,7 @@ func (c *cps) GetDeploymentSchedule(ctx context.Context, params GetDeploymentSch if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetDeploymentSchedule, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetDeploymentSchedule, c.Error(resp)) @@ -109,6 +111,7 @@ func (c *cps) UpdateDeploymentSchedule(ctx context.Context, params UpdateDeploym if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateDeploymentSchedule, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateDeploymentSchedule, c.Error(resp)) diff --git a/pkg/cps/deployments.go b/pkg/cps/deployments.go index b46551a5..6d727417 100644 --- a/pkg/cps/deployments.go +++ b/pkg/cps/deployments.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -108,6 +109,7 @@ func (c *cps) ListDeployments(ctx context.Context, params ListDeploymentsRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListDeployments, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListDeployments, c.Error(resp)) @@ -137,6 +139,7 @@ func (c *cps) GetProductionDeployment(ctx context.Context, params GetDeploymentR if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetProductionDeployment, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetProductionDeployment, c.Error(resp)) @@ -166,6 +169,7 @@ func (c *cps) GetStagingDeployment(ctx context.Context, params GetDeploymentRequ if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetStagingDeployment, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetStagingDeployment, c.Error(resp)) diff --git a/pkg/cps/dv_challenges.go b/pkg/cps/dv_challenges.go index 91356f0d..9b8a5b32 100644 --- a/pkg/cps/dv_challenges.go +++ b/pkg/cps/dv_challenges.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -86,6 +88,7 @@ func (c *cps) GetChangeLetsEncryptChallenges(ctx context.Context, params GetChan if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeLetsEncryptChallenges, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeLetsEncryptChallenges, c.Error(resp)) @@ -120,6 +123,7 @@ func (c *cps) AcknowledgeDVChallenges(ctx context.Context, params Acknowledgemen if err != nil { return fmt.Errorf("%w: request failed: %s", ErrAcknowledgeLetsEncryptChallenges, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK { return fmt.Errorf("%s: %w", ErrAcknowledgeLetsEncryptChallenges, c.Error(resp)) diff --git a/pkg/cps/enrollments.go b/pkg/cps/enrollments.go index a471ff05..b4294d66 100644 --- a/pkg/cps/enrollments.go +++ b/pkg/cps/enrollments.go @@ -8,6 +8,7 @@ import ( "net/url" "strconv" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -334,6 +335,7 @@ func (c *cps) ListEnrollments(ctx context.Context, params ListEnrollmentsRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListEnrollments, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListEnrollments, c.Error(resp)) @@ -364,6 +366,7 @@ func (c *cps) GetEnrollment(ctx context.Context, params GetEnrollmentRequest) (* if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEnrollment, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEnrollment, c.Error(resp)) @@ -408,6 +411,7 @@ func (c *cps) CreateEnrollment(ctx context.Context, params CreateEnrollmentReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateEnrollment, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrCreateEnrollment, c.Error(resp)) @@ -467,6 +471,7 @@ func (c *cps) UpdateEnrollment(ctx context.Context, params UpdateEnrollmentReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateEnrollment, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateEnrollment, c.Error(resp)) @@ -516,6 +521,7 @@ func (c *cps) RemoveEnrollment(ctx context.Context, params RemoveEnrollmentReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrRemoveEnrollment, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrRemoveEnrollment, c.Error(resp)) diff --git a/pkg/cps/history.go b/pkg/cps/history.go index 957f88fe..653f5c4f 100644 --- a/pkg/cps/history.go +++ b/pkg/cps/history.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -161,6 +162,7 @@ func (c *cps) GetDVHistory(ctx context.Context, params GetDVHistoryRequest) (*Ge if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetDVHistory, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetDVHistory, c.Error(resp)) @@ -188,6 +190,7 @@ func (c *cps) GetCertificateHistory(ctx context.Context, params GetCertificateHi if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCertificateHistory, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetCertificateHistory, c.Error(resp)) @@ -215,6 +218,7 @@ func (c *cps) GetChangeHistory(ctx context.Context, params GetChangeHistoryReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeHistory, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeHistory, c.Error(resp)) diff --git a/pkg/cps/post_verification_warnings.go b/pkg/cps/post_verification_warnings.go index bad0a129..64a68a1c 100644 --- a/pkg/cps/post_verification_warnings.go +++ b/pkg/cps/post_verification_warnings.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -42,6 +44,7 @@ func (c *cps) GetChangePostVerificationWarnings(ctx context.Context, params GetC if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangePostVerificationWarnings, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangePostVerificationWarnings, c.Error(resp)) @@ -71,6 +74,7 @@ func (c *cps) AcknowledgePostVerificationWarnings(ctx context.Context, params Ac if err != nil { return fmt.Errorf("%w: request failed: %s", ErrAcknowledgePostVerificationWarnings, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return fmt.Errorf("%s: %w", ErrAcknowledgePostVerificationWarnings, c.Error(resp)) diff --git a/pkg/cps/pre_verification_warnings.go b/pkg/cps/pre_verification_warnings.go index b0960a2d..82f28ddc 100644 --- a/pkg/cps/pre_verification_warnings.go +++ b/pkg/cps/pre_verification_warnings.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -51,6 +53,7 @@ func (c *cps) GetChangePreVerificationWarnings(ctx context.Context, params GetCh if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangePreVerificationWarnings, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangePreVerificationWarnings, c.Error(resp)) @@ -85,6 +88,7 @@ func (c *cps) AcknowledgePreVerificationWarnings(ctx context.Context, params Ack if err != nil { return fmt.Errorf("%w: request failed: %s", ErrAcknowledgePreVerificationWarnings, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK { return fmt.Errorf("%s: %w", ErrAcknowledgePreVerificationWarnings, c.Error(resp)) diff --git a/pkg/cps/third_party_csr.go b/pkg/cps/third_party_csr.go index 8a18185c..746ef47d 100644 --- a/pkg/cps/third_party_csr.go +++ b/pkg/cps/third_party_csr.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -95,6 +96,7 @@ func (c *cps) GetChangeThirdPartyCSR(ctx context.Context, params GetChangeReques if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeThirdPartyCSR, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeThirdPartyCSR, c.Error(resp)) @@ -124,6 +126,7 @@ func (c *cps) UploadThirdPartyCertAndTrustChain(ctx context.Context, params Uplo if err != nil { return fmt.Errorf("%w: request failed: %s", ErrUploadThirdPartyCertAndTrustChain, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return fmt.Errorf("%s: %w", ErrUploadThirdPartyCertAndTrustChain, c.Error(resp)) diff --git a/pkg/datastream/properties.go b/pkg/datastream/properties.go index c3aa9019..8b0e86af 100644 --- a/pkg/datastream/properties.go +++ b/pkg/datastream/properties.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -77,6 +78,7 @@ func (d *ds) GetProperties(ctx context.Context, params GetPropertiesRequest) (*P if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetProperties, d.Error(resp)) @@ -110,6 +112,7 @@ func (d *ds) GetDatasetFields(ctx context.Context, params GetDatasetFieldsReques if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetDatasetFields, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetDatasetFields, d.Error(resp)) diff --git a/pkg/datastream/stream.go b/pkg/datastream/stream.go index 3e62aff8..67e6c946 100644 --- a/pkg/datastream/stream.go +++ b/pkg/datastream/stream.go @@ -8,6 +8,7 @@ import ( "net/url" "strconv" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -303,6 +304,7 @@ func (d *ds) CreateStream(ctx context.Context, params CreateStreamRequest) (*Det if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateStream, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateStream, d.Error(resp)) @@ -342,6 +344,7 @@ func (d *ds) GetStream(ctx context.Context, params GetStreamRequest) (*DetailedS if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetStream, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetStream, d.Error(resp)) @@ -379,6 +382,7 @@ func (d *ds) UpdateStream(ctx context.Context, params UpdateStreamRequest) (*Det if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateStream, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateStream, d.Error(resp)) @@ -412,6 +416,7 @@ func (d *ds) DeleteStream(ctx context.Context, params DeleteStreamRequest) error if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteStream, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteStream, d.Error(resp)) @@ -445,6 +450,7 @@ func (d *ds) ListStreams(ctx context.Context, params ListStreamsRequest) ([]Stre if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListStreams, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListStreams, d.Error(resp)) diff --git a/pkg/datastream/stream_activation.go b/pkg/datastream/stream_activation.go index 9d0fc3f5..4cc33d54 100644 --- a/pkg/datastream/stream_activation.go +++ b/pkg/datastream/stream_activation.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -87,6 +88,7 @@ func (d *ds) ActivateStream(ctx context.Context, params ActivateStreamRequest) ( if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrActivateStream, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrActivateStream, d.Error(resp)) @@ -120,6 +122,7 @@ func (d *ds) DeactivateStream(ctx context.Context, params DeactivateStreamReques if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeactivateStream, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrDeactivateStream, d.Error(resp)) @@ -153,6 +156,7 @@ func (d *ds) GetActivationHistory(ctx context.Context, params GetActivationHisto if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetActivationHistory, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetActivationHistory, d.Error(resp)) diff --git a/pkg/dns/authorities.go b/pkg/dns/authorities.go index 80cfcca1..6344e3f4 100644 --- a/pkg/dns/authorities.go +++ b/pkg/dns/authorities.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -77,6 +78,7 @@ func (d *dns) GetAuthorities(ctx context.Context, params GetAuthoritiesRequest) if err != nil { return nil, fmt.Errorf("GetAuthorities request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) diff --git a/pkg/dns/data.go b/pkg/dns/data.go index 87b573cb..8ce0dd0b 100644 --- a/pkg/dns/data.go +++ b/pkg/dns/data.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -58,6 +60,7 @@ func (d *dns) ListGroups(ctx context.Context, params ListGroupRequest) (*ListGro if err != nil { return nil, fmt.Errorf("ListZoneGroups request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) diff --git a/pkg/dns/record.go b/pkg/dns/record.go index 225a34a5..76505b25 100644 --- a/pkg/dns/record.go +++ b/pkg/dns/record.go @@ -8,6 +8,7 @@ import ( "sync" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -143,6 +144,7 @@ func (d *dns) CreateRecord(ctx context.Context, params CreateRecordRequest) erro if err != nil { return fmt.Errorf("CreateRecord request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return d.Error(resp) @@ -187,6 +189,7 @@ func (d *dns) UpdateRecord(ctx context.Context, params UpdateRecordRequest) erro if err != nil { return fmt.Errorf("UpdateRecord request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return d.Error(resp) @@ -225,6 +228,7 @@ func (d *dns) DeleteRecord(ctx context.Context, params DeleteRecordRequest) erro if err != nil { return fmt.Errorf("DeleteRecord request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) diff --git a/pkg/dns/record_lookup.go b/pkg/dns/record_lookup.go index 05fe16ce..535024b3 100644 --- a/pkg/dns/record_lookup.go +++ b/pkg/dns/record_lookup.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -137,6 +138,7 @@ func (d *dns) GetRecord(ctx context.Context, params GetRecordRequest) (*GetRecor if err != nil { return nil, fmt.Errorf("GetRecord request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -164,6 +166,7 @@ func (d *dns) GetRecordList(ctx context.Context, params GetRecordListRequest) (* if err != nil { return nil, fmt.Errorf("GetRecordList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) diff --git a/pkg/dns/recordsets.go b/pkg/dns/recordsets.go index 7c732366..f340859c 100644 --- a/pkg/dns/recordsets.go +++ b/pkg/dns/recordsets.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -167,6 +168,7 @@ func (d *dns) GetRecordSets(ctx context.Context, params GetRecordSetsRequest) (* if err != nil { return nil, fmt.Errorf("GetRecordsets request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -213,6 +215,7 @@ func (d *dns) CreateRecordSets(ctx context.Context, params CreateRecordSetsReque if err != nil { return fmt.Errorf("CreateRecordsets request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) @@ -259,6 +262,7 @@ func (d *dns) UpdateRecordSets(ctx context.Context, params UpdateRecordSetsReque if err != nil { return fmt.Errorf("UpdateRecordsets request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) diff --git a/pkg/dns/tsig.go b/pkg/dns/tsig.go index a2097ec8..d0e06aac 100644 --- a/pkg/dns/tsig.go +++ b/pkg/dns/tsig.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -262,6 +263,7 @@ func (d *dns) ListTSIGKeys(ctx context.Context, params ListTSIGKeysRequest) (*Li if err != nil { return nil, fmt.Errorf(" ListTsigKeys request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -294,6 +296,7 @@ func (d *dns) GetTSIGKeyZones(ctx context.Context, params GetTSIGKeyZonesRequest if err != nil { return nil, fmt.Errorf("GetTsigKeyZones request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -321,6 +324,7 @@ func (d *dns) GetTSIGKeyAliases(ctx context.Context, params GetTSIGKeyAliasesReq if err != nil { return nil, fmt.Errorf("GetTsigKeyAliases request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -352,6 +356,7 @@ func (d *dns) UpdateTSIGKeyBulk(ctx context.Context, params UpdateTSIGKeyBulkReq if err != nil { return fmt.Errorf("TsigKeyBulkUpdate request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) @@ -379,6 +384,7 @@ func (d *dns) GetTSIGKey(ctx context.Context, params GetTSIGKeyRequest) (*GetTSI if err != nil { return nil, fmt.Errorf("GetTsigKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -405,6 +411,7 @@ func (d *dns) DeleteTSIGKey(ctx context.Context, params DeleteTSIGKeyRequest) er if err != nil { return fmt.Errorf("DeleteTsigKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) @@ -436,6 +443,7 @@ func (d *dns) UpdateTSIGKey(ctx context.Context, params UpdateTSIGKeyRequest) er if err != nil { return fmt.Errorf("UpdateTsigKey request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) diff --git a/pkg/dns/zone.go b/pkg/dns/zone.go index 9e0311cd..d5efd967 100644 --- a/pkg/dns/zone.go +++ b/pkg/dns/zone.go @@ -16,6 +16,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -339,6 +340,7 @@ func (d *dns) ListZones(ctx context.Context, params ListZonesRequest) (*ZoneList if err != nil { return nil, fmt.Errorf("listzones request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -366,6 +368,7 @@ func (d *dns) GetZone(ctx context.Context, params GetZoneRequest) (*GetZoneRespo if err != nil { return nil, fmt.Errorf("GetZone request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -393,6 +396,7 @@ func (d *dns) GetChangeList(ctx context.Context, params GetChangeListRequest) (* if err != nil { return nil, fmt.Errorf("GetChangeList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -420,6 +424,7 @@ func (d *dns) GetMasterZoneFile(ctx context.Context, params GetMasterZoneFileReq if err != nil { return "", fmt.Errorf("GetMasterZoneFile request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return "", d.Error(resp) @@ -455,6 +460,7 @@ func (d *dns) PostMasterZoneFile(ctx context.Context, params PostMasterZoneFileR if err != nil { return fmt.Errorf("Create PostMasterZoneFile failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) @@ -506,6 +512,7 @@ func (d *dns) CreateZone(ctx context.Context, params CreateZoneRequest) error { if err != nil { return fmt.Errorf("Create Zone request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return d.Error(resp) @@ -557,6 +564,7 @@ func (d *dns) SaveChangeList(ctx context.Context, params SaveChangeListRequest) if err != nil { return fmt.Errorf("SaveChangeList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return d.Error(resp) @@ -597,6 +605,7 @@ func (d *dns) SubmitChangeList(ctx context.Context, params SubmitChangeListReque if err != nil { return fmt.Errorf("SubmitChangeList request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return d.Error(resp) @@ -639,6 +648,7 @@ func (d *dns) UpdateZone(ctx context.Context, params UpdateZoneRequest) error { if err != nil { return fmt.Errorf("Zone Update request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return d.Error(resp) @@ -741,6 +751,7 @@ func (d *dns) GetZoneNames(ctx context.Context, params GetZoneNamesRequest) (*Ge if err != nil { return nil, fmt.Errorf("GetZoneNames request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -768,6 +779,7 @@ func (d *dns) GetZoneNameTypes(ctx context.Context, params GetZoneNameTypesReque if err != nil { return nil, fmt.Errorf("GetZoneNameTypes request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -794,6 +806,7 @@ func (d *dns) GetZonesDNSSecStatus(ctx context.Context, params GetZonesDNSSecSta if err != nil { return nil, fmt.Errorf("GetZonesDNSSecStatus request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) diff --git a/pkg/dns/zonebulk.go b/pkg/dns/zonebulk.go index 86767cc9..c427fb69 100644 --- a/pkg/dns/zonebulk.go +++ b/pkg/dns/zonebulk.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -205,6 +206,7 @@ func (d *dns) GetBulkZoneCreateStatus(ctx context.Context, params GetBulkZoneCre if err != nil { return nil, fmt.Errorf("GetBulkZoneCreateStatus request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -233,6 +235,7 @@ func (d *dns) GetBulkZoneDeleteStatus(ctx context.Context, params GetBulkZoneDel if err != nil { return nil, fmt.Errorf("GetBulkZoneDeleteStatus request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -261,6 +264,7 @@ func (d *dns) GetBulkZoneCreateResult(ctx context.Context, params GetBulkZoneCre if err != nil { return nil, fmt.Errorf("GetBulkZoneCreateResult request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -289,6 +293,7 @@ func (d *dns) GetBulkZoneDeleteResult(ctx context.Context, params GetBulkZoneDel if err != nil { return nil, fmt.Errorf("GetBulkZoneDeleteResult request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, d.Error(resp) @@ -320,6 +325,7 @@ func (d *dns) CreateBulkZones(ctx context.Context, params CreateBulkZonesRequest if err != nil { return nil, fmt.Errorf("CreateBulkZones request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, d.Error(resp) @@ -351,6 +357,7 @@ func (d *dns) DeleteBulkZones(ctx context.Context, params DeleteBulkZonesRequest if err != nil { return nil, fmt.Errorf("DeleteBulkZones request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, d.Error(resp) diff --git a/pkg/edgeworkers/activations.go b/pkg/edgeworkers/activations.go index 070872bc..3784b912 100644 --- a/pkg/edgeworkers/activations.go +++ b/pkg/edgeworkers/activations.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -153,6 +154,7 @@ func (e *edgeworkers) ListActivations(ctx context.Context, params ListActivation if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListActivations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListActivations, e.Error(resp)) @@ -181,6 +183,7 @@ func (e *edgeworkers) GetActivation(ctx context.Context, params GetActivationReq if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetActivation, e.Error(resp)) @@ -210,6 +213,7 @@ func (e *edgeworkers) ActivateVersion(ctx context.Context, params ActivateVersio if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrActivateVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrActivateVersion, e.Error(resp)) @@ -239,6 +243,7 @@ func (e *edgeworkers) CancelPendingActivation(ctx context.Context, params Cancel if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCancelActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCancelActivation, e.Error(resp)) diff --git a/pkg/edgeworkers/contracts.go b/pkg/edgeworkers/contracts.go index c6c0fd59..8ced8006 100644 --- a/pkg/edgeworkers/contracts.go +++ b/pkg/edgeworkers/contracts.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -34,6 +36,7 @@ func (e *edgeworkers) ListContracts(ctx context.Context) (*ListContractsResponse if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListContracts, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListContracts, e.Error(resp)) diff --git a/pkg/edgeworkers/deactivations.go b/pkg/edgeworkers/deactivations.go index 625e78e8..2827884e 100644 --- a/pkg/edgeworkers/deactivations.go +++ b/pkg/edgeworkers/deactivations.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -128,6 +129,7 @@ func (e *edgeworkers) ListDeactivations(ctx context.Context, params ListDeactiva if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListDeactivations, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListDeactivations, e.Error(resp)) @@ -159,6 +161,7 @@ func (e *edgeworkers) DeactivateVersion(ctx context.Context, params DeactivateVe if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeactivateVersion, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrDeactivateVersion, e.Error(resp)) @@ -187,6 +190,7 @@ func (e *edgeworkers) GetDeactivation(ctx context.Context, params GetDeactivatio if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetDeactivation, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetDeactivation, e.Error(resp)) diff --git a/pkg/edgeworkers/edgekv_access_tokens.go b/pkg/edgeworkers/edgekv_access_tokens.go index b067e7cb..07fcddc7 100644 --- a/pkg/edgeworkers/edgekv_access_tokens.go +++ b/pkg/edgeworkers/edgekv_access_tokens.go @@ -8,6 +8,7 @@ import ( "net/url" "strconv" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -177,6 +178,7 @@ func (e *edgeworkers) CreateEdgeKVAccessToken(ctx context.Context, params Create if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateEdgeKVAccessToken, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCreateEdgeKVAccessToken, e.Error(resp)) @@ -207,6 +209,7 @@ func (e *edgeworkers) GetEdgeKVAccessToken(ctx context.Context, params GetEdgeKV if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeKVAccessToken, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeKVAccessToken, e.Error(resp)) @@ -240,6 +243,7 @@ func (e *edgeworkers) ListEdgeKVAccessTokens(ctx context.Context, params ListEdg if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListEdgeKVAccessToken, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListEdgeKVAccessToken, e.Error(resp)) @@ -270,6 +274,7 @@ func (e *edgeworkers) DeleteEdgeKVAccessToken(ctx context.Context, params Delete if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeleteEdgeKVAccessToken, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrDeleteEdgeKVAccessToken, e.Error(resp)) diff --git a/pkg/edgeworkers/edgekv_groups.go b/pkg/edgeworkers/edgekv_groups.go index ae1c381e..d60d2e27 100644 --- a/pkg/edgeworkers/edgekv_groups.go +++ b/pkg/edgeworkers/edgekv_groups.go @@ -7,7 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -50,6 +50,7 @@ func (e *edgeworkers) ListGroupsWithinNamespace(ctx context.Context, params List if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListGroupsWithinNamespace, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListGroupsWithinNamespace, e.Error(resp)) diff --git a/pkg/edgeworkers/edgekv_initialize.go b/pkg/edgeworkers/edgekv_initialize.go index 5e4fe4e0..e8214be1 100644 --- a/pkg/edgeworkers/edgekv_initialize.go +++ b/pkg/edgeworkers/edgekv_initialize.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) // EdgeKVInitialize is EdgeKV Initialize API interface @@ -41,6 +43,7 @@ func (e *edgeworkers) InitializeEdgeKV(ctx context.Context) (*EdgeKVInitializati if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrInitializeEdgeKV, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrInitializeEdgeKV, e.Error(resp)) @@ -64,6 +67,7 @@ func (e *edgeworkers) GetEdgeKVInitializationStatus(ctx context.Context) (*EdgeK if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeKVInitialize, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeKVInitialize, e.Error(resp)) diff --git a/pkg/edgeworkers/edgekv_items.go b/pkg/edgeworkers/edgekv_items.go index c233c5eb..82020c57 100644 --- a/pkg/edgeworkers/edgekv_items.go +++ b/pkg/edgeworkers/edgekv_items.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -141,6 +142,7 @@ func (e *edgeworkers) ListItems(ctx context.Context, params ListItemsRequest) (* if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListItems, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListItems, e.Error(resp)) @@ -169,6 +171,7 @@ func (e *edgeworkers) GetItem(ctx context.Context, params GetItemRequest) (*Item if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetItem, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetItem, e.Error(resp)) @@ -209,6 +212,7 @@ func (e *edgeworkers) UpsertItem(ctx context.Context, params UpsertItemRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpsertItem, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpsertItem, e.Error(resp)) @@ -243,6 +247,7 @@ func (e *edgeworkers) DeleteItem(ctx context.Context, params DeleteItemRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeleteItem, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrDeleteItem, e.Error(resp)) diff --git a/pkg/edgeworkers/edgekv_namespaces.go b/pkg/edgeworkers/edgekv_namespaces.go index fa497e35..01f2b47d 100644 --- a/pkg/edgeworkers/edgekv_namespaces.go +++ b/pkg/edgeworkers/edgekv_namespaces.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -173,6 +174,7 @@ func (e *edgeworkers) ListEdgeKVNamespaces(ctx context.Context, params ListEdgeK if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListEdgeKVNamespace, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListEdgeKVNamespace, e.Error(resp)) @@ -200,6 +202,7 @@ func (e *edgeworkers) GetEdgeKVNamespace(ctx context.Context, params GetEdgeKVNa if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeKVNamespace, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeKVNamespace, e.Error(resp)) @@ -227,6 +230,7 @@ func (e *edgeworkers) CreateEdgeKVNamespace(ctx context.Context, params CreateEd if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateEdgeKVNamespace, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCreateEdgeKVNamespace, e.Error(resp)) @@ -254,6 +258,7 @@ func (e *edgeworkers) UpdateEdgeKVNamespace(ctx context.Context, params UpdateEd if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateEdgeKVNamespace, err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateEdgeKVNamespace, e.Error(resp)) diff --git a/pkg/edgeworkers/edgeworker_id.go b/pkg/edgeworkers/edgeworker_id.go index 54be07df..d6ec7826 100644 --- a/pkg/edgeworkers/edgeworker_id.go +++ b/pkg/edgeworkers/edgeworker_id.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -151,6 +152,7 @@ func (e *edgeworkers) GetEdgeWorkerID(ctx context.Context, params GetEdgeWorkerI if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeWorkerID, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeWorkerID, e.Error(resp)) @@ -186,6 +188,7 @@ func (e *edgeworkers) ListEdgeWorkersID(ctx context.Context, params ListEdgeWork if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListEdgeWorkersID, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListEdgeWorkersID, e.Error(resp)) @@ -217,6 +220,7 @@ func (e *edgeworkers) CreateEdgeWorkerID(ctx context.Context, params CreateEdgeW if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateEdgeWorkerID, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateEdgeWorkerID, e.Error(resp)) @@ -248,6 +252,7 @@ func (e *edgeworkers) UpdateEdgeWorkerID(ctx context.Context, params UpdateEdgeW if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateEdgeWorkerID, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateEdgeWorkerID, e.Error(resp)) @@ -279,6 +284,7 @@ func (e *edgeworkers) CloneEdgeWorkerID(ctx context.Context, params CloneEdgeWor if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCloneEdgeWorkerID, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCloneEdgeWorkerID, e.Error(resp)) @@ -308,6 +314,7 @@ func (e *edgeworkers) DeleteEdgeWorkerID(ctx context.Context, params DeleteEdgeW if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteEdgeWorkerID, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteEdgeWorkerID, e.Error(resp)) diff --git a/pkg/edgeworkers/edgeworker_version.go b/pkg/edgeworkers/edgeworker_version.go index 9b0502f3..123051f5 100644 --- a/pkg/edgeworkers/edgeworker_version.go +++ b/pkg/edgeworkers/edgeworker_version.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -132,6 +133,7 @@ func (e *edgeworkers) GetEdgeWorkerVersion(ctx context.Context, params GetEdgeWo if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeWorkerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeWorkerVersion, e.Error(resp)) @@ -159,6 +161,7 @@ func (e *edgeworkers) ListEdgeWorkerVersions(ctx context.Context, params ListEdg if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListEdgeWorkerVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListEdgeWorkerVersions, e.Error(resp)) @@ -186,6 +189,7 @@ func (e *edgeworkers) GetEdgeWorkerVersionContent(ctx context.Context, params Ge if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeWorkerVersionContent, err) } + defer session.CloseResponseBody(resp) var result Bundle data, err := ioutil.ReadAll(resp.Body) @@ -222,6 +226,7 @@ func (e *edgeworkers) CreateEdgeWorkerVersion(ctx context.Context, params Create if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateEdgeWorkerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateEdgeWorkerVersion, e.Error(resp)) @@ -247,6 +252,7 @@ func (e *edgeworkers) DeleteEdgeWorkerVersion(ctx context.Context, params Delete if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteEdgeWorkerVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteEdgeWorkerVersion, e.Error(resp)) diff --git a/pkg/edgeworkers/permission_group.go b/pkg/edgeworkers/permission_group.go index f91404d6..c5bf5123 100644 --- a/pkg/edgeworkers/permission_group.go +++ b/pkg/edgeworkers/permission_group.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -62,6 +63,7 @@ func (e *edgeworkers) GetPermissionGroup(ctx context.Context, params GetPermissi if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPermissionGroup, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPermissionGroup, e.Error(resp)) @@ -86,6 +88,7 @@ func (e *edgeworkers) ListPermissionGroups(ctx context.Context) (*ListPermission if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPermissionGroups, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPermissionGroups, e.Error(resp)) diff --git a/pkg/edgeworkers/properties.go b/pkg/edgeworkers/properties.go index bb2236f5..7a586879 100644 --- a/pkg/edgeworkers/properties.go +++ b/pkg/edgeworkers/properties.go @@ -8,6 +8,7 @@ import ( "net/url" "strconv" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -73,6 +74,7 @@ func (e *edgeworkers) ListProperties(ctx context.Context, params ListPropertiesR if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListProperties, e.Error(resp)) diff --git a/pkg/edgeworkers/report.go b/pkg/edgeworkers/report.go index 3f21a21b..4e983209 100644 --- a/pkg/edgeworkers/report.go +++ b/pkg/edgeworkers/report.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -256,6 +257,7 @@ func (e *edgeworkers) GetSummaryReport(ctx context.Context, params GetSummaryRep if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetSummaryReport, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetSummaryReport, e.Error(resp)) @@ -303,6 +305,7 @@ func (e *edgeworkers) GetReport(ctx context.Context, params GetReportRequest) (* if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetReport, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetReport, e.Error(resp)) @@ -327,6 +330,7 @@ func (e *edgeworkers) ListReports(ctx context.Context) (*ListReportsResponse, er if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListReports, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListReports, e.Error(resp)) diff --git a/pkg/edgeworkers/resource_tier.go b/pkg/edgeworkers/resource_tier.go index 053c2dd2..923bdb06 100644 --- a/pkg/edgeworkers/resource_tier.go +++ b/pkg/edgeworkers/resource_tier.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -89,6 +90,7 @@ func (e *edgeworkers) ListResourceTiers(ctx context.Context, params ListResource if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListResourceTiers, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListResourceTiers, e.Error(resp)) @@ -117,6 +119,7 @@ func (e *edgeworkers) GetResourceTier(ctx context.Context, params GetResourceTie if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetResourceTier, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetResourceTier, e.Error(resp)) diff --git a/pkg/edgeworkers/secure_tokens.go b/pkg/edgeworkers/secure_tokens.go index 97af4d54..8d55175c 100644 --- a/pkg/edgeworkers/secure_tokens.go +++ b/pkg/edgeworkers/secure_tokens.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -63,6 +64,7 @@ func (e *edgeworkers) CreateSecureToken(ctx context.Context, params CreateSecure if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateSecureToken, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateSecureToken, e.Error(resp)) diff --git a/pkg/edgeworkers/validations.go b/pkg/edgeworkers/validations.go index 90982aa1..fdbab9c2 100644 --- a/pkg/edgeworkers/validations.go +++ b/pkg/edgeworkers/validations.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -61,6 +62,7 @@ func (e *edgeworkers) ValidateBundle(ctx context.Context, params ValidateBundleR if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrValidateBundle, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrValidateBundle, e.Error(resp)) diff --git a/pkg/gtm/asmap.go b/pkg/gtm/asmap.go index a110469e..3d8ebb28 100644 --- a/pkg/gtm/asmap.go +++ b/pkg/gtm/asmap.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -162,6 +163,7 @@ func (g *gtm) ListASMaps(ctx context.Context, params ListASMapsRequest) ([]ASMap if err != nil { return nil, fmt.Errorf("ListASMaps request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -190,6 +192,7 @@ func (g *gtm) GetASMap(ctx context.Context, params GetASMapRequest) (*GetASMapRe if err != nil { return nil, fmt.Errorf("GetASMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -218,6 +221,7 @@ func (g *gtm) CreateASMap(ctx context.Context, params CreateASMapRequest) (*Crea if err != nil { return nil, fmt.Errorf("ASMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) @@ -246,6 +250,7 @@ func (g *gtm) UpdateASMap(ctx context.Context, params UpdateASMapRequest) (*Upda if err != nil { return nil, fmt.Errorf("ASMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -274,6 +279,7 @@ func (g *gtm) DeleteASMap(ctx context.Context, params DeleteASMapRequest) (*Dele if err != nil { return nil, fmt.Errorf("ASMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) diff --git a/pkg/gtm/cidrmap.go b/pkg/gtm/cidrmap.go index 8f6457fa..4e5c994b 100644 --- a/pkg/gtm/cidrmap.go +++ b/pkg/gtm/cidrmap.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -159,6 +160,7 @@ func (g *gtm) ListCIDRMaps(ctx context.Context, params ListCIDRMapsRequest) ([]C if err != nil { return nil, fmt.Errorf("ListCIDRMaps request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -187,6 +189,7 @@ func (g *gtm) GetCIDRMap(ctx context.Context, params GetCIDRMapRequest) (*GetCID if err != nil { return nil, fmt.Errorf("GetCIDRMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -215,6 +218,7 @@ func (g *gtm) CreateCIDRMap(ctx context.Context, params CreateCIDRMapRequest) (* if err != nil { return nil, fmt.Errorf("CIDRMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) @@ -243,6 +247,7 @@ func (g *gtm) UpdateCIDRMap(ctx context.Context, params UpdateCIDRMapRequest) (* if err != nil { return nil, fmt.Errorf("CIDRMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -271,6 +276,7 @@ func (g *gtm) DeleteCIDRMap(ctx context.Context, params DeleteCIDRMapRequest) (* if err != nil { return nil, fmt.Errorf("CIDRMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) diff --git a/pkg/gtm/datacenter.go b/pkg/gtm/datacenter.go index e6831407..0ebfd040 100644 --- a/pkg/gtm/datacenter.go +++ b/pkg/gtm/datacenter.go @@ -8,6 +8,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -168,6 +169,7 @@ func (g *gtm) ListDatacenters(ctx context.Context, params ListDatacentersRequest if err != nil { return nil, fmt.Errorf("ListDatacenters request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -196,6 +198,7 @@ func (g *gtm) GetDatacenter(ctx context.Context, params GetDatacenterRequest) (* if err != nil { return nil, fmt.Errorf("GetDatacenter request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -224,6 +227,8 @@ func (g *gtm) CreateDatacenter(ctx context.Context, params CreateDatacenterReque if err != nil { return nil, fmt.Errorf("CreateDatacenter request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) } @@ -301,6 +306,8 @@ func createDefaultDC(ctx context.Context, g *gtm, defaultID int, domainName stri if err != nil { return nil, fmt.Errorf("DefaultDatacenter request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) } @@ -328,6 +335,8 @@ func (g *gtm) UpdateDatacenter(ctx context.Context, params UpdateDatacenterReque if err != nil { return nil, fmt.Errorf("UpdateDatacenter request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) } @@ -355,6 +364,8 @@ func (g *gtm) DeleteDatacenter(ctx context.Context, params DeleteDatacenterReque if err != nil { return nil, fmt.Errorf("DeleteDatacenter request failed: %w", err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) } diff --git a/pkg/gtm/domain.go b/pkg/gtm/domain.go index 7ecb6e97..164f2d70 100644 --- a/pkg/gtm/domain.go +++ b/pkg/gtm/domain.go @@ -9,6 +9,7 @@ import ( "unicode" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -221,6 +222,7 @@ func (g *gtm) GetDomainStatus(ctx context.Context, params GetDomainStatusRequest if err != nil { return nil, fmt.Errorf("GetDomain request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -245,6 +247,7 @@ func (g *gtm) ListDomains(ctx context.Context) ([]DomainItem, error) { if err != nil { return nil, fmt.Errorf("ListDomains request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -273,6 +276,7 @@ func (g *gtm) GetDomain(ctx context.Context, params GetDomainRequest) (*GetDomai if err != nil { return nil, fmt.Errorf("GetDomain request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -315,6 +319,7 @@ func (g *gtm) CreateDomain(ctx context.Context, params CreateDomainRequest) (*Cr if err != nil { return nil, fmt.Errorf("domain request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) @@ -357,6 +362,7 @@ func (g *gtm) UpdateDomain(ctx context.Context, params UpdateDomainRequest) (*Up if err != nil { return nil, fmt.Errorf("domain request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -385,6 +391,7 @@ func (g *gtm) DeleteDomain(ctx context.Context, params DeleteDomainRequest) (*De if err != nil { return nil, fmt.Errorf("DeleteDomain request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -436,6 +443,7 @@ func (g *gtm) NullFieldMap(ctx context.Context, domain *Domain) (*NullFieldMapSt if err != nil { return nil, fmt.Errorf("GetDomain request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) diff --git a/pkg/gtm/geomap.go b/pkg/gtm/geomap.go index 2a1289f4..66c471d3 100644 --- a/pkg/gtm/geomap.go +++ b/pkg/gtm/geomap.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -161,6 +162,7 @@ func (g *gtm) ListGeoMaps(ctx context.Context, params ListGeoMapsRequest) ([]Geo if err != nil { return nil, fmt.Errorf("ListGeoMaps request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -189,6 +191,7 @@ func (g *gtm) GetGeoMap(ctx context.Context, params GetGeoMapRequest) (*GetGeoMa if err != nil { return nil, fmt.Errorf("GetGeoMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -217,6 +220,7 @@ func (g *gtm) CreateGeoMap(ctx context.Context, params CreateGeoMapRequest) (*Cr if err != nil { return nil, fmt.Errorf("GeoMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) @@ -245,6 +249,7 @@ func (g *gtm) UpdateGeoMap(ctx context.Context, params UpdateGeoMapRequest) (*Up if err != nil { return nil, fmt.Errorf("GeoMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -273,6 +278,7 @@ func (g *gtm) DeleteGeoMap(ctx context.Context, params DeleteGeoMapRequest) (*De if err != nil { return nil, fmt.Errorf("GeoMap request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) diff --git a/pkg/gtm/property.go b/pkg/gtm/property.go index abff6c24..d06ebe3c 100644 --- a/pkg/gtm/property.go +++ b/pkg/gtm/property.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -273,6 +274,7 @@ func (g *gtm) ListProperties(ctx context.Context, params ListPropertiesRequest) if err != nil { return nil, fmt.Errorf("ListProperties request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -301,6 +303,7 @@ func (g *gtm) GetProperty(ctx context.Context, params GetPropertyRequest) (*GetP if err != nil { return nil, fmt.Errorf("GetProperty request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -329,6 +332,7 @@ func (g *gtm) CreateProperty(ctx context.Context, params CreatePropertyRequest) if err != nil { return nil, fmt.Errorf("property request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) @@ -357,6 +361,7 @@ func (g *gtm) UpdateProperty(ctx context.Context, params UpdatePropertyRequest) if err != nil { return nil, fmt.Errorf("property request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -385,6 +390,7 @@ func (g *gtm) DeleteProperty(ctx context.Context, params DeletePropertyRequest) if err != nil { return nil, fmt.Errorf("DeleteProperty request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) diff --git a/pkg/gtm/resource.go b/pkg/gtm/resource.go index b1a7b91a..d118c31f 100644 --- a/pkg/gtm/resource.go +++ b/pkg/gtm/resource.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -173,6 +174,7 @@ func (g *gtm) ListResources(ctx context.Context, params ListResourcesRequest) ([ if err != nil { return nil, fmt.Errorf("ListResources request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -201,6 +203,7 @@ func (g *gtm) GetResource(ctx context.Context, params GetResourceRequest) (*GetR if err != nil { return nil, fmt.Errorf("GetResource request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -229,6 +232,7 @@ func (g *gtm) CreateResource(ctx context.Context, params CreateResourceRequest) if err != nil { return nil, fmt.Errorf("resource request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, g.Error(resp) @@ -257,6 +261,7 @@ func (g *gtm) UpdateResource(ctx context.Context, params UpdateResourceRequest) if err != nil { return nil, fmt.Errorf("resource request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) @@ -285,6 +290,7 @@ func (g *gtm) DeleteResource(ctx context.Context, params DeleteResourceRequest) if err != nil { return nil, fmt.Errorf("DeleteResource request failed: %w", err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, g.Error(resp) diff --git a/pkg/hapi/change_requests.go b/pkg/hapi/change_requests.go index 5ff77fd4..ee8166b7 100644 --- a/pkg/hapi/change_requests.go +++ b/pkg/hapi/change_requests.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -48,6 +50,7 @@ func (h *hapi) GetChangeRequest(ctx context.Context, prop GetChangeRequest) (*Ch if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetChangeRequest, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetChangeRequest, h.Error(resp)) diff --git a/pkg/hapi/edgehostname.go b/pkg/hapi/edgehostname.go index 473b810d..02892b3f 100644 --- a/pkg/hapi/edgehostname.go +++ b/pkg/hapi/edgehostname.go @@ -12,7 +12,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -229,6 +229,7 @@ func (h *hapi) DeleteEdgeHostname(ctx context.Context, params DeleteEdgeHostname if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeleteEdgeHostname, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%s: %w", ErrDeleteEdgeHostname, h.Error(resp)) @@ -253,6 +254,7 @@ func (h *hapi) GetEdgeHostname(ctx context.Context, edgeHostnameID int) (*GetEdg if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeHostname, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeHostname, h.Error(resp)) @@ -299,6 +301,7 @@ func (h *hapi) UpdateEdgeHostname(ctx context.Context, request UpdateEdgeHostnam if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateEdgeHostname, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusAccepted { return nil, fmt.Errorf("%w: %s", ErrUpdateEdgeHostname, h.Error(resp)) @@ -331,6 +334,7 @@ func (h *hapi) GetCertificate(ctx context.Context, params GetCertificateRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCertificate, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode == http.StatusNotFound { return nil, fmt.Errorf("%s: %s: %w", ErrGetCertificate, ErrNotFound, h.Error(resp)) diff --git a/pkg/iam/api_clients.go b/pkg/iam/api_clients.go index 816d93c1..babef015 100644 --- a/pkg/iam/api_clients.go +++ b/pkg/iam/api_clients.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -414,6 +415,7 @@ func (i *iam) LockAPIClient(ctx context.Context, params LockAPIClientRequest) (* if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrLockAPIClient, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrLockAPIClient, i.Error(resp)) @@ -445,6 +447,7 @@ func (i *iam) UnlockAPIClient(ctx context.Context, params UnlockAPIClientRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUnlockAPIClient, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUnlockAPIClient, i.Error(resp)) @@ -476,13 +479,13 @@ func (i *iam) ListAPIClients(ctx context.Context, params ListAPIClientsRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAPIClients, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAPIClients, i.Error(resp)) } return result, nil - } func (i *iam) GetAPIClient(ctx context.Context, params GetAPIClientRequest) (*GetAPIClientResponse, error) { @@ -516,6 +519,7 @@ func (i *iam) GetAPIClient(ctx context.Context, params GetAPIClientRequest) (*Ge if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetAPIClient, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetAPIClient, i.Error(resp)) @@ -542,6 +546,7 @@ func (i *iam) CreateAPIClient(ctx context.Context, params CreateAPIClientRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateAPIClient, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateAPIClient, i.Error(resp)) @@ -572,6 +577,7 @@ func (i *iam) UpdateAPIClient(ctx context.Context, params UpdateAPIClientRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateAPIClient, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateAPIClient, i.Error(resp)) @@ -597,6 +603,7 @@ func (i *iam) DeleteAPIClient(ctx context.Context, params DeleteAPIClientRequest if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteAPIClient, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteAPIClient, i.Error(resp)) diff --git a/pkg/iam/api_clients_credentials.go b/pkg/iam/api_clients_credentials.go index 47d4b04a..a5cd603c 100644 --- a/pkg/iam/api_clients_credentials.go +++ b/pkg/iam/api_clients_credentials.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -206,6 +207,7 @@ func (i *iam) CreateCredential(ctx context.Context, params CreateCredentialReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateCredential, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateCredential, i.Error(resp)) @@ -241,6 +243,7 @@ func (i *iam) ListCredentials(ctx context.Context, params ListCredentialsRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListCredentials, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListCredentials, i.Error(resp)) @@ -280,6 +283,7 @@ func (i *iam) GetCredential(ctx context.Context, params GetCredentialRequest) (* if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCredential, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetCredential, i.Error(resp)) @@ -321,6 +325,7 @@ func (i *iam) UpdateCredential(ctx context.Context, params UpdateCredentialReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateCredential, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateCredential, i.Error(resp)) @@ -355,6 +360,7 @@ func (i *iam) DeleteCredential(ctx context.Context, params DeleteCredentialReque if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteCredential, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteCredential, i.Error(resp)) @@ -389,6 +395,7 @@ func (i *iam) DeactivateCredential(ctx context.Context, params DeactivateCredent if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeactivateCredential, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeactivateCredential, i.Error(resp)) @@ -419,6 +426,7 @@ func (i *iam) DeactivateCredentials(ctx context.Context, params DeactivateCreden if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeactivateCredentials, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeactivateCredentials, i.Error(resp)) diff --git a/pkg/iam/blocked_properties.go b/pkg/iam/blocked_properties.go index 6720eac4..0fbe2b0c 100644 --- a/pkg/iam/blocked_properties.go +++ b/pkg/iam/blocked_properties.go @@ -8,6 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -70,6 +71,7 @@ func (i *iam) ListBlockedProperties(ctx context.Context, params ListBlockedPrope if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListBlockedProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListBlockedProperties, i.Error(resp)) @@ -98,6 +100,7 @@ func (i *iam) UpdateBlockedProperties(ctx context.Context, params UpdateBlockedP if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateBlockedProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateBlockedProperties, i.Error(resp)) diff --git a/pkg/iam/cidr.go b/pkg/iam/cidr.go index ed28b947..b5c0de18 100644 --- a/pkg/iam/cidr.go +++ b/pkg/iam/cidr.go @@ -11,6 +11,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -186,6 +187,7 @@ func (i *iam) ListCIDRBlocks(ctx context.Context, params ListCIDRBlocksRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListCIDRBlocks, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListCIDRBlocks, i.Error(resp)) @@ -212,6 +214,7 @@ func (i *iam) CreateCIDRBlock(ctx context.Context, params CreateCIDRBlockRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateCIDRBlock, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateCIDRBlock, i.Error(resp)) @@ -247,6 +250,7 @@ func (i *iam) GetCIDRBlock(ctx context.Context, params GetCIDRBlockRequest) (*Ge if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCIDRBlock, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetCIDRBlock, i.Error(resp)) @@ -273,6 +277,7 @@ func (i *iam) UpdateCIDRBlock(ctx context.Context, params UpdateCIDRBlockRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateCIDRBlock, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateCIDRBlock, i.Error(resp)) @@ -298,6 +303,7 @@ func (i *iam) DeleteCIDRBlock(ctx context.Context, params DeleteCIDRBlockRequest if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteCIDRBlock, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteCIDRBlock, i.Error(resp)) @@ -332,6 +338,7 @@ func (i *iam) ValidateCIDRBlock(ctx context.Context, params ValidateCIDRBlockReq if err != nil { return fmt.Errorf("%w: request failed: %s", ErrValidateCIDRBlock, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrValidateCIDRBlock, i.Error(resp)) diff --git a/pkg/iam/groups.go b/pkg/iam/groups.go index 95f4d63d..3aadaf2d 100644 --- a/pkg/iam/groups.go +++ b/pkg/iam/groups.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -166,6 +167,7 @@ func (i *iam) CreateGroup(ctx context.Context, params GroupRequest) (*Group, err if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateGroup, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateGroup, i.Error(resp)) @@ -201,6 +203,7 @@ func (i *iam) GetGroup(ctx context.Context, params GetGroupRequest) (*Group, err if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetGroup, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetGroup, i.Error(resp)) @@ -238,6 +241,7 @@ func (i *iam) ListAffectedUsers(ctx context.Context, params ListAffectedUsersReq if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAffectedUsers, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAffectedUsers, i.Error(resp)) @@ -269,6 +273,7 @@ func (i *iam) ListGroups(ctx context.Context, params ListGroupsRequest) ([]Group if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListGroups, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListGroups, i.Error(resp)) @@ -299,6 +304,7 @@ func (i *iam) RemoveGroup(ctx context.Context, params RemoveGroupRequest) error if err != nil { return fmt.Errorf("%w: request failed: %s", ErrRemoveGroup, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrRemoveGroup, i.Error(resp)) @@ -330,6 +336,7 @@ func (i *iam) UpdateGroupName(ctx context.Context, params GroupRequest) (*Group, if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateGroupName, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateGroupName, i.Error(resp)) @@ -360,6 +367,7 @@ func (i *iam) MoveGroup(ctx context.Context, params MoveGroupRequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrMoveGroup, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%w: %s", ErrMoveGroup, i.Error(resp)) diff --git a/pkg/iam/helper.go b/pkg/iam/helper.go index 573694e7..e15e36bc 100644 --- a/pkg/iam/helper.go +++ b/pkg/iam/helper.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -190,6 +191,7 @@ func (i *iam) ListAllowedCPCodes(ctx context.Context, params ListAllowedCPCodesR if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAllowedCPCodes, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAllowedCPCodes, i.Error(resp)) @@ -212,6 +214,7 @@ func (i *iam) ListAuthorizedUsers(ctx context.Context) (ListAuthorizedUsersRespo if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAuthorizedUsers, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAuthorizedUsers, i.Error(resp)) @@ -251,6 +254,7 @@ func (i *iam) ListAllowedAPIs(ctx context.Context, params ListAllowedAPIsRequest if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAllowedAPIs, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAllowedAPIs, i.Error(resp)) @@ -279,6 +283,7 @@ func (i *iam) ListAccessibleGroups(ctx context.Context, params ListAccessibleGro if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrAccessibleGroups, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrAccessibleGroups, i.Error(resp)) diff --git a/pkg/iam/ip_allowlist.go b/pkg/iam/ip_allowlist.go index 264d2dd0..80717846 100644 --- a/pkg/iam/ip_allowlist.go +++ b/pkg/iam/ip_allowlist.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -38,6 +40,7 @@ func (i *iam) DisableIPAllowlist(ctx context.Context) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDisableIPAllowlist, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDisableIPAllowlist, i.Error(resp)) @@ -61,6 +64,7 @@ func (i *iam) EnableIPAllowlist(ctx context.Context) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrEnableIPAllowlist, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrEnableIPAllowlist, i.Error(resp)) @@ -85,6 +89,7 @@ func (i *iam) GetIPAllowlistStatus(ctx context.Context) (*GetIPAllowlistStatusRe if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetIPAllowlistStatus, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetIPAllowlistStatus, i.Error(resp)) diff --git a/pkg/iam/properties.go b/pkg/iam/properties.go index 66c5aedb..88600228 100644 --- a/pkg/iam/properties.go +++ b/pkg/iam/properties.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -234,6 +235,7 @@ func (i *iam) ListProperties(ctx context.Context, params ListPropertiesRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListProperties, i.Error(resp)) @@ -271,6 +273,7 @@ func (i *iam) ListUsersForProperty(ctx context.Context, params ListUsersForPrope if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListUsersForProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListUsersForProperty, i.Error(resp)) @@ -306,6 +309,7 @@ func (i *iam) GetProperty(ctx context.Context, params GetPropertyRequest) (*GetP if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetProperty, i.Error(resp)) @@ -333,6 +337,7 @@ func (i *iam) MoveProperty(ctx context.Context, params MovePropertyRequest) erro if err != nil { return fmt.Errorf("%w: request failed: %s", ErrMoveProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrMoveProperty, i.Error(resp)) @@ -404,6 +409,7 @@ func (i *iam) BlockUsers(ctx context.Context, params BlockUsersRequest) (*BlockU if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrBlockUsers, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrBlockUsers, i.Error(resp)) diff --git a/pkg/iam/roles.go b/pkg/iam/roles.go index 6c032bf8..601fdeda 100644 --- a/pkg/iam/roles.go +++ b/pkg/iam/roles.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -175,6 +176,7 @@ func (i *iam) CreateRole(ctx context.Context, params CreateRoleRequest) (*Role, if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateRole, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateRole, i.Error(resp)) @@ -213,6 +215,7 @@ func (i *iam) GetRole(ctx context.Context, params GetRoleRequest) (*Role, error) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetRole, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetRole, i.Error(resp)) @@ -244,6 +247,7 @@ func (i *iam) UpdateRole(ctx context.Context, params UpdateRoleRequest) (*Role, if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateRole, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateRole, i.Error(resp)) @@ -274,6 +278,7 @@ func (i *iam) DeleteRole(ctx context.Context, params DeleteRoleRequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeleteRole, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeleteRole, i.Error(resp)) @@ -311,6 +316,7 @@ func (i *iam) ListRoles(ctx context.Context, params ListRolesRequest) ([]Role, e if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListRoles, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListRoles, i.Error(resp)) @@ -338,6 +344,7 @@ func (i *iam) ListGrantableRoles(ctx context.Context) ([]RoleGrantedRole, error) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListGrantableRoles, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListGrantableRoles, i.Error(resp)) diff --git a/pkg/iam/support.go b/pkg/iam/support.go index 382dae87..b3466472 100644 --- a/pkg/iam/support.go +++ b/pkg/iam/support.go @@ -8,6 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -112,6 +113,7 @@ func (i *iam) GetPasswordPolicy(ctx context.Context) (*GetPasswordPolicyResponse if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPasswordPolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPasswordPolicy, i.Error(resp)) @@ -136,6 +138,7 @@ func (i *iam) ListProducts(ctx context.Context) ([]string, error) { if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListProducts, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListProducts, i.Error(resp)) @@ -164,6 +167,7 @@ func (i *iam) ListStates(ctx context.Context, params ListStatesRequest) ([]strin if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListStates, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListStates, i.Error(resp)) @@ -188,6 +192,7 @@ func (i *iam) ListTimeoutPolicies(ctx context.Context) ([]TimeoutPolicy, error) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListTimeoutPolicies, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListTimeoutPolicies, i.Error(resp)) @@ -225,6 +230,7 @@ func (i *iam) ListAccountSwitchKeys(ctx context.Context, params ListAccountSwitc if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAccountSwitchKeys, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAccountSwitchKeys, i.Error(resp)) @@ -249,6 +255,7 @@ func (i *iam) SupportedContactTypes(ctx context.Context) ([]string, error) { if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrSupportedContactTypes, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrSupportedContactTypes, i.Error(resp)) @@ -273,6 +280,7 @@ func (i *iam) SupportedCountries(ctx context.Context) ([]string, error) { if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrSupportedCountries, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrSupportedCountries, i.Error(resp)) @@ -297,6 +305,7 @@ func (i *iam) SupportedLanguages(ctx context.Context) ([]string, error) { if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrSupportedLanguages, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrSupportedLanguages, i.Error(resp)) @@ -321,6 +330,7 @@ func (i *iam) SupportedTimezones(ctx context.Context) ([]Timezone, error) { if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrSupportedTimezones, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrSupportedTimezones, i.Error(resp)) diff --git a/pkg/iam/user.go b/pkg/iam/user.go index 9667659b..bd901908 100644 --- a/pkg/iam/user.go +++ b/pkg/iam/user.go @@ -10,6 +10,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/go-ozzo/ozzo-validation/v4/is" ) @@ -356,6 +357,7 @@ func (i *iam) CreateUser(ctx context.Context, params CreateUserRequest) (*User, if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateUser, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateUser, i.Error(resp)) @@ -394,6 +396,7 @@ func (i *iam) GetUser(ctx context.Context, params GetUserRequest) (*User, error) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetUser, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetUser, i.Error(resp)) @@ -429,6 +432,7 @@ func (i *iam) ListUsers(ctx context.Context, params ListUsersRequest) ([]UserLis if err != nil { return nil, fmt.Errorf("%w: request failed:\n%s", ErrListUsers, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListUsers, i.Error(resp)) @@ -459,6 +463,7 @@ func (i *iam) RemoveUser(ctx context.Context, params RemoveUserRequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrRemoveUser, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrRemoveUser, i.Error(resp)) @@ -491,6 +496,7 @@ func (i *iam) UpdateUserAuthGrants(ctx context.Context, params UpdateUserAuthGra if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateUserAuthGrants, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateUserAuthGrants, i.Error(resp)) @@ -522,6 +528,7 @@ func (i *iam) UpdateUserInfo(ctx context.Context, params UpdateUserInfoRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateUserInfo, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateUserInfo, i.Error(resp)) @@ -553,6 +560,7 @@ func (i *iam) UpdateUserNotifications(ctx context.Context, params UpdateUserNoti if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateUserNotifications, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateUserNotifications, i.Error(resp)) @@ -587,6 +595,7 @@ func (i *iam) UpdateTFA(ctx context.Context, params UpdateTFARequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrUpdateTFA, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrUpdateTFA, i.Error(resp)) @@ -617,6 +626,7 @@ func (i *iam) UpdateMFA(ctx context.Context, params UpdateMFARequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrUpdateMFA, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrUpdateMFA, i.Error(resp)) @@ -643,6 +653,7 @@ func (i *iam) ResetMFA(ctx context.Context, params ResetMFARequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrResetMFA, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrResetMFA, i.Error(resp)) diff --git a/pkg/iam/user_lock.go b/pkg/iam/user_lock.go index c77d3eef..aec52a26 100644 --- a/pkg/iam/user_lock.go +++ b/pkg/iam/user_lock.go @@ -8,6 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -67,6 +68,7 @@ func (i *iam) LockUser(ctx context.Context, params LockUserRequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrLockUser, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrLockUser, i.Error(resp)) @@ -97,6 +99,7 @@ func (i *iam) UnlockUser(ctx context.Context, params UnlockUserRequest) error { if err != nil { return fmt.Errorf("%w: request failed: %s", ErrUnlockUser, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrUnlockUser, i.Error(resp)) diff --git a/pkg/iam/user_password.go b/pkg/iam/user_password.go index 459099e1..9faa8e5b 100644 --- a/pkg/iam/user_password.go +++ b/pkg/iam/user_password.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -81,6 +82,7 @@ func (i *iam) ResetUserPassword(ctx context.Context, params ResetUserPasswordReq if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrResetUserPassword, err) } + defer session.CloseResponseBody(resp) if !((!params.SendEmail && resp.StatusCode == http.StatusOK) || (params.SendEmail && resp.StatusCode == http.StatusNoContent)) { return nil, fmt.Errorf("%s: %w", ErrResetUserPassword, i.Error(resp)) @@ -111,6 +113,7 @@ func (i *iam) SetUserPassword(ctx context.Context, params SetUserPasswordRequest if err != nil { return fmt.Errorf("%w: request failed: %s", ErrSetUserPassword, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrSetUserPassword, i.Error(resp)) diff --git a/pkg/imaging/policy.go b/pkg/imaging/policy.go index 8407fa93..90d492e8 100644 --- a/pkg/imaging/policy.go +++ b/pkg/imaging/policy.go @@ -8,7 +8,7 @@ import ( "net/http" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -356,6 +356,7 @@ func (i *imaging) ListPolicies(ctx context.Context, params ListPoliciesRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicies, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicies, i.Error(resp)) @@ -387,6 +388,7 @@ func (i *imaging) GetPolicy(ctx context.Context, params GetPolicyRequest) (Polic if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicy, i.Error(resp)) @@ -423,6 +425,7 @@ func (i *imaging) UpsertPolicy(ctx context.Context, params UpsertPolicyRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpsertPolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrUpsertPolicy, i.Error(resp)) @@ -454,6 +457,7 @@ func (i *imaging) DeletePolicy(ctx context.Context, params DeletePolicyRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeletePolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrDeletePolicy, i.Error(resp)) @@ -485,6 +489,7 @@ func (i *imaging) GetPolicyHistory(ctx context.Context, params GetPolicyHistoryR if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicyHistory, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicyHistory, i.Error(resp)) @@ -516,6 +521,7 @@ func (i *imaging) RollbackPolicy(ctx context.Context, params RollbackPolicyReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrRollbackPolicy, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrRollbackPolicy, i.Error(resp)) diff --git a/pkg/imaging/policyset.go b/pkg/imaging/policyset.go index ee10cc46..a8bcb122 100644 --- a/pkg/imaging/policyset.go +++ b/pkg/imaging/policyset.go @@ -8,7 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -210,6 +210,7 @@ func (i *imaging) ListPolicySets(ctx context.Context, params ListPolicySetsReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListPolicySets, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListPolicySets, i.Error(resp)) @@ -249,6 +250,7 @@ func (i *imaging) GetPolicySet(ctx context.Context, params GetPolicySetRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPolicySet, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPolicySet, i.Error(resp)) @@ -278,6 +280,7 @@ func (i *imaging) CreatePolicySet(ctx context.Context, params CreatePolicySetReq if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreatePolicySet, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreatePolicySet, i.Error(resp)) @@ -312,6 +315,7 @@ func (i *imaging) UpdatePolicySet(ctx context.Context, params UpdatePolicySetReq if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePolicySet, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdatePolicySet, i.Error(resp)) @@ -344,6 +348,7 @@ func (i *imaging) DeletePolicySet(ctx context.Context, params DeletePolicySetReq if err != nil { return fmt.Errorf("%w: request failed: %s", ErrDeletePolicySet, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent { return fmt.Errorf("%s: %w", ErrDeletePolicySet, i.Error(resp)) diff --git a/pkg/networklists/activations.go b/pkg/networklists/activations.go index 9be1e0ba..8ec9c2f1 100644 --- a/pkg/networklists/activations.go +++ b/pkg/networklists/activations.go @@ -6,6 +6,7 @@ import ( "net/http" "time" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -265,6 +266,7 @@ func (p *networklists) GetActivations(ctx context.Context, params GetActivations if err != nil { return nil, fmt.Errorf("getactivations request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -296,6 +298,7 @@ func (p *networklists) GetActivation(ctx context.Context, params GetActivationRe if err != nil { return nil, fmt.Errorf("getactivation request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -325,6 +328,7 @@ func (p *networklists) CreateActivations(ctx context.Context, params CreateActiv if err != nil { return nil, fmt.Errorf("create activation request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -375,6 +379,7 @@ func (p *networklists) RemoveActivations(ctx context.Context, params RemoveActiv if err != nil { return nil, fmt.Errorf("remove activation request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) diff --git a/pkg/networklists/network_list.go b/pkg/networklists/network_list.go index 8622b9b0..e057e00e 100644 --- a/pkg/networklists/network_list.go +++ b/pkg/networklists/network_list.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -285,6 +286,7 @@ func (p *networklists) GetNetworkList(ctx context.Context, params GetNetworkList if err != nil { return nil, fmt.Errorf("getnetworklist request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -314,6 +316,7 @@ func (p *networklists) GetNetworkLists(ctx context.Context, params GetNetworkLis if err != nil { return nil, fmt.Errorf("getnetworklists request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -356,6 +359,7 @@ func (p *networklists) UpdateNetworkList(ctx context.Context, params UpdateNetwo if err != nil { return nil, fmt.Errorf("update NetworkList request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -386,6 +390,7 @@ func (p *networklists) CreateNetworkList(ctx context.Context, params CreateNetwo if err != nil { return nil, fmt.Errorf("create networklistrequest failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, p.Error(resp) @@ -422,6 +427,7 @@ func (p *networklists) RemoveNetworkList(ctx context.Context, params RemoveNetwo if err != nil { return nil, fmt.Errorf("RemoveNetworkList request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK { return nil, p.Error(resp) diff --git a/pkg/networklists/network_list_description.go b/pkg/networklists/network_list_description.go index 9f1f2bcd..d2a31498 100644 --- a/pkg/networklists/network_list_description.go +++ b/pkg/networklists/network_list_description.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -107,6 +108,7 @@ func (p *networklists) GetNetworkListDescription(ctx context.Context, params Get if err != nil { return nil, fmt.Errorf("getnetworklistdescription request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -139,6 +141,7 @@ func (p *networklists) UpdateNetworkListDescription(ctx context.Context, params if err != nil { return nil, fmt.Errorf("create NetworkListDescription request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { return nil, p.Error(resp) diff --git a/pkg/networklists/network_list_subscription.go b/pkg/networklists/network_list_subscription.go index b02824f2..ce1eed8e 100644 --- a/pkg/networklists/network_list_subscription.go +++ b/pkg/networklists/network_list_subscription.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -108,6 +110,7 @@ func (p *networklists) GetNetworkListSubscription(ctx context.Context, _ GetNetw if err != nil { return nil, fmt.Errorf("getnetworklistsubscription request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -134,6 +137,7 @@ func (p *networklists) UpdateNetworkListSubscription(ctx context.Context, params if err != nil { return nil, fmt.Errorf("remove NetworkListSubscription request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { return nil, p.Error(resp) @@ -159,6 +163,7 @@ func (p *networklists) RemoveNetworkListSubscription(ctx context.Context, params if err != nil { return nil, fmt.Errorf("remove NetworkListSubscription request failed: %s", err.Error()) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { return nil, p.Error(resp) diff --git a/pkg/papi/activation.go b/pkg/papi/activation.go index 80f3d6ab..34a39bbe 100644 --- a/pkg/papi/activation.go +++ b/pkg/papi/activation.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/spf13/cast" ) @@ -269,6 +270,7 @@ func (p *papi) CreateActivation(ctx context.Context, params CreateActivationRequ if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateActivation, p.Error(resp)) @@ -318,6 +320,7 @@ func (p *papi) GetActivations(ctx context.Context, params GetActivationsRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetActivations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetActivations, p.Error(resp)) @@ -352,6 +355,7 @@ func (p *papi) GetActivation(ctx context.Context, params GetActivationRequest) ( if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetActivation, p.Error(resp)) @@ -396,6 +400,7 @@ func (p *papi) CancelActivation(ctx context.Context, params CancelActivationRequ if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCancelActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCancelActivation, p.Error(resp)) diff --git a/pkg/papi/clientsettings.go b/pkg/papi/clientsettings.go index 053ad5ea..a4fb842f 100644 --- a/pkg/papi/clientsettings.go +++ b/pkg/papi/clientsettings.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -38,6 +40,7 @@ func (p *papi) GetClientSettings(ctx context.Context) (*ClientSettingsBody, erro if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetClientSettings, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetClientSettings, p.Error(resp)) @@ -63,6 +66,7 @@ func (p *papi) UpdateClientSettings(ctx context.Context, params ClientSettingsBo if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateClientSettings, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetClientSettings, p.Error(resp)) diff --git a/pkg/papi/contract.go b/pkg/papi/contract.go index 3015b1a9..1dde36dc 100644 --- a/pkg/papi/contract.go +++ b/pkg/papi/contract.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -46,6 +48,7 @@ func (p *papi) GetContracts(ctx context.Context) (*GetContractsResponse, error) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetContracts, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetContracts, p.Error(resp)) diff --git a/pkg/papi/cpcode.go b/pkg/papi/cpcode.go index da9b5a0a..15b59cbd 100644 --- a/pkg/papi/cpcode.go +++ b/pkg/papi/cpcode.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -210,6 +211,7 @@ func (p *papi) GetCPCodes(ctx context.Context, params GetCPCodesRequest) (*GetCP if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCPCodes, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetCPCodes, p.Error(resp)) @@ -238,6 +240,7 @@ func (p *papi) GetCPCode(ctx context.Context, params GetCPCodeRequest) (*GetCPCo if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCPCode, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetCPCode, p.Error(resp)) @@ -266,6 +269,7 @@ func (p *papi) GetCPCodeDetail(ctx context.Context, ID int) (*CPCodeDetailRespon if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetCPCodeDetail, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetCPCodeDetail, p.Error(resp)) @@ -294,6 +298,8 @@ func (p *papi) CreateCPCode(ctx context.Context, r CreateCPCodeRequest) (*Create if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateCPCode, err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateCPCode, p.Error(resp)) } @@ -325,6 +331,7 @@ func (p *papi) UpdateCPCode(ctx context.Context, r UpdateCPCodeRequest) (*CPCode if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateCPCode, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateCPCode, p.Error(resp)) diff --git a/pkg/papi/edgehostname.go b/pkg/papi/edgehostname.go index a6707108..7b3327e2 100644 --- a/pkg/papi/edgehostname.go +++ b/pkg/papi/edgehostname.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -197,6 +198,7 @@ func (p *papi) GetEdgeHostnames(ctx context.Context, params GetEdgeHostnamesRequ if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeHostnames, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetEdgeHostnames, p.Error(resp)) @@ -233,6 +235,7 @@ func (p *papi) GetEdgeHostname(ctx context.Context, params GetEdgeHostnameReques if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetEdgeHostname, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, p.Error(resp) @@ -272,6 +275,8 @@ func (p *papi) CreateEdgeHostname(ctx context.Context, r CreateEdgeHostnameReque if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateEdgeHostname, err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateEdgeHostname, p.Error(resp)) } diff --git a/pkg/papi/group.go b/pkg/papi/group.go index 1d35cee6..466ad449 100644 --- a/pkg/papi/group.go +++ b/pkg/papi/group.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -50,6 +52,7 @@ func (p *papi) GetGroups(ctx context.Context) (*GetGroupsResponse, error) { if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetGroups, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetGroups, p.Error(resp)) diff --git a/pkg/papi/include.go b/pkg/papi/include.go index b11fa11d..df0d7ba5 100644 --- a/pkg/papi/include.go +++ b/pkg/papi/include.go @@ -8,7 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" - + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -259,6 +259,7 @@ func (p *papi) ListIncludes(ctx context.Context, params ListIncludesRequest) (*L if err != nil { return nil, fmt.Errorf("%s: request failed: %w", ErrListIncludes, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListIncludes, p.Error(resp)) @@ -299,6 +300,7 @@ func (p *papi) ListIncludeParents(ctx context.Context, params ListIncludeParents if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListIncludeParents, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListIncludeParents, p.Error(resp)) @@ -335,6 +337,7 @@ func (p *papi) GetInclude(ctx context.Context, params GetIncludeRequest) (*GetIn if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetInclude, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetInclude, p.Error(resp)) @@ -376,6 +379,7 @@ func (p *papi) CreateInclude(ctx context.Context, params CreateIncludeRequest) ( if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateInclude, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateInclude, p.Error(resp)) @@ -425,6 +429,7 @@ func (p *papi) DeleteInclude(ctx context.Context, params DeleteIncludeRequest) ( if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeleteInclude, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrDeleteInclude, p.Error(resp)) diff --git a/pkg/papi/include_activations.go b/pkg/papi/include_activations.go index 5df617cd..8cdeda80 100644 --- a/pkg/papi/include_activations.go +++ b/pkg/papi/include_activations.go @@ -11,6 +11,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/ptr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -373,6 +374,7 @@ func (p *papi) ActivateInclude(ctx context.Context, params ActivateIncludeReques if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrActivateInclude, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrActivateInclude, p.Error(resp)) @@ -419,6 +421,7 @@ func (p *papi) DeactivateInclude(ctx context.Context, params DeactivateIncludeRe if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrDeactivateInclude, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrDeactivateInclude, p.Error(resp)) @@ -461,6 +464,7 @@ func (p *papi) CancelIncludeActivation(ctx context.Context, params CancelInclude if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCancelIncludeActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrCancelIncludeActivation, p.Error(resp)) @@ -489,6 +493,7 @@ func (p *papi) GetIncludeActivation(ctx context.Context, params GetIncludeActiva if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetIncludeActivation, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetIncludeActivation, p.Error(resp)) @@ -539,6 +544,7 @@ func (p *papi) ListIncludeActivations(ctx context.Context, params ListIncludeAct if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListIncludeActivations, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListIncludeActivations, p.Error(resp)) diff --git a/pkg/papi/include_rule.go b/pkg/papi/include_rule.go index ee72c51e..10a6b95f 100644 --- a/pkg/papi/include_rule.go +++ b/pkg/papi/include_rule.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -143,6 +144,7 @@ func (p *papi) GetIncludeRuleTree(ctx context.Context, params GetIncludeRuleTree if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetIncludeRuleTree, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetIncludeRuleTree, p.Error(resp)) @@ -188,6 +190,8 @@ func (p *papi) UpdateIncludeRuleTree(ctx context.Context, params UpdateIncludeRu if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateIncludeRuleTree, err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateIncludeRuleTree, p.Error(resp)) } diff --git a/pkg/papi/include_versions.go b/pkg/papi/include_versions.go index eeafea0d..0ad996aa 100644 --- a/pkg/papi/include_versions.go +++ b/pkg/papi/include_versions.go @@ -9,6 +9,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -218,6 +219,7 @@ func (p *papi) CreateIncludeVersion(ctx context.Context, params CreateIncludeVer if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateIncludeVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreateIncludeVersion, p.Error(resp)) @@ -263,6 +265,7 @@ func (p *papi) GetIncludeVersion(ctx context.Context, params GetIncludeVersionRe if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetIncludeVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetIncludeVersion, p.Error(resp)) @@ -304,6 +307,7 @@ func (p *papi) ListIncludeVersions(ctx context.Context, params ListIncludeVersio if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListIncludeVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListIncludeVersions, p.Error(resp)) @@ -332,6 +336,7 @@ func (p *papi) ListIncludeVersionAvailableCriteria(ctx context.Context, params L if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListIncludeVersionAvailableCriteria, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListIncludeVersionAvailableCriteria, p.Error(resp)) @@ -360,6 +365,7 @@ func (p *papi) ListIncludeVersionAvailableBehaviors(ctx context.Context, params if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListIncludeVersionAvailableBehaviors, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListIncludeVersionAvailableBehaviors, p.Error(resp)) diff --git a/pkg/papi/products.go b/pkg/papi/products.go index 51cf5397..40a4b28c 100644 --- a/pkg/papi/products.go +++ b/pkg/papi/products.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -66,6 +67,7 @@ func (p *papi) GetProducts(ctx context.Context, params GetProductsRequest) (*Get if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetProducts, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetProducts, p.Error(resp)) diff --git a/pkg/papi/property.go b/pkg/papi/property.go index 057cdc20..a5a31047 100644 --- a/pkg/papi/property.go +++ b/pkg/papi/property.go @@ -8,6 +8,7 @@ import ( "net/url" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -219,6 +220,7 @@ func (p *papi) GetProperties(ctx context.Context, params GetPropertiesRequest) ( if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetProperties, p.Error(resp)) @@ -251,6 +253,7 @@ func (p *papi) CreateProperty(ctx context.Context, params CreatePropertyRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreateProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode == http.StatusNotFound { return nil, fmt.Errorf("%s: %w: %s", ErrCreateProperty, ErrNotFound, err) @@ -305,6 +308,7 @@ func (p *papi) GetProperty(ctx context.Context, params GetPropertyRequest) (*Get if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetProperty, p.Error(resp)) @@ -353,6 +357,7 @@ func (p *papi) RemoveProperty(ctx context.Context, params RemovePropertyRequest) if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrRemoveProperty, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrRemoveProperty, p.Error(resp)) diff --git a/pkg/papi/propertyhostname.go b/pkg/papi/propertyhostname.go index 9900e43a..1f1b3649 100644 --- a/pkg/papi/propertyhostname.go +++ b/pkg/papi/propertyhostname.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -145,6 +146,8 @@ func (p *papi) GetPropertyVersionHostnames(ctx context.Context, params GetProper if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPropertyVersionHostnames, err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPropertyVersionHostnames, p.Error(resp)) } @@ -184,6 +187,7 @@ func (p *papi) UpdatePropertyVersionHostnames(ctx context.Context, params Update if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePropertyVersionHostnames, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdatePropertyVersionHostnames, p.Error(resp)) diff --git a/pkg/papi/propertyversion.go b/pkg/papi/propertyversion.go index af6df251..ab2ac520 100644 --- a/pkg/papi/propertyversion.go +++ b/pkg/papi/propertyversion.go @@ -10,6 +10,7 @@ import ( "strconv" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -285,6 +286,7 @@ func (p *papi) GetPropertyVersions(ctx context.Context, params GetPropertyVersio if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPropertyVersions, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPropertyVersions, p.Error(resp)) @@ -320,6 +322,7 @@ func (p *papi) GetLatestVersion(ctx context.Context, params GetLatestVersionRequ if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetLatestVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetLatestVersion, p.Error(resp)) @@ -356,6 +359,7 @@ func (p *papi) GetPropertyVersion(ctx context.Context, params GetPropertyVersion if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetPropertyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetPropertyVersion, p.Error(resp)) @@ -391,6 +395,7 @@ func (p *papi) CreatePropertyVersion(ctx context.Context, request CreateProperty if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrCreatePropertyVersion, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusCreated { return nil, fmt.Errorf("%s: %w", ErrCreatePropertyVersion, p.Error(resp)) @@ -439,6 +444,7 @@ func (p *papi) GetAvailableBehaviors(ctx context.Context, params GetAvailableBeh if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetAvailableBehaviors, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetAvailableBehaviors, p.Error(resp)) @@ -479,6 +485,7 @@ func (p *papi) GetAvailableCriteria(ctx context.Context, params GetAvailableCrit if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetAvailableCriteria, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetAvailableCriteria, p.Error(resp)) @@ -519,6 +526,7 @@ func (p *papi) ListAvailableIncludes(ctx context.Context, params ListAvailableIn if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListAvailableIncludes, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListAvailableIncludes, p.Error(resp)) @@ -559,6 +567,7 @@ func (p *papi) ListReferencedIncludes(ctx context.Context, params ListReferenced if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrListReferencedIncludes, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrListReferencedIncludes, p.Error(resp)) diff --git a/pkg/papi/response_link.go b/pkg/papi/response_link.go index ac2727ca..18d73617 100644 --- a/pkg/papi/response_link.go +++ b/pkg/papi/response_link.go @@ -14,7 +14,7 @@ var ( // ResponseLinkParse parse the link and returns the id func ResponseLinkParse(link string) (string, error) { - locURL, err := url.Parse(string(link)) + locURL, err := url.Parse(link) if err != nil { return "", err } diff --git a/pkg/papi/rule.go b/pkg/papi/rule.go index c13e1443..29b8fb85 100644 --- a/pkg/papi/rule.go +++ b/pkg/papi/rule.go @@ -8,6 +8,7 @@ import ( "regexp" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegriderr" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -263,6 +264,7 @@ func (p *papi) GetRuleTree(ctx context.Context, params GetRuleTreeRequest) (*Get if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetRuleTree, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetRuleTree, p.Error(resp)) @@ -305,6 +307,8 @@ func (p *papi) UpdateRuleTree(ctx context.Context, request UpdateRulesRequest) ( if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrUpdateRuleTree, err) } + defer session.CloseResponseBody(resp) + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrUpdateRuleTree, p.Error(resp)) } diff --git a/pkg/papi/ruleformats.go b/pkg/papi/ruleformats.go index 7fa3518f..a620a0a7 100644 --- a/pkg/papi/ruleformats.go +++ b/pkg/papi/ruleformats.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" ) type ( @@ -39,6 +41,7 @@ func (p *papi) GetRuleFormats(ctx context.Context) (*GetRuleFormatsResponse, err if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrGetRuleFormats, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrGetRuleFormats, p.Error(resp)) diff --git a/pkg/papi/search.go b/pkg/papi/search.go index 08266b82..a24a8eaf 100644 --- a/pkg/papi/search.go +++ b/pkg/papi/search.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -88,6 +89,7 @@ func (p *papi) SearchProperties(ctx context.Context, request SearchRequest) (*Se if err != nil { return nil, fmt.Errorf("%w: request failed: %s", ErrSearchProperties, err) } + defer session.CloseResponseBody(resp) if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s: %w", ErrSearchProperties, p.Error(resp)) diff --git a/pkg/session/session.go b/pkg/session/session.go index 0024e42a..c4f5e81c 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -208,3 +208,8 @@ func WithContextHeaders(h http.Header) ContextOption { o.header = h } } + +// CloseResponseBody closes response body +func CloseResponseBody(resp *http.Response) { + _ = resp.Body.Close() +} From 61e84a2c52142a7ffc7dbeea49c65424f08133e3 Mon Sep 17 00:00:00 2001 From: Michal Wojcik Date: Mon, 4 Nov 2024 13:56:23 +0100 Subject: [PATCH 06/12] DXE-4336 Debug messages are emitted when cli-terraform retries HTTP requests --- pkg/session/logger.go | 52 ++++++++++++++++++++++++++++++++++++++++++ pkg/session/retries.go | 1 + 2 files changed, 53 insertions(+) create mode 100644 pkg/session/logger.go diff --git a/pkg/session/logger.go b/pkg/session/logger.go new file mode 100644 index 00000000..eb8ff5c8 --- /dev/null +++ b/pkg/session/logger.go @@ -0,0 +1,52 @@ +package session + +import ( + "github.com/apex/log" + "github.com/hashicorp/go-retryablehttp" +) + +// GetRetryableLogger returns wrapper retryablehttp.LeveledLogger for log.Interface +func GetRetryableLogger(log log.Interface) retryablehttp.LeveledLogger { + return &retryableLogger{log: log} +} + +// retryableLogger is wrapper for log.Interface to expose retryablehttp.LeveledLogger needed for retry logic +type retryableLogger struct { + log log.Interface +} + +// Error level formatted message. +func (l *retryableLogger) Error(msg string, keysAndValues ...interface{}) { + kv := append([]interface{}{}, keysAndValues...) + switch msg { + case "request failed": + l.log.Errorf("%s %s request failed: %v", kv[1], kv[3], kv[5]) + case "error reading response body": + l.log.Errorf("error reading response body: %v", kv[1]) + default: + l.log.Errorf(msg, keysAndValues...) + } +} + +// Info level formatted message. +func (l *retryableLogger) Info(msg string, keysAndValues ...interface{}) { + l.log.Infof(msg, keysAndValues...) +} + +// Debug level formatted message. +func (l *retryableLogger) Debug(msg string, keysAndValues ...interface{}) { + kv := append([]interface{}{}, keysAndValues...) + switch msg { + case "retrying request": + l.log.Debugf("%s: retrying in %s (%d left)", kv[1], kv[3], kv[5]) + case "performing request": + l.log.Debugf("%s %s", kv[1], kv[3]) + default: + l.log.Debugf(msg, keysAndValues...) + } +} + +// Warn level formatted message. +func (l *retryableLogger) Warn(msg string, keysAndValues ...interface{}) { + l.log.Warnf(msg, keysAndValues...) +} diff --git a/pkg/session/retries.go b/pkg/session/retries.go index be8d4852..17631696 100644 --- a/pkg/session/retries.go +++ b/pkg/session/retries.go @@ -67,6 +67,7 @@ func configureRetryClient(conf RetryConfig, signFunc func(r *http.Request) error } retryClient.CheckRetry = overrideRetryPolicy(retryablehttp.DefaultRetryPolicy, conf.ExcludedEndpoints) retryClient.Backoff = overrideBackoff(retryablehttp.DefaultBackoff, log) + retryClient.Logger = GetRetryableLogger(log) return retryClient, err } From 614e05d1e0e960ffa7d55052698fc214a95d2195 Mon Sep 17 00:00:00 2001 From: Amith Halavarthy Basavanagouda Date: Tue, 1 Oct 2024 06:33:41 +0000 Subject: [PATCH 07/12] BOTMAN-14988 Added a Content protection fields to export data --- CHANGELOG.md | 6 +++- pkg/appsec/export_configuration.go | 15 ++++---- .../ExportConfiguration.json | 35 +++++++++++++++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bce62952..ff6a7152 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,11 @@ #### FEATURES/ENHANCEMENTS: - +* APPSEC + * Added following content protection fields to `GetExportConfigurationResponse` under `BotManagement` section + * `ContentProtectionRules` + * `ContentProtectionRuleSequence` + * `ContentProtectionJavaScriptInjectionRules` diff --git a/pkg/appsec/export_configuration.go b/pkg/appsec/export_configuration.go index a5a4db86..e421d64a 100644 --- a/pkg/appsec/export_configuration.go +++ b/pkg/appsec/export_configuration.go @@ -808,12 +808,15 @@ type ( // BotManagement is returned as part of GetExportConfigurationResponse BotManagement struct { - AkamaiBotCategoryActions []map[string]interface{} `json:"akamaiBotCategoryActions,omitempty"` - BotDetectionActions []map[string]interface{} `json:"botDetectionActions,omitempty"` - BotManagementSettings map[string]interface{} `json:"botManagementSettings,omitempty"` - CustomBotCategoryActions []map[string]interface{} `json:"customBotCategoryActions,omitempty"` - JavascriptInjectionRules map[string]interface{} `json:"javascriptInjectionRules,omitempty"` - TransactionalEndpoints *TransactionalEndpoints `json:"transactionalEndpoints,omitempty"` + AkamaiBotCategoryActions []map[string]interface{} `json:"akamaiBotCategoryActions,omitempty"` + BotDetectionActions []map[string]interface{} `json:"botDetectionActions,omitempty"` + BotManagementSettings map[string]interface{} `json:"botManagementSettings,omitempty"` + CustomBotCategoryActions []map[string]interface{} `json:"customBotCategoryActions,omitempty"` + JavascriptInjectionRules map[string]interface{} `json:"javascriptInjectionRules,omitempty"` + TransactionalEndpoints *TransactionalEndpoints `json:"transactionalEndpoints,omitempty"` + ContentProtectionRules []map[string]interface{} `json:"contentProtectionRules,omitempty"` + ContentProtectionRuleSequence []string `json:"contentProtectionRuleSequence,omitempty"` + ContentProtectionJavaScriptInjectionRules []map[string]interface{} `json:"contentProtectionJavaScriptInjectionRules,omitempty"` } // TransactionalEndpoints is returned as port of GetExportConfigurationResponse diff --git a/pkg/appsec/testdata/TestExportConfiguration/ExportConfiguration.json b/pkg/appsec/testdata/TestExportConfiguration/ExportConfiguration.json index d33fc933..ea4632cc 100644 --- a/pkg/appsec/testdata/TestExportConfiguration/ExportConfiguration.json +++ b/pkg/appsec/testdata/TestExportConfiguration/ExportConfiguration.json @@ -1851,7 +1851,38 @@ "innerKey": "innerValueA" } } - } + }, + "contentProtectionRules": [ + { + "contentProtectionRuleId": "fakeba52-5c9e-4aa0-b5f7-5b88601d0d76", + "contentProtectionRuleName": "New Rule", + "primitiveKey": "primitiveValueA", + "arrayKey": [ + "arrayValueA1", + "arrayValueA2" + ], + "objectKey": { + "innerKey": "innerValueA" + } + } + ], + "contentProtectionRuleSequence": [ + "fakeba52-5c9e-4aa0-b5f7-5b88601d0d76" + ], + "contentProtectionJavaScriptInjectionRules": [ + { + "contentProtectionJavaScriptInjectionRuleId": "fakeb37c-15ce-4ec8-ad99-0252d8a4580b", + "contentProtectionJavaScriptInjectionRuleName": "New Injection Rule", + "primitiveKey": "primitiveValueA", + "arrayKey": [ + "arrayValueA1", + "arrayValueA2" + ], + "objectKey": { + "innerKey": "innerValueA" + } + } + ] }, "RequestBody": { "requestBodyInspectionLimitInKB" : "8" @@ -2126,4 +2157,4 @@ } ] } -} \ No newline at end of file +} From 16178e6116b387fd98c44615d12ef49688fe3019 Mon Sep 17 00:00:00 2001 From: Chaitanya Sanjay Bhangale Date: Fri, 25 Oct 2024 13:27:20 +0000 Subject: [PATCH 08/12] SECKSD-29186 Fix siem action types validation --- CHANGELOG.md | 9 ++++++ pkg/appsec/siem_settings.go | 28 ++++++++++++++-- pkg/appsec/siem_settings_test.go | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff6a7152..f249fbac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,15 @@ #### BUG FIXES: +* APPSEC + * Fixed SIEM exception validation for `Exceptions` field + + + + + + + * Cloud Access * Added custom error `ErrAccessKeyNotFound` to easier verify if provided access key does not exist. diff --git a/pkg/appsec/siem_settings.go b/pkg/appsec/siem_settings.go index eec7c5fd..cf63c4af 100644 --- a/pkg/appsec/siem_settings.go +++ b/pkg/appsec/siem_settings.go @@ -130,14 +130,32 @@ func (v UpdateSiemSettingsRequest) Validate() error { // Validate validates an Exception struct. func (v Exception) Validate() error { + validActionTypes := []string{"alert", "deny", "all_custom", "abort", "allow", "delay", "ignore", "monitor", "slow", "tarpit", "*"} return validation.Errors{ "Protection": validation.Validate(v.Protection, validation.Required, validation.In("botmanagement", "ipgeo", "rate", "urlProtection", "slowpost", "customrules", "waf", "apirequestconstraints", "clientrep", "malwareprotection", "aprProtection"). Error(fmt.Sprintf("value '%s' is invalid. Must be one of: 'botmanagement', 'ipgeo', 'rate', 'urlProtection', 'slowpost', 'customrules', 'waf', 'apirequestconstraints', 'clientrep', 'malwareprotection', 'aprProtection'", v.Protection))), - "ActionTypes": validation.Validate(v.Protection, validation.Required, validation.In("alert", "deny", "all_custom", "abort", "allow", "delay", "ignore", "monitor", "slow", "tarpit"). - Error(fmt.Sprintf("value '%v' is invalid. Must be one of: 'alert', 'deny', 'all_custom', 'abort', 'allow', 'delay', 'ignore', 'monitor', 'slow', 'tarpit'", v.ActionTypes))), + "ActionTypes": validation.ValidateStruct(&v, + validation.Field(&v.ActionTypes, validation.Required, validation.By(func(value interface{}) error { + actions, _ := value.([]string) + for _, actionType := range actions { + if !containsElement(validActionTypes, actionType) { + return fmt.Errorf("value '%s' is invalid. Must be one of: %v", actionType, validActionTypes) + } + } + return nil + }))), }.Filter() } +func containsElement(slice []string, item string) bool { + for _, v := range slice { + if v == item { + return true + } + } + return false +} + // Validate validates a RemoveSiemSettingsRequest. // Deprecated: this method will be removed in a future release. func (v RemoveSiemSettingsRequest) Validate() error { @@ -188,6 +206,12 @@ func (p *appsec) UpdateSiemSettings(ctx context.Context, params UpdateSiemSettin return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error()) } + for _, exception := range params.Exceptions { + if err := exception.Validate(); err != nil { + return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error()) + } + } + uri := fmt.Sprintf( "/appsec/v1/configs/%d/versions/%d/siem", params.ConfigID, diff --git a/pkg/appsec/siem_settings_test.go b/pkg/appsec/siem_settings_test.go index 46ae4835..26e1239b 100644 --- a/pkg/appsec/siem_settings_test.go +++ b/pkg/appsec/siem_settings_test.go @@ -6,6 +6,7 @@ import ( "errors" "net/http" "net/http/httptest" + "regexp" "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" @@ -185,6 +186,7 @@ func TestAppSec_UpdateSiemSettings(t *testing.T) { expectedResponse *UpdateSiemSettingsResponse withError error headers http.Header + errors *regexp.Regexp }{ "200 Success": { params: UpdateSiemSettingsRequest{ @@ -214,6 +216,52 @@ func TestAppSec_UpdateSiemSettings(t *testing.T) { expectedResponse: &result, expectedPath: "/appsec/v1/configs/43253/versions/15/siem", }, + "400 Bad Request action types": { + params: UpdateSiemSettingsRequest{ + ConfigID: 43253, + Version: 15, + EnableSiem: true, + Exceptions: []Exception{ + { + ActionTypes: []string{"reject"}, + Protection: "botmanagement", + }, + { + ActionTypes: []string{"deny"}, + Protection: "ipgeo", + }, + { + ActionTypes: []string{"alert"}, + Protection: "rate", + }, + }, + }, + headers: http.Header{ + "Content-Type": []string{"application/json;charset=UTF-8"}, + }, + responseStatus: http.StatusBadRequest, + errors: regexp.MustCompile(`struct validation: ActionTypes:.+`), + expectedPath: "/appsec/v1/configs/43253/versions/15/siem", + }, + "400 Bad Request protection": { + params: UpdateSiemSettingsRequest{ + ConfigID: 43253, + Version: 15, + EnableSiem: true, + Exceptions: []Exception{ + { + ActionTypes: []string{"tarpit"}, + Protection: "bot", + }, + }, + }, + headers: http.Header{ + "Content-Type": []string{"application/json;charset=UTF-8"}, + }, + responseStatus: http.StatusBadRequest, + errors: regexp.MustCompile(`struct validation: Protection:.+`), + expectedPath: "/appsec/v1/configs/43253/versions/15/siem", + }, "500 internal server error": { params: UpdateSiemSettingsRequest{ ConfigID: 43253, @@ -251,6 +299,13 @@ func TestAppSec_UpdateSiemSettings(t *testing.T) { session.ContextWithOptions( context.Background(), session.WithContextHeaders(test.headers)), test.params) + + if test.errors != nil { + require.Error(t, err) + assert.Regexp(t, test.errors, err.Error()) + return + } + if test.withError != nil { assert.True(t, errors.Is(err, test.withError), "want: %s; got: %s", test.withError, err) return From 07e1e8e29472cfdd296c9d41398992d333758594 Mon Sep 17 00:00:00 2001 From: Chaitanya Sanjay Bhangale Date: Wed, 6 Nov 2024 13:46:08 +0000 Subject: [PATCH 09/12] SECKSD-28867 modify EnabledBotmanSiemEvents to be omitted if empty --- CHANGELOG.md | 8 +++- pkg/appsec/siem_settings.go | 10 ++--- pkg/appsec/siem_settings_test.go | 39 ++++++++++++++++++- .../SiemSettingsWithoutEnabledBotmanSiem.json | 24 ++++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 pkg/appsec/testdata/TestSiemSettings/SiemSettingsWithoutEnabledBotmanSiem.json diff --git a/CHANGELOG.md b/CHANGELOG.md index f249fbac..889f089e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,13 @@ * `ContentProtectionRuleSequence` * `ContentProtectionJavaScriptInjectionRules` - + * Changed `EnabledBotmanSiemEvents` to `*bool` and omitted from following structs when empty + * `GetSiemSettingResponse` + * `RemoveSiemSettingsRequest` + * `RemoveSiemSettingsResponse` + * `UpdateSiemSettingsRequest` + * `UpdateSiemSettingsResponse` + * General diff --git a/pkg/appsec/siem_settings.go b/pkg/appsec/siem_settings.go index cf63c4af..5eb585bb 100644 --- a/pkg/appsec/siem_settings.go +++ b/pkg/appsec/siem_settings.go @@ -61,7 +61,7 @@ type ( GetSiemSettingResponse struct { EnableForAllPolicies bool `json:"enableForAllPolicies"` EnableSiem bool `json:"enableSiem"` - EnabledBotmanSiemEvents bool `json:"enabledBotmanSiemEvents"` + EnabledBotmanSiemEvents *bool `json:"enabledBotmanSiemEvents"` SiemDefinitionID int `json:"siemDefinitionId"` FirewallPolicyIds []string `json:"firewallPolicyIds"` Exceptions []Exception `json:"exceptions"` @@ -73,7 +73,7 @@ type ( Version int `json:"-"` EnableForAllPolicies bool `json:"enableForAllPolicies"` EnableSiem bool `json:"enableSiem"` - EnabledBotmanSiemEvents bool `json:"enabledBotmanSiemEvents"` + EnabledBotmanSiemEvents *bool `json:"enabledBotmanSiemEvents,omitempty"` SiemDefinitionID int `json:"siemDefinitionId"` FirewallPolicyIds []string `json:"firewallPolicyIds"` Exceptions []Exception `json:"exceptions,omitempty"` @@ -83,7 +83,7 @@ type ( UpdateSiemSettingsResponse struct { EnableForAllPolicies bool `json:"enableForAllPolicies"` EnableSiem bool `json:"enableSiem"` - EnabledBotmanSiemEvents bool `json:"enabledBotmanSiemEvents"` + EnabledBotmanSiemEvents *bool `json:"enabledBotmanSiemEvents"` SiemDefinitionID int `json:"siemDefinitionId"` FirewallPolicyIds []string `json:"firewallPolicyIds"` Exceptions []Exception `json:"exceptions"` @@ -96,7 +96,7 @@ type ( Version int `json:"-"` EnableForAllPolicies bool `json:"-"` EnableSiem bool `json:"enableSiem"` - EnabledBotmanSiemEvents bool `json:"-"` + EnabledBotmanSiemEvents *bool `json:"-"` SiemDefinitionID int `json:"-"` FirewallPolicyIds []string `json:"-"` } @@ -106,7 +106,7 @@ type ( RemoveSiemSettingsResponse struct { EnableForAllPolicies bool `json:"enableForAllPolicies"` EnableSiem bool `json:"enableSiem"` - EnabledBotmanSiemEvents bool `json:"enabledBotmanSiemEvents"` + EnabledBotmanSiemEvents *bool `json:"enabledBotmanSiemEvents"` SiemDefinitionID int `json:"siemDefinitionId"` FirewallPolicyIds []string `json:"firewallPolicyIds"` } diff --git a/pkg/appsec/siem_settings_test.go b/pkg/appsec/siem_settings_test.go index 26e1239b..4a0e205f 100644 --- a/pkg/appsec/siem_settings_test.go +++ b/pkg/appsec/siem_settings_test.go @@ -9,6 +9,7 @@ import ( "regexp" "testing" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/ptr" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -167,11 +168,16 @@ func TestAppSec_GetSiemSettings(t *testing.T) { // Test Update SiemSettings. func TestAppSec_UpdateSiemSettings(t *testing.T) { result := UpdateSiemSettingsResponse{} + resultWithoutEnabledBotman := UpdateSiemSettingsResponse{} respData := compactJSON(loadFixtureBytes("testdata/TestSiemSettings/SiemSettings.json")) err := json.Unmarshal([]byte(respData), &result) require.NoError(t, err) + respDataWithoutEnableBotman := compactJSON(loadFixtureBytes("testdata/TestSiemSettings/SiemSettingsWithoutEnabledBotmanSiem.json")) + err = json.Unmarshal([]byte(respDataWithoutEnableBotman), &resultWithoutEnabledBotman) + require.NoError(t, err) + req := UpdateSiemSettingsRequest{} reqData := compactJSON(loadFixtureBytes("testdata/TestSiemSettings/SiemSettings.json")) @@ -189,6 +195,35 @@ func TestAppSec_UpdateSiemSettings(t *testing.T) { errors *regexp.Regexp }{ "200 Success": { + params: UpdateSiemSettingsRequest{ + ConfigID: 43253, + Version: 15, + EnableSiem: true, + EnabledBotmanSiemEvents: ptr.To(false), + Exceptions: []Exception{ + { + ActionTypes: []string{"*"}, + Protection: "botmanagement", + }, + { + ActionTypes: []string{"deny"}, + Protection: "ipgeo", + }, + { + ActionTypes: []string{"alert"}, + Protection: "rate", + }, + }, + }, + headers: http.Header{ + "Content-Type": []string{"application/json;charset=UTF-8"}, + }, + responseStatus: http.StatusCreated, + responseBody: respData, + expectedResponse: &result, + expectedPath: "/appsec/v1/configs/43253/versions/15/siem", + }, + "200 Success without EnabledBotmanSiemEvents": { params: UpdateSiemSettingsRequest{ ConfigID: 43253, Version: 15, @@ -212,8 +247,8 @@ func TestAppSec_UpdateSiemSettings(t *testing.T) { "Content-Type": []string{"application/json;charset=UTF-8"}, }, responseStatus: http.StatusCreated, - responseBody: respData, - expectedResponse: &result, + responseBody: respDataWithoutEnableBotman, + expectedResponse: &resultWithoutEnabledBotman, expectedPath: "/appsec/v1/configs/43253/versions/15/siem", }, "400 Bad Request action types": { diff --git a/pkg/appsec/testdata/TestSiemSettings/SiemSettingsWithoutEnabledBotmanSiem.json b/pkg/appsec/testdata/TestSiemSettings/SiemSettingsWithoutEnabledBotmanSiem.json new file mode 100644 index 00000000..d7fde64f --- /dev/null +++ b/pkg/appsec/testdata/TestSiemSettings/SiemSettingsWithoutEnabledBotmanSiem.json @@ -0,0 +1,24 @@ +{ + "enableForAllPolicies": true, + "enableSiem": true, + "siemDefinitionId": 1, + "exceptions":[ + { + "actionTypes": [ + "*" + ], + "protection": "botmanagement" + }, + { + "actionTypes": [ + "alert" + ], + "protection": "ipgeo" + }, + { + "actionTypes": [ + "alert" + ], + "protection": "rate" + }] +} \ No newline at end of file From 3d7595bf37ec371c07ba7bcc4a98318f7e932644 Mon Sep 17 00:00:00 2001 From: Michal Wojcik Date: Tue, 12 Nov 2024 09:08:45 +0000 Subject: [PATCH 10/12] DXE-4323 Reconcile edgegrid-golang with API attributes --- CHANGELOG.md | 9 +- pkg/dns/tsig_test.go | 16 +-- pkg/dns/zone.go | 123 +++++++++++-------- pkg/dns/zone_test.go | 257 +++++++++++++++++++++++++++++++++++---- pkg/dns/zonebulk_test.go | 10 ++ 5 files changed, 328 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 889f089e..842bf090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,8 +68,13 @@ - - +* DNS + * Added support for `OutboundZoneTransfer` field in requests and responses for these methods: + * `CreateBulkZones` + * `CreateZone` + * `GetZone` + * `ListZones` + * `UpdateZone` diff --git a/pkg/dns/tsig_test.go b/pkg/dns/tsig_test.go index e5c491f4..19b02089 100644 --- a/pkg/dns/tsig_test.go +++ b/pkg/dns/tsig_test.go @@ -113,7 +113,7 @@ func TestDNS_GetTSIGKeyZones(t *testing.T) { TsigKey: &TSIGKey{ Name: "example.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, }, responseStatus: http.StatusOK, @@ -134,7 +134,7 @@ func TestDNS_GetTSIGKeyZones(t *testing.T) { TsigKey: &TSIGKey{ Name: "example.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, }, responseStatus: http.StatusInternalServerError, @@ -262,7 +262,7 @@ func TestDNS_TSIGKeyBulkUpdate(t *testing.T) { Key: &TSIGKey{ Name: "brook.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, Zones: []string{"brook.com", "river.com"}, }, @@ -279,7 +279,7 @@ func TestDNS_TSIGKeyBulkUpdate(t *testing.T) { Key: &TSIGKey{ Name: "brook.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, Zones: []string{"brook.com", "river.com"}, }, @@ -342,7 +342,7 @@ func TestDNS_GetTSIGKey(t *testing.T) { { "name": "example.com.akamai.com.", "algorithm": "hmac-sha512", - "secret": "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + "secret": "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", "zonesCount": 7 }`, expectedPath: "/config-dns/v2/zones/example.com/key", @@ -350,7 +350,7 @@ func TestDNS_GetTSIGKey(t *testing.T) { TSIGKey: TSIGKey{ Name: "example.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, ZoneCount: 7, }, @@ -472,7 +472,7 @@ func TestDNS_UpdateTSIGKey(t *testing.T) { TsigKey: &TSIGKey{ Name: "example.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, Zone: "example.com", }, @@ -484,7 +484,7 @@ func TestDNS_UpdateTSIGKey(t *testing.T) { TsigKey: &TSIGKey{ Name: "example.com.akamai.com.", Algorithm: "hmac-sha512", - Secret: "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", }, Zone: "example.com", }, diff --git a/pkg/dns/zone.go b/pkg/dns/zone.go index d5efd967..0e206e02 100644 --- a/pkg/dns/zone.go +++ b/pkg/dns/zone.go @@ -9,6 +9,7 @@ import ( "io" "io/ioutil" "net/http" + "net/url" "reflect" "strconv" "strings" @@ -33,36 +34,46 @@ type ( // ZoneCreate contains zone create request ZoneCreate struct { - Zone string `json:"zone"` - Type string `json:"type"` - Masters []string `json:"masters,omitempty"` - Comment string `json:"comment,omitempty"` - SignAndServe bool `json:"signAndServe"` - SignAndServeAlgorithm string `json:"signAndServeAlgorithm,omitempty"` - TSIGKey *TSIGKey `json:"tsigKey,omitempty"` - Target string `json:"target,omitempty"` - EndCustomerID string `json:"endCustomerId,omitempty"` - ContractID string `json:"contractId,omitempty"` + Zone string `json:"zone"` + Type string `json:"type"` + Masters []string `json:"masters,omitempty"` + Comment string `json:"comment,omitempty"` + SignAndServe bool `json:"signAndServe"` + SignAndServeAlgorithm string `json:"signAndServeAlgorithm,omitempty"` + TSIGKey *TSIGKey `json:"tsigKey,omitempty"` + Target string `json:"target,omitempty"` + EndCustomerID string `json:"endCustomerId,omitempty"` + ContractID string `json:"contractId,omitempty"` + OutboundZoneTransfer *OutboundZoneTransfer `json:"outboundZoneTransfer,omitempty"` + } + + // OutboundZoneTransfer contains OutboundZoneTransfer request parameters + OutboundZoneTransfer struct { + ACL []string `json:"ACL"` + Enabled bool `json:"enabled"` + NotifyTargets []string `json:"notifyTargets"` + TSIGKey *TSIGKey `json:"tsigKey,omitempty"` } // ZoneResponse contains zone create response ZoneResponse struct { - Zone string `json:"zone,omitempty"` - Type string `json:"type,omitempty"` - Masters []string `json:"masters,omitempty"` - Comment string `json:"comment,omitempty"` - SignAndServe bool `json:"signAndServe"` - SignAndServeAlgorithm string `json:"signAndServeAlgorithm,omitempty"` - TSIGKey *TSIGKey `json:"tsigKey,omitempty"` - Target string `json:"target,omitempty"` - EndCustomerID string `json:"endCustomerId,omitempty"` - ContractID string `json:"contractId,omitempty"` - AliasCount int64 `json:"aliasCount,omitempty"` - ActivationState string `json:"activationState,omitempty"` - LastActivationDate string `json:"lastActivationDate,omitempty"` - LastModifiedBy string `json:"lastModifiedBy,omitempty"` - LastModifiedDate string `json:"lastModifiedDate,omitempty"` - VersionID string `json:"versionId,omitempty"` + Zone string `json:"zone,omitempty"` + Type string `json:"type,omitempty"` + Masters []string `json:"masters,omitempty"` + Comment string `json:"comment,omitempty"` + SignAndServe bool `json:"signAndServe"` + SignAndServeAlgorithm string `json:"signAndServeAlgorithm,omitempty"` + TSIGKey *TSIGKey `json:"tsigKey,omitempty"` + Target string `json:"target,omitempty"` + EndCustomerID string `json:"endCustomerId,omitempty"` + ContractID string `json:"contractId,omitempty"` + AliasCount int64 `json:"aliasCount,omitempty"` + ActivationState string `json:"activationState,omitempty"` + LastActivationDate string `json:"lastActivationDate,omitempty"` + LastModifiedBy string `json:"lastModifiedBy,omitempty"` + LastModifiedDate string `json:"lastModifiedDate,omitempty"` + VersionID string `json:"versionId,omitempty"` + OutboundZoneTransfer *OutboundZoneTransfer `json:"outboundZoneTransfer,omitempty"` } // ListMetadata contains metadata for List Zones request @@ -291,7 +302,8 @@ var zoneStructMap = map[string]string{ "TSIGKey": "tsigKey", "Target": "target", "EndCustomerID": "endCustomerId", - "ContractId": "contractId"} + "OutboundZoneTransfer": "outboundZoneTransfer", + "ContractID": "contractId"} // Util to convert struct to http request body, eg. io.reader func convertStructToReqBody(srcStruct interface{}) (io.Reader, error) { @@ -490,27 +502,28 @@ func (d *dns) CreateZone(ctx context.Context, params CreateZoneRequest) error { return err } - zoneMap := filterZoneCreate(params.CreateZone) - - var zoneResponse ZoneResponse - zoneURL := "/config-dns/v2/zones/?contractId=" + params.ZoneQueryString.Contract - if len(params.ZoneQueryString.Group) > 0 { - zoneURL += "&gid=" + params.ZoneQueryString.Group + uri, err := url.Parse("/config-dns/v2/zones") + if err != nil { + return fmt.Errorf("%w: failed to parse uri: %s", ErrCreateZone, err) } - reqBody, err := convertStructToReqBody(zoneMap) - if err != nil { - return fmt.Errorf("failed to generate request body: %w", err) + q := uri.Query() + q.Add("contractId", params.ZoneQueryString.Contract) + if params.ZoneQueryString.Group != "" { + q.Add("gid", params.ZoneQueryString.Group) } + uri.RawQuery = q.Encode() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, zoneURL, reqBody) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri.String(), nil) if err != nil { - return fmt.Errorf("failed to create Zone Create request: %w", err) + return fmt.Errorf("failed to create zone create request: %w", err) } - resp, err := d.Exec(req, &zoneResponse) + zoneMap := filterZoneCreate(params.CreateZone) + var zoneResponse ZoneResponse + resp, err := d.Exec(req, &zoneResponse, zoneMap) if err != nil { - return fmt.Errorf("Create Zone request failed: %w", err) + return fmt.Errorf("create zone request failed: %w", err) } defer session.CloseResponseBody(resp) @@ -520,9 +533,9 @@ func (d *dns) CreateZone(ctx context.Context, params CreateZoneRequest) error { if strings.ToUpper(params.CreateZone.Type) == "PRIMARY" { // Timing issue with Create immediately followed by SaveChangelist - for _, clear := range params.ClearConn { + for _, shouldClear := range params.ClearConn { // should only be one entry - if clear { + if shouldClear { logger.Info("Clearing Idle Connections") d.Client().CloseIdleConnections() } @@ -554,7 +567,7 @@ func (d *dns) SaveChangeList(ctx context.Context, params SaveChangeListRequest) return fmt.Errorf("failed to generate request body: %w", err) } - postURL := fmt.Sprintf("/config-dns/v2/changelists/?zone=%s", params.Zone) + postURL := fmt.Sprintf("/config-dns/v2/changelists?zone=%s", params.Zone) req, err := http.NewRequestWithContext(ctx, http.MethodPost, postURL, reqBody) if err != nil { return fmt.Errorf("failed to create SaveChangeList request: %w", err) @@ -632,21 +645,17 @@ func (d *dns) UpdateZone(ctx context.Context, params UpdateZoneRequest) error { } zoneMap := filterZoneCreate(params.CreateZone) - reqBody, err := convertStructToReqBody(zoneMap) - if err != nil { - return fmt.Errorf("failed to generate request body: %w", err) - } putURL := fmt.Sprintf("/config-dns/v2/zones/%s", params.CreateZone.Zone) - req, err := http.NewRequestWithContext(ctx, http.MethodPut, putURL, reqBody) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, putURL, nil) if err != nil { return fmt.Errorf("failed to create Get Update request: %w", err) } var result ZoneResponse - resp, err := d.Exec(req, &result) + resp, err := d.Exec(req, &result, zoneMap) if err != nil { - return fmt.Errorf("Zone Update request failed: %w", err) + return fmt.Errorf("zone update request failed: %w", err) } defer session.CloseResponseBody(resp) @@ -670,7 +679,7 @@ func filterZoneCreate(zone *ZoneCreate) map[string]interface{} { if zoneType == "ALIAS" { filteredZone[varLower] = varValue } - case "TsigKey": + case "TSIGKey": if zoneType == "SECONDARY" { filteredZone[varLower] = varValue } @@ -686,6 +695,18 @@ func filterZoneCreate(zone *ZoneCreate) map[string]interface{} { if zoneType != "ALIAS" { filteredZone[varLower] = varValue } + case "OutboundZoneTransfer": + // this is workaround for the check if value is not nil to avoid adding empty entry + switch v := varValue.(type) { + case *OutboundZoneTransfer: + { + if v != nil { + filteredZone[varLower] = varValue + } + } + default: + filteredZone[varLower] = varValue + } default: filteredZone[varLower] = varValue } diff --git a/pkg/dns/zone_test.go b/pkg/dns/zone_test.go index b08ff4cd..e4070d24 100644 --- a/pkg/dns/zone_test.go +++ b/pkg/dns/zone_test.go @@ -1,6 +1,7 @@ package dns import ( + "bytes" "context" "errors" "io/ioutil" @@ -30,7 +31,7 @@ func TestDNS_ListZones(t *testing.T) { ContractIDs: "1-1ACYUM", Search: "org", SortBy: "-contractId,zone", - Types: "primary,alias", + Types: "secondary,alias", Page: 1, PageSize: 25, }, @@ -53,18 +54,33 @@ func TestDNS_ListZones(t *testing.T) { { "contractId": "1-2ABCDE", "zone": "example.com", - "type": "primary", + "type": "secondary", "aliasCount": 1, "signAndServe": false, "versionId": "ae02357c-693d-4ac4-b33d-8352d9b7c786", "lastModifiedDate": "2017-01-03T12:00:00Z", "lastModifiedBy": "user28", "lastActivationDate": "2017-01-03T12:00:00Z", - "activationState": "ACTIVE" + "activationState": "ACTIVE", + "masters": ["1.1.1.1"], + "outboundZoneTransfer": { + "ACL": [ + "192.0.2.156/24" + ], + "enabled": true, + "notifyTargets": [ + "192.0.2.192" + ], + "tsigKey": { + "algorithm": "hmac-sha1", + "name": "other.com.akamai.com3", + "secret": "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==" + } + } } ] }`, - expectedPath: "/config-dns/v2/zones?contractIds=1-1ACYUM&search=org&sortBy=-contractId%2Czone&types=primary%2Calias&page=1&pageSize=25&showAll=false", + expectedPath: "/config-dns/v2/zones?contractIds=1-1ACYUM&page=1&pageSize=25&search=org&showAll=false&sortBy=-contractId%2Czone&types=secondary%2Calias", expectedResponse: &ZoneListResponse{ Metadata: &ListMetadata{ Page: 1, @@ -77,7 +93,7 @@ func TestDNS_ListZones(t *testing.T) { { ContractID: "1-2ABCDE", Zone: "example.com", - Type: "primary", + Type: "secondary", AliasCount: 1, SignAndServe: false, VersionID: "ae02357c-693d-4ac4-b33d-8352d9b7c786", @@ -85,6 +101,17 @@ func TestDNS_ListZones(t *testing.T) { LastModifiedBy: "user28", LastActivationDate: "2017-01-03T12:00:00Z", ActivationState: "ACTIVE", + Masters: []string{"1.1.1.1"}, + OutboundZoneTransfer: &OutboundZoneTransfer{ + ACL: []string{"192.0.2.156/24"}, + Enabled: true, + NotifyTargets: []string{"192.0.2.192"}, + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com3", + Algorithm: "hmac-sha1", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + }, + }, }, }, }, @@ -106,7 +133,7 @@ func TestDNS_ListZones(t *testing.T) { "detail": "Error fetching authorities", "status": 500 }`, - expectedPath: "/config-dns/v2/zones?contractIds=1-1ACYUM&search=org&sortBy=-contractId%2Czone&types=primary%2Calias&page=1&pageSize=25&showAll=false", + expectedPath: "/config-dns/v2/zones?contractIds=1-1ACYUM&page=1&pageSize=25&search=org&showAll=false&sortBy=-contractId%2Czone&types=primary%2Calias", withError: &Error{ Type: "internal_error", Title: "Internal Server Error", @@ -119,6 +146,7 @@ func TestDNS_ListZones(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodGet, r.Method) w.WriteHeader(test.responseStatus) _, err := w.Write([]byte(test.responseBody)) @@ -315,7 +343,7 @@ func TestDNS_GetZone(t *testing.T) { { "contractId": "1-2ABCDE", "zone": "example.com", - "type": "primary", + "type": "secondary", "aliasCount": 1, "signAndServe": true, "signAndServeAlgorithm": "RSA_SHA256", @@ -323,13 +351,28 @@ func TestDNS_GetZone(t *testing.T) { "lastModifiedDate": "2017-01-03T12:00:00Z", "lastModifiedBy": "user28", "lastActivationDate": "2017-01-03T12:00:00Z", - "activationState": "ACTIVE" + "activationState": "ACTIVE", + "masters": ["1.1.1.1"], + "outboundZoneTransfer": { + "ACL": [ + "192.0.2.156/24" + ], + "enabled": true, + "notifyTargets": [ + "192.0.2.192" + ], + "tsigKey": { + "algorithm": "hmac-sha1", + "name": "other.com.akamai.com3", + "secret": "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==" + } + } }`, expectedPath: "/config-dns/v2/zones/example.com", expectedResponse: &GetZoneResponse{ ContractID: "1-2ABCDE", Zone: "example.com", - Type: "primary", + Type: "secondary", AliasCount: 1, SignAndServe: true, SignAndServeAlgorithm: "RSA_SHA256", @@ -338,6 +381,17 @@ func TestDNS_GetZone(t *testing.T) { LastModifiedBy: "user28", LastActivationDate: "2017-01-03T12:00:00Z", ActivationState: "ACTIVE", + Masters: []string{"1.1.1.1"}, + OutboundZoneTransfer: &OutboundZoneTransfer{ + ACL: []string{"192.0.2.156/24"}, + Enabled: true, + NotifyTargets: []string{"192.0.2.192"}, + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com3", + Algorithm: "hmac-sha1", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + }, + }, }, }, "500 internal server error": { @@ -365,7 +419,7 @@ func TestDNS_GetZone(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - //assert.Equal(t, test.expectedPath, r.URL.String()) + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodGet, r.Method) w.WriteHeader(test.responseStatus) _, err := w.Write([]byte(test.responseBody)) @@ -438,7 +492,7 @@ www.example.com. 300 IN A 10.0.0.2"`, for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - //assert.Equal(t, test.expectedPath, r.URL.String()) + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodGet, r.Method) w.WriteHeader(test.responseStatus) _, err := w.Write([]byte(test.responseBody)) @@ -511,6 +565,7 @@ www.example.com. 300 IN A 10.0.0.2"`, for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodPost, r.Method) w.WriteHeader(test.responseStatus) if len(test.responseBody) > 0 { @@ -551,7 +606,7 @@ func TestDNS_GetChangeList(t *testing.T) { "lastModifiedDate": "2017-02-01T12:00:12.524Z", "stale": false }`, - expectedPath: "/config-dns/v2/zones/example.com", + expectedPath: "/config-dns/v2/changelists/example.com", expectedResponse: &GetChangeListResponse{ Zone: "example.com", ChangeTag: "476754f4-d605-479f-853b-db854d7254fa", @@ -572,7 +627,7 @@ func TestDNS_GetChangeList(t *testing.T) { "detail": "Error fetching authorities", "status": 500 }`, - expectedPath: "/config-dns/v2/zones/example.com", + expectedPath: "/config-dns/v2/changelists/example.com", withError: &Error{ Type: "internal_error", Title: "Internal Server Error", @@ -585,7 +640,7 @@ func TestDNS_GetChangeList(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - //assert.Equal(t, test.expectedPath, r.URL.String()) + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodGet, r.Method) w.WriteHeader(test.responseStatus) _, err := w.Write([]byte(test.responseBody)) @@ -684,19 +739,62 @@ func TestDNS_CreateZone(t *testing.T) { tests := map[string]struct { params CreateZoneRequest responseStatus int + requestBody string responseBody string expectedPath string withError error }{ - "201 Created": { + "201 Created Primary": { params: CreateZoneRequest{ CreateZone: &ZoneCreate{ Zone: "example.com", ContractID: "1-2ABCDE", Type: "primary", }, + ZoneQueryString: ZoneQueryString{ + Contract: "1-2ABCDE", + }, }, responseStatus: http.StatusCreated, + requestBody: `{"comment":"","contractId":"1-2ABCDE","endCustomerId":"","signAndServe":false,"signAndServeAlgorithm":"","type":"primary","zone":"example.com"}`, + responseBody: ` + { + "contractId": "1-2ABCDE", + "zone": "other.com", + "type": "primary", + "aliasCount": 1, + "signAndServe": false, + "comment": "Initial add", + "versionId": "7949b2db-ac43-4773-a3ec-dc93202142fd", + "lastModifiedDate": "2016-12-11T03:21:00Z", + "lastModifiedBy": "user31", + "lastActivationDate": "2017-01-03T12:00:00Z", + "activationState": "ERROR", + "masters": [ + "1.2.3.4", + "1.2.3.5" + ] + }`, + expectedPath: "/config-dns/v2/zones?contractId=1-2ABCDE", + }, + "201 Created Secondary": { + params: CreateZoneRequest{ + CreateZone: &ZoneCreate{ + Zone: "example.com", + ContractID: "1-2ABCDE", + Type: "secondary", + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com.", + Algorithm: "hmac-sha512", + Secret: "fakeSecretajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo", + }, + }, + ZoneQueryString: ZoneQueryString{ + Contract: "1-2ABCDE", + }, + }, + responseStatus: http.StatusCreated, + requestBody: `{"comment":"","contractId":"1-2ABCDE","endCustomerId":"","masters":null,"signAndServe":false,"signAndServeAlgorithm":"","tsigKey":{"name":"other.com.akamai.com.","algorithm":"hmac-sha512","secret":"fakeSecretajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo"},"type":"secondary","zone":"example.com"}`, responseBody: ` { "contractId": "1-2ABCDE", @@ -717,7 +815,7 @@ func TestDNS_CreateZone(t *testing.T) { "tsigKey": { "name": "other.com.akamai.com.", "algorithm": "hmac-sha512", - "secret": "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==" + "secret": "fakeSecretajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo" } }`, expectedPath: "/config-dns/v2/zones?contractId=1-2ABCDE", @@ -729,6 +827,9 @@ func TestDNS_CreateZone(t *testing.T) { ContractID: "1-2ABCDE", Type: "primary", }, + ZoneQueryString: ZoneQueryString{ + Contract: "1-2ABCDE", + }, }, responseStatus: http.StatusInternalServerError, responseBody: ` @@ -751,7 +852,15 @@ func TestDNS_CreateZone(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodPost, r.Method) + if test.requestBody != "" { + buf := new(bytes.Buffer) + _, err := buf.ReadFrom(r.Body) + assert.NoError(t, err) + req := buf.String() + assert.Equal(t, test.requestBody, req) + } w.WriteHeader(test.responseStatus) if len(test.responseBody) > 0 { _, err := w.Write([]byte(test.responseBody)) @@ -817,6 +926,7 @@ func TestDNS_SaveChangelist(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodPost, r.Method) w.WriteHeader(test.responseStatus) if len(test.responseBody) > 0 { @@ -850,7 +960,7 @@ func TestDNS_SubmitChangelist(t *testing.T) { Type: "primary", }, responseStatus: http.StatusNoContent, - expectedPath: "/config-dns/v2/changelists?zone=example.com", + expectedPath: "/config-dns/v2/changelists/example.com/submit", }, "500 internal server error": { params: SubmitChangeListRequest{ @@ -866,7 +976,7 @@ func TestDNS_SubmitChangelist(t *testing.T) { "detail": "Error creating zone", "status": 500 }`, - expectedPath: "/config-dns/v2/changelists?zone=example.com", + expectedPath: "/config-dns/v2/changelists/example.com/submit", withError: &Error{ Type: "internal_error", Title: "Internal Server Error", @@ -879,6 +989,7 @@ func TestDNS_SubmitChangelist(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodPost, r.Method) w.WriteHeader(test.responseStatus) if len(test.responseBody) > 0 { @@ -901,18 +1012,90 @@ func TestDNS_UpdateZone(t *testing.T) { tests := map[string]struct { params UpdateZoneRequest responseStatus int + requestBody string responseBody string expectedPath string withError error }{ - "200 OK": { + "200 OK primary": { params: UpdateZoneRequest{ CreateZone: &ZoneCreate{ Zone: "example.com", ContractID: "1-2ABCDE", Type: "primary", + OutboundZoneTransfer: &OutboundZoneTransfer{ + ACL: []string{"192.0.2.156/24"}, + Enabled: true, + NotifyTargets: []string{"192.0.2.192"}, + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com", + Algorithm: "hmac-sha1", + Secret: "fakeW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + }, + }, }, }, + requestBody: `{"comment":"","contractId":"1-2ABCDE","endCustomerId":"","outboundZoneTransfer":{"ACL":["192.0.2.156/24"],"enabled":true,"notifyTargets":["192.0.2.192"],"tsigKey":{"name":"other.com.akamai.com","algorithm":"hmac-sha1","secret":"fakeW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw=="}},"signAndServe":false,"signAndServeAlgorithm":"","type":"primary","zone":"example.com"}`, + responseStatus: http.StatusOK, + responseBody: ` + { + "contractId": "1-2ABCDE", + "zone": "other.com", + "type": "primary", + "aliasCount": 1, + "signAndServe": false, + "comment": "Initial add", + "versionId": "7949b2db-ac43-4773-a3ec-dc93202142fd", + "lastModifiedDate": "2016-12-11T03:21:00Z", + "lastModifiedBy": "user31", + "lastActivationDate": "2017-01-03T12:00:00Z", + "activationState": "ERROR", + "masters": [ + "1.2.3.4", + "1.2.3.5" + ], + "outboundZoneTransfer": { + "ACL": [ + "192.0.2.156/24" + ], + "enabled": true, + "notifyTargets": [ + "192.0.2.192" + ], + "tsigKey": { + "algorithm": "hmac-sha1", + "name": "other.com.akamai.com3", + "secret": "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==" + } + } + }`, + expectedPath: "/config-dns/v2/zones/example.com", + }, + "200 OK secondary": { + params: UpdateZoneRequest{ + CreateZone: &ZoneCreate{ + Zone: "example.com", + ContractID: "1-2ABCDE", + Type: "secondary", + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com.", + Algorithm: "hmac-sha512", + Secret: "fakeSecretajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo", + }, + Masters: []string{"1.2.3.4", "1.2.3.5"}, + OutboundZoneTransfer: &OutboundZoneTransfer{ + ACL: []string{"192.0.2.156/24"}, + Enabled: true, + NotifyTargets: []string{"192.0.2.192"}, + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com", + Algorithm: "hmac-sha1", + Secret: "fakeW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + }, + }, + }, + }, + requestBody: `{"comment":"","contractId":"1-2ABCDE","endCustomerId":"","masters":["1.2.3.4","1.2.3.5"],"outboundZoneTransfer":{"ACL":["192.0.2.156/24"],"enabled":true,"notifyTargets":["192.0.2.192"],"tsigKey":{"name":"other.com.akamai.com","algorithm":"hmac-sha1","secret":"fakeW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw=="}},"signAndServe":false,"signAndServeAlgorithm":"","tsigKey":{"name":"other.com.akamai.com.","algorithm":"hmac-sha512","secret":"fakeSecretajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo"},"type":"secondary","zone":"example.com"}`, responseStatus: http.StatusOK, responseBody: ` { @@ -934,10 +1117,24 @@ func TestDNS_UpdateZone(t *testing.T) { "tsigKey": { "name": "other.com.akamai.com.", "algorithm": "hmac-sha512", - "secret": "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==" + "secret": "fakeSecretajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo" + }, + "outboundZoneTransfer": { + "ACL": [ + "192.0.2.156/24" + ], + "enabled": true, + "notifyTargets": [ + "192.0.2.192" + ], + "tsigKey": { + "algorithm": "hmac-sha1", + "name": "other.com.akamai.com3", + "secret": "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==" + } } }`, - expectedPath: "/config-dns/v2/zones?contractId=1-2ABCDE", + expectedPath: "/config-dns/v2/zones/example.com", }, "500 internal server error": { params: UpdateZoneRequest{ @@ -955,7 +1152,7 @@ func TestDNS_UpdateZone(t *testing.T) { "detail": "Error creating zone", "status": 500 }`, - expectedPath: "/config-dns/v2/zones?contractId=1-2ABCDE", + expectedPath: "/config-dns/v2/zones/example.com", withError: &Error{ Type: "internal_error", Title: "Internal Server Error", @@ -968,7 +1165,15 @@ func TestDNS_UpdateZone(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodPut, r.Method) + if test.requestBody != "" { + buf := new(bytes.Buffer) + _, err := buf.ReadFrom(r.Body) + assert.NoError(t, err) + req := buf.String() + assert.Equal(t, test.requestBody, req) + } w.WriteHeader(test.responseStatus) if len(test.responseBody) > 0 { _, err := w.Write([]byte(test.responseBody)) @@ -1040,7 +1245,7 @@ func TestDNS_GetZoneNames(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - //assert.Equal(t, test.expectedPath, r.URL.String()) + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodGet, r.Method) w.WriteHeader(test.responseStatus) _, err := w.Write([]byte(test.responseBody)) @@ -1070,7 +1275,7 @@ func TestDNS_GetZoneNameTypes(t *testing.T) { "200 OK": { params: GetZoneNameTypesRequest{ Zone: "example.com", - ZoneName: "names", + ZoneName: "www.example.com", }, responseStatus: http.StatusOK, responseBody: ` @@ -1089,7 +1294,7 @@ func TestDNS_GetZoneNameTypes(t *testing.T) { "500 internal server error": { params: GetZoneNameTypesRequest{ Zone: "example.com", - ZoneName: "names", + ZoneName: "www.example.com", }, responseStatus: http.StatusInternalServerError, responseBody: ` @@ -1112,7 +1317,7 @@ func TestDNS_GetZoneNameTypes(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - //assert.Equal(t, test.expectedPath, r.URL.String()) + assert.Equal(t, test.expectedPath, r.URL.String()) assert.Equal(t, http.MethodGet, r.Method) w.WriteHeader(test.responseStatus) _, err := w.Write([]byte(test.responseBody)) diff --git a/pkg/dns/zonebulk_test.go b/pkg/dns/zonebulk_test.go index 394b6771..359982a4 100644 --- a/pkg/dns/zonebulk_test.go +++ b/pkg/dns/zonebulk_test.go @@ -186,6 +186,16 @@ func TestDNS_CreateBulkZones(t *testing.T) { Type: "secondary", Comment: "testing bulk operations", Masters: []string{"1.2.3.4", "1.2.3.10"}, + OutboundZoneTransfer: &OutboundZoneTransfer{ + ACL: []string{"192.0.2.156/24"}, + Enabled: true, + NotifyTargets: []string{"192.0.2.192"}, + TSIGKey: &TSIGKey{ + Name: "other.com.akamai.com3", + Algorithm: "hmac-sha1", + Secret: "fakeR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLw==", + }, + }, }, { Zone: "two.testbulk.net", From a154eebaa5736aa8fe641dea439e12f4ef910436 Mon Sep 17 00:00:00 2001 From: Wojciech Zagrajczuk Date: Tue, 12 Nov 2024 09:39:00 +0000 Subject: [PATCH 11/12] DXE-4340 Update changelog for release --- CHANGELOG.md | 116 +++++---------------------------------------------- 1 file changed, 10 insertions(+), 106 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 842bf090..f420ae19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,72 +1,28 @@ # RELEASE NOTES -## X.X.X (X X, X) - -#### BREAKING CHANGES: - - - - - - - - - - - - - - - - - - - - +## 9.1.0 (Nov 14, 2024) +#### FEATURES/ENHANCEMENTS: +* General + * Added a configurable `WithRetries` option for creating new sessions with global GET retries. It can be configured with these parameters: + * `retryMax` - The maximum number of API request retries. + * `retryWaitMin` - The minimum wait time in `time.Duration` between API requests retries. + * `retryWaitMax` - The maximum wait time in `time.Duration` between API requests retries. + * `excludedEndpoints` - The list of path expressions defining endpoints which should be excluded from the retry feature. + * Added logic responsible for closing the response body in each method. -#### FEATURES/ENHANCEMENTS: * APPSEC * Added following content protection fields to `GetExportConfigurationResponse` under `BotManagement` section * `ContentProtectionRules` * `ContentProtectionRuleSequence` * `ContentProtectionJavaScriptInjectionRules` - * Changed `EnabledBotmanSiemEvents` to `*bool` and omitted from following structs when empty * `GetSiemSettingResponse` * `RemoveSiemSettingsRequest` * `RemoveSiemSettingsResponse` * `UpdateSiemSettingsRequest` * `UpdateSiemSettingsResponse` - - - -* General - * Added a configurable `WithRetries` option for creating new sessions with global GET retries. It can be configured with parameters: - * `retryMax` - The maximum number of API request retries. - * `retryWaitMin` - The minimum wait time in `time.Duration` between API requests retries. - * `retryWaitMax` - The maximum wait time in `time.Duration` between API requests retries. - * `excludedEndpoints` - List of path expressions defining endpoints which should be excluded from retry feature - - - - - - - -* General - * Added logic responsible for closing the response body in each method. - - - - - - - - - - * DNS * Added support for `OutboundZoneTransfer` field in requests and responses for these methods: @@ -76,66 +32,14 @@ * `ListZones` * `UpdateZone` - - - - - - - - - - - - - - - - #### BUG FIXES: * APPSEC - * Fixed SIEM exception validation for `Exceptions` field - - - - - - + * Fixed SIEM exception validation for the `Exceptions` field. * Cloud Access * Added custom error `ErrAccessKeyNotFound` to easier verify if provided access key does not exist. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## 9.0.0 (Oct 3, 2024) #### BREAKING CHANGES: From b1adec18efad011101934c2970b9355e7234385c Mon Sep 17 00:00:00 2001 From: Malgorzata Niemczyk Date: Thu, 14 Nov 2024 09:08:26 +0000 Subject: [PATCH 12/12] DXISSUE-41 readme update and examples Merge in DEVEXP/akamaiopen-edgegrid-golang from feature/DXISSUE-41-readme-update-and-examples to develop --- CHANGELOG.md | 893 +++++++++--------- LICENSE | 4 +- README.md | 848 ++++++++++++++++- examples/README.md | 90 ++ .../auth-signer/create/create-credentials.go | 55 ++ .../auth-signer/delete/delete-credentials.go | 59 ++ examples/auth-signer/get/get-credentials.go | 55 ++ .../auth-signer/update/update-credentials.go | 68 ++ examples/sdk/create/create-credentials.go | 53 ++ examples/sdk/delete/delete-credentials.go | 53 ++ examples/sdk/get/get-credentials.go | 53 ++ examples/sdk/update/update-credentials.go | 70 ++ pkg/edgegrid/README.md | 69 -- pkg/iam/api_clients_credentials.go | 2 +- pkg/iam/user.go | 2 +- pkg/session/README.md | 81 -- pkg/session/session.go | 6 +- 17 files changed, 1863 insertions(+), 598 deletions(-) create mode 100644 examples/README.md create mode 100644 examples/auth-signer/create/create-credentials.go create mode 100644 examples/auth-signer/delete/delete-credentials.go create mode 100644 examples/auth-signer/get/get-credentials.go create mode 100644 examples/auth-signer/update/update-credentials.go create mode 100644 examples/sdk/create/create-credentials.go create mode 100644 examples/sdk/delete/delete-credentials.go create mode 100644 examples/sdk/get/get-credentials.go create mode 100644 examples/sdk/update/update-credentials.go delete mode 100644 pkg/edgegrid/README.md delete mode 100644 pkg/session/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index f420ae19..e78a84cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 9.1.0 (Nov 14, 2024) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * General * Added a configurable `WithRetries` option for creating new sessions with global GET retries. It can be configured with these parameters: @@ -32,7 +32,7 @@ * `ListZones` * `UpdateZone` -#### BUG FIXES: +### BUG FIXES: * APPSEC * Fixed SIEM exception validation for the `Exceptions` field. @@ -42,31 +42,34 @@ ## 9.0.0 (Oct 3, 2024) -#### BREAKING CHANGES: +### BREAKING CHANGES: * General * Consolidated multiple sub-interfaces into a single interface for each sub-provider. - * Renamed `NTWRKLISTS` interface to `NetworkList` for `networklists` provider - * Removed `tools` package in favour of `ptr` package + * Renamed the `NTWRKLISTS` interface to `NetworkList` for the `networklists` provider. + * Removed the `tools` package in favor of the `ptr` package. * Cloudaccess - * Changed naming of request body fields for following structures: - * `BodyParams` to `Body` in `CreateAccessKeyVersionRequest` - * `CreateAccessKeyVersionBodyParams` to `CreateAccessKeyVersionRequestBody` + * Changed naming of the request body fields for the `CreateAccessKeyVersionRequest` structure: + * From `BodyParams` to `Body`. + * From `CreateAccessKeyVersionBodyParams` to `CreateAccessKeyVersionRequestBody`. * Cloudlets - * Changed naming of request body fields for following structures: - * `BodyParams` to `Body` in `UpdatePolicyRequest` and `ClonePolicyRequest` - * `UpdatePolicyBodyParams` to `UpdatePolicyRequestBody` - * `ClonePolicyBodyParams` to `ClonePolicyRequestBody` + * Changed naming of the request body fields for the `UpdatePolicyRequest` structure: + * From `BodyParams` to `Body`. + * From `UpdatePolicyBodyParams` to `UpdatePolicyRequestBody`. + * Changed naming of the request body fields for the `ClonePolicyRequest` structure: + * From `BodyParams` to `Body`. + * From `ClonePolicyBodyParams` to `ClonePolicyRequestBody`. * Cloudwrapper - * Changed naming of request body fields for following structures: - * `CreateConfigurationBody` to `CreateConfigurationRequestBody` - * `UpdateConfigurationBody` to `UpdateConfigurationRequestBody` + * Changed naming of the request body field for the `CreateConfigurationRequest` structure: + * From`CreateConfigurationBody` to `CreateConfigurationRequestBody`. + * Changed naming of the request body field for the `UpdateConfigurationRequest` structure: + * From `UpdateConfigurationBody` to `UpdateConfigurationRequestBody`. * DNS - * Refactored parameters in following methods: + * Refactored parameters in these methods: * `GetAuthorities` - from (context.Context, string) into (context.Context, `GetAuthoritiesRequest`) * `GetNameServerRecordList` - from (context.Context, string) into (context.Context, `GetNameServerRecordListRequest`) * `GetRecord` - from (context.Context, string, string, string) into (context.Context, `GetRecordRequest`) @@ -102,40 +105,40 @@ * `CreateBulkZones` - from (context.Context, *BulkZonesCreate, ZoneQueryString) into (context.Context, `CreateBulkZonesRequest`) * `DeleteBulkZones` - from (context.Context, *ZoneNameListResponse, ...bool) into (context.Context, `DeleteBulkZonesRequest`) * `GetRdata` - from (context.Context, string, string, string) into (context.Context, `GetRdataRequest`) - * Refactored response in following methods: - * `GetAuthorities` - `*AuthorityResponse` into `*GetAuthoritiesResponse` + * Refactored the responses in these methods: + * `GetAuthorities` - from `*AuthorityResponse` into `*GetAuthoritiesResponse` * `GetRecord` - `*RecordBody` into `*GetRecordResponse` - * `GetRecordList` - `*RecordSetResponse` into `*GetRecordListResponse` - * `GetRecordSets` - `*RecordSetResponse` into `*GetRecordSetsResponse` - * `GetTSIGKey` - `*TSIGKeyResponse` into `*GetTSIGKeyResponse` - * `ListTSIGKeys` - `*TSIGReportResponse` into `*ListTSIGKeysResponse` - * `GetTSIGKeyZones` - `*ZoneNameListResponse` into `*GetTSIGKeyZonesResponse` - * `GetTSIGKeyAliases` - `*ZoneNameListResponse` into `*GetTSIGKeyAliasesResponse` - * `GetZone` - `*ZoneResponse` into `*GetZoneResponse` - * `GetChangeList` - `*ChangeListResponse` into `*GetChangeListResponse` - * `GetZoneNames` - `*ZoneNamesResponse` into `*GetZoneNamesResponse` - * `GetZoneNameTypes` - `*ZoneNameTypesResponse` into `*GetZoneNameTypesResponse` - * `GetBulkZoneCreateStatus` - `*BulkStatusResponse` into `*GetBulkZoneCreateStatusResponse` - * `GetBulkZoneDeleteStatus` - `*BulkStatusResponse` into `*GetBulkZoneDeleteStatusResponse` - * `GetBulkZoneCreateResult` - `*BulkCreateResultResponse` into `*GetBulkZoneCreateResultResponse` - * `GetBulkZoneDeleteResult` - `*BulkDeleteResultResponse` into `*GetBulkZoneDeleteResultResponse` - * `CreateBulkZones` - `*BulkZonesResponse` into `*CreateBulkZonesResponse` - * `DeleteBulkZones` - `*BulkZonesResponse` into `*DeleteBulkZonesResponse` - * Removed following interfaces: + * `GetRecordList` - from `*RecordSetResponse` into `*GetRecordListResponse` + * `GetRecordSets` - from `*RecordSetResponse` into `*GetRecordSetsResponse` + * `GetTSIGKey` - from `*TSIGKeyResponse` into `*GetTSIGKeyResponse` + * `ListTSIGKeys` - from `*TSIGReportResponse` into `*ListTSIGKeysResponse` + * `GetTSIGKeyZones` - from **`*ZoneNameListResponse` into `*GetTSIGKeyZonesResponse` + * `GetTSIGKeyAliases` - from `*ZoneNameListResponse` into `*GetTSIGKeyAliasesResponse` + * `GetZone` - from `*ZoneResponse` into `*GetZoneResponse` + * `GetChangeList` - from `*ChangeListResponse` into `*GetChangeListResponse` + * `GetZoneNames` - from `*ZoneNamesResponse` into `*GetZoneNamesResponse` + * `GetZoneNameTypes` - from `*ZoneNameTypesResponse` into `*GetZoneNameTypesResponse` + * `GetBulkZoneCreateStatus` - from `*BulkStatusResponse` into `*GetBulkZoneCreateStatusResponse` + * `GetBulkZoneDeleteStatus` - from `*BulkStatusResponse` into `*GetBulkZoneDeleteStatusResponse` + * `GetBulkZoneCreateResult` - from `*BulkCreateResultResponse` into `*GetBulkZoneCreateResultResponse` + * `GetBulkZoneDeleteResult` - from `*BulkDeleteResultResponse` into `*GetBulkZoneDeleteResultResponse` + * `CreateBulkZones` - from `*BulkZonesResponse` into `*CreateBulkZonesResponse` + * `DeleteBulkZones` - from `*BulkZonesResponse` into `*DeleteBulkZonesResponse` + * Removed these interfaces: * `Authorities` * `Data` * `Records` * `Recordsets` * `TSIGKeys` * `Zones` - * Renamed following methods: - * `SaveChangelist` into `SaveChangeList` - * `SubmitChangelist` into `SubmitChangeList` - * `TSIGKeyBulkUpdate` into `UpdateTSIGKeyBulk` + * Renamed these methods: + * From `SaveChangelist` into `SaveChangeList` + * From `SubmitChangelist` into `SubmitChangeList` + * From `TSIGKeyBulkUpdate` into `UpdateTSIGKeyBulk` * EdgeKV - * For the `CreateEdgeKVAccessTokenRequest`, removed the `Expiry` field and added the `RestrictToEdgeWorkerIDs` field. - * For the `CreateEdgeKVAccessTokenResponse`, removed the `Expiry` and `Value` fields, and added these fields: + * For the `CreateEdgeKVAccessTokenRequest` structure, removed the `Expiry` field and added the `RestrictToEdgeWorkerIDs` field. + * For the `CreateEdgeKVAccessTokenResponse` structure, removed the `Expiry` and `Value` fields, and added these fields: * `AllowOnProduction` * `AllowOnStaging` * `CPCode` @@ -145,15 +148,15 @@ * `NextScheduledRefreshDate` * `RestrictToEdgeWorkerIDs` * `TokenActivationStatus` - * Added these fields to the `EdgeKVAccessToken` method: + * Added these fields to the `EdgeKVAccessToken` structure: * `TokenActivationStatus` * `IssueDate` * `LatestRefreshDate` * `NextScheduledRefreshDate` * Edgeworkers - * Changed naming of request body fields for these structures: - * `EdgeWorkerIDBodyRequest` to `EdgeWorkerIDRequestBody` + * Changed naming of request body field for this structure: + * From `EdgeWorkerIDBodyRequest` to `EdgeWorkerIDRequestBody`. * GTM * Refactored parameters in these methods: @@ -192,43 +195,43 @@ * `CreateResource` - from (context.Context, *Resource, string) into (context.Context, `CreateResourceRequest`) * `UpdateResource` - from (context.Context, *Resource, string) into (context.Context, `UpdateResourceRequest`) * `DeleteResource` - from (context.Context, *Resource, string) into (context.Context, `DeleteResourceRequest`) - * Refactored response in these methods: - * `ListASMaps` - `[]*ASMap` into `[]ASMap` - * `GetASMap` - `*ASMap` into `*GetASMapResponse` - * `CreateASMap` - `*ASMapResponse` into `*CreateASMapResponse` - * `UpdateASMap` - `*ResponseStatus` into `*UpdateASMapResponse` - * `DeleteASMap` -`*ResponseStatus` into `*DeleteASMapResponse` - * `ListCIDRMaps` - `[]*CIDRMap` into `[]CIDRMap` - * `GetCIDRMap` - `*CIDRMap` into `*GetCIDRMapResponse` - * `CreateCIDRMap` - `*CIDRMapResponse` into `*CreateCIDRMapResponse` - * `UpdateCIDRMap` - `*ResponseStatus` into `*UpdateCIDRMapResponse` - * `DeleteCIDRMap` - `*ResponseStatus` into `*DeleteCIDRMapResponse` - * `ListDatacenters` - `[]*Datacenter` into `[]Datacenter` - * `CreateDatacenter` - `*DatacenterResponse` into `*CreateDatacenterResponse` - * `UpdateDatacenter` - `*ResponseStatus` into `*UpdateDatacenterResponse` - * `DeleteDatacenter` - `*ResponseStatus` into `*DeleteDatacenterResponse` - * `ListDomains` - `[]*DomainItem` into `[]DomainItem` + * Refactored the responses in these methods: + * `ListASMaps` - from `[]*ASMap` into `[]ASMap` + * `GetASMap` - from`*ASMap` into `*GetASMapResponse` + * `CreateASMap` - from `*ASMapResponse` into `*CreateASMapResponse` + * `UpdateASMap` - from `*ResponseStatus` into `*UpdateASMapResponse` + * `DeleteASMap` - from`*ResponseStatus` into `*DeleteASMapResponse` + * `ListCIDRMaps` - from `[]*CIDRMap` into `[]CIDRMap` + * `GetCIDRMap` - from `*CIDRMap` into `*GetCIDRMapResponse` + * `CreateCIDRMap` - from `*CIDRMapResponse` into `*CreateCIDRMapResponse` + * `UpdateCIDRMap` - from `*ResponseStatus` into `*UpdateCIDRMapResponse` + * `DeleteCIDRMap` - from `*ResponseStatus` into `*DeleteCIDRMapResponse` + * `ListDatacenters` - from `[]*Datacenter` into `[]Datacenter` + * `CreateDatacenter` - from `*DatacenterResponse` into `*CreateDatacenterResponse` + * `UpdateDatacenter` - from `*ResponseStatus` into `*UpdateDatacenterResponse` + * `DeleteDatacenter` - from `*ResponseStatus` into `*DeleteDatacenterResponse` + * `ListDomains` - from `[]*DomainItem` into `[]DomainItem` * `GetDomain` - `*Domain` into `*GetDomainResponse` - * `CreateDomain` - `*DomainResponse` into `*CreateDomainResponse` - * `UpdateDomain` - `*ResponseStatus` into `*UpdateDomainResponse` + * `CreateDomain` - from `*DomainResponse` into `*CreateDomainResponse` + * `UpdateDomain` - from `*ResponseStatus` into `*UpdateDomainResponse` * `DeleteDomain` - `*ResponseStatus` into `*DeleteDomainResponse` - * `GetDomainStatus` - `*ResponseStatus` into `*GetDomainStatusResponse` - * `ListGeoMaps` - `[]*GeoMap` into `[]GeoMap` - * `GetGeoMap` - `*GeoMap` into `*GetGeoMapResponse` - * `CreateGeoMap` - `*GeoMapResponse` into `*CreateGeoMapResponse` - * `UpdateGeoMap` - `*ResponseStatus` into `*UpdateGeoMapResponse` - * `DeleteGeoMap` - `*ResponseStatus` into `*DeleteGeoMapResponse` - * `ListProperties` - `[]*Property` into `[]Property` - * `GetProperty` - `*Property` into `*GetPropertyResponse` - * `CreateProperty` - `*PropertyResponse` into `*CreatePropertyResponse` - * `UpdateProperty` - `*ResponseStatus` into `*UpdatePropertyResponse` - * `DeleteProperty` - `*ResponseStatus` into `*DeletePropertyResponse` - * `ListResources` - `[]*Resource` into `[]Resource` - * `GetResource` - `*Resource` into `*GetResourceResponse` - * `CreateResource` - `*ResourceResponse` into `*CreateResourceResponse` - * `UpdateResource` - `*ResponseStatus` into `*UpdateResourceResponse` - * `DeleteResource` - `*ResponseStatus` into `*DeleteResourceResponse` - * Extended response for these methods - previously only status was returned, now status and resource are returned: + * `GetDomainStatus` - from `*ResponseStatus` into `*GetDomainStatusResponse` + * `ListGeoMaps` - from `[]*GeoMap` into `[]GeoMap` + * `GetGeoMap` - from `*GeoMap` into `*GetGeoMapResponse` + * `CreateGeoMap` - from `*GeoMapResponse` into `*CreateGeoMapResponse` + * `UpdateGeoMap` - from `*ResponseStatus` into `*UpdateGeoMapResponse` + * `DeleteGeoMap` - from `*ResponseStatus` into `*DeleteGeoMapResponse` + * `ListProperties` - from `[]*Property` into `[]Property` + * `GetProperty` - from `*Property` into `*GetPropertyResponse` + * `CreateProperty` - from `*PropertyResponse` into `*CreatePropertyResponse` + * `UpdateProperty` - from `*ResponseStatus` into `*UpdatePropertyResponse` + * `DeleteProperty` - from `*ResponseStatus` into `*DeletePropertyResponse` + * `ListResources` - from `[]*Resource` into `[]Resource` + * `GetResource` - from `*Resource` into `*GetResourceResponse` + * `CreateResource` - from `*ResourceResponse` into `*CreateResourceResponse` + * `UpdateResource` - from `*ResponseStatus` into `*UpdateResourceResponse` + * `DeleteResource` - from `*ResponseStatus` into `*DeleteResourceResponse` + * Extended the response for these methods - previously only the status was returned, now the status and resource are returned: * `UpdateASMap` * `DeleteASMap` * `UpdateCIDRMap` @@ -254,19 +257,19 @@ * IAM * Migrated V2 endpoints to V3. * Improved date handling to use `time.Time` instead of `string`. - * Changed fields in these structures: + * Changed field types in these structures: * `Users` - * `LastLoginDate`. Changed the field data type from `string` to `time.Time` - * `PasswordExpiryDate`. Changed the field data type from `string` to `time.Time` + * `LastLoginDate`. Changed the field data type from `string` to `time.Time`. + * `PasswordExpiryDate`. Changed the field data type from `string` to `time.Time`. * `UserListItem` - * `LastLoginDate`. Changed the field data type from `string` to `time.Time` + * `LastLoginDate`. Changed the field data type from `string` to `time.Time`. * `Role` - * `CreatedDate`. Changed the field data type from `string` to `time.Time` - * `ModifiedDate`. Changed the field data type from `string` to `time.Time` + * `CreatedDate`. Changed the field data type from `string` to `time.Time`. + * `ModifiedDate`. Changed the field data type from `string` to `time.Time`. * `RoleUser` - * `LastLoginDate`. Changed the field data type from `string` to `time.Time` + * `LastLoginDate`. Changed the field data type from `string` to `time.Time`. * `GroupUser` - * `LastLoginDate`. Changed the field data type from `string` to `time.Time` + * `LastLoginDate`. Changed the field data type from `string` to `time.Time`. * Changed the `Notifications` field to a pointer type in these structures: * `CreateUserRequest` * `UpdateUserNotificationsRequest` @@ -276,7 +279,7 @@ * PAPI * Removed the `rule_format` and `product_id` fields from the `Property` structure, as this information is populated in the `GetPropertyVersion` method. -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC * Added the `Exceptions` field to these structures: @@ -284,15 +287,15 @@ * `GetSiemSettingResponse` * `UpdateSiemSettingsRequest` * `UpdateSiemSettingsResponse` - * Added the `Source` field to the `GetExportConfigurationRequest` method and the `TargetProduct` field to the `GetExportConfigurationResponse` method. + * Added the `Source` field to the `GetExportConfigurationRequest` structure and the `TargetProduct` field to the `GetExportConfigurationResponse` structure. * IAM - * Updated structures: - * `User` with `AdditionalAuthenticationConfigured` and `Actions` - * `UserListItem` with `AdditionalAuthenticationConfigured` and `AdditionalAuthentication` - * `UserBasicInfo` with `AdditionalAuthentication` - * `UserActions` with `CanGenerateBypassCode` - * `UserNotificationOptions` with `APIClientCredentialExpiry` + * Updated these structures: + * `User` with the `AdditionalAuthenticationConfigured` and `Actions` parameters. + * `UserListItem` with the `AdditionalAuthenticationConfigured` and `AdditionalAuthentication` parameters. + * `UserBasicInfo` with the `AdditionalAuthentication` parameter. + * `UserActions` with the `CanGenerateBypassCode` parameter. + * `UserNotificationOptions` with the `APIClientCredentialExpiry` parameter. * Added new methods: * [UpdateMFA](https://techdocs.akamai.com/iam-api/reference/put-user-profile-additional-authentication) * [ResetMFA](https://techdocs.akamai.com/iam-api/reference/put-ui-identity-reset-additional-authentication) @@ -306,7 +309,7 @@ * [DeactivateYourCredentials](https://techdocs.akamai.com/iam-api/reference/post-self-credentials-deactivate) and [DeactivateCredentials](https://techdocs.akamai.com/iam-api/reference/post-client-credentials-deactivate) * Added the `UserStatus` and `AccountID` parameters to the `User` structure. * Added the [GetPasswordPolicy](https://techdocs.akamai.com/iam-api/reference/get-common-password-policy) method to get a password policy for an account. - * Added Helper APIs + * Added Helper APIs: * [ListAllowedCPCodes](https://techdocs.akamai.com/iam-api/reference/post-api-clients-users-allowed-cpcodes) * [ListAuthorizedUsers](https://techdocs.akamai.com/iam-api/reference/get-api-clients-users) * [ListAllowedAPIs](https://techdocs.akamai.com/iam-api/reference/get-api-clients-users-allowed-apis) @@ -334,15 +337,15 @@ ## 8.4.0 (Aug 22, 2024) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Added field `ClientLists` to `RuleConditions` and `AttackGroupConditions` - * The `RequestBodyInspectionLimitOverride` field has been added in these structures: - * `GetAdvancedSettingsRequestBodyResponse`, - * `UpdateAdvancedSettingsRequestBodyRequest`, - * `UpdateAdvancedSettingsRequestBodyResponse`, - * `RemoveAdvancedSettingsRequestBodyRequest`, + * Added the `ClientLists` field to the `RuleConditions` and `AttackGroupConditions` structures. + * Added the `RequestBodyInspectionLimitOverride` field to these structures: + * `GetAdvancedSettingsRequestBodyResponse` + * `UpdateAdvancedSettingsRequestBodyRequest` + * `UpdateAdvancedSettingsRequestBodyResponse` + * `RemoveAdvancedSettingsRequestBodyRequest` * `RemoveAdvancedSettingsRequestBodyResponse` * IAM @@ -350,20 +353,20 @@ * [GetProperty](https://techdocs.akamai.com/iam-api/reference/get-property) * [ListProperties](https://techdocs.akamai.com/iam-api/reference/get-properties) * [MoveProperty](https://techdocs.akamai.com/iam-api/reference/put-property) - * `MapPropertyIDToName` - to provide property name for given IAM property ID - + * `MapPropertyIDToName` - to provide a property name for a given IAM property ID + * PAPI - * Added new method `MapPropertyNameToID` to provide PAPI property ID for given property name + * Added a new method `MapPropertyNameToID` to provide a PAPI property ID for a given property name. ## 8.3.0 (July 09, 2024) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * General - * Added `To` utility function in the `ptr` package that helps with creating value pointers + * Added the `To` utility function in the `ptr` package to facilitate creating value pointers. * BOTMAN - * Added Content Protection APIs + * Added Content Protection APIs: * [CreateContentProtectionRule](https://techdocs.akamai.com/content-protector/reference/post-content-protection-rule) * [GetContentProtectionRuleList](https://techdocs.akamai.com/content-protector/reference/get-content-protection-rules) * [GetContentProtectionRule](https://techdocs.akamai.com/content-protector/reference/get-content-protection-rule) @@ -377,7 +380,7 @@ * [UpdateContentProtectionJavaScriptInjectionRule](https://techdocs.akamai.com/content-protector/reference/put-content-protection-javascript-injection-rule) * [RemoveContentProtectionJavaScriptInjectionRule](https://techdocs.akamai.com/content-protector/reference/delete-content-protection-javascript-injection-rule) -* Added Cloud Access Manager API support +* Added Cloud Access Manager API support: * Access Keys * [GetAccessKeyStatus](https://techdocs.akamai.com/cloud-access-mgr/reference/get-access-key-create-request) * [CreateAccessKey](https://techdocs.akamai.com/cloud-access-mgr/reference/post-access-key) @@ -397,11 +400,11 @@ * [PerformAsyncPropertiesLookup](https://techdocs.akamai.com/cloud-access-mgr/reference/get-property-lookup) * DNS - * Added [GetZonesDNSSecStatus](https://techdocs.akamai.com/edge-dns/reference/post-zones-dns-sec-status) method returning the current DNSSEC status for one or more zones + * Added the [GetZonesDNSSecStatus](https://techdocs.akamai.com/edge-dns/reference/post-zones-dns-sec-status) method returning the current DNSSEC status for one or more zones. -#### Deprecations +### Deprecations -* Deprecated these functions in the `tools` package. Use `ptr.To` instead. +* Deprecated these functions in the `tools` package (use `ptr.To` instead): * `BoolPtr` * `IntPtr` * `Int64Ptr` @@ -411,55 +414,55 @@ ## 8.2.0 (May 21, 2024) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Added `CounterType` field to `CreateRatePolicyResponse`, `UpdateRatePolicyResponse`, `RemoveRatePolicyResponse`, `GetRatePoliciesResponse` and `GetRatePolicyResponse` structs to support managing rate policy counter type + * Added the `CounterType` field to the `CreateRatePolicyResponse`, `UpdateRatePolicyResponse`, `RemoveRatePolicyResponse`, `GetRatePoliciesResponse`, and `GetRatePolicyResponse` structures to support managing the rate policy counter type. -* BOTMAN - * Added [GetCustomBotCategoryItemSequence](https://techdocs.akamai.com/bot-manager/reference/get-custom-bot-category-item-sequence) and [UpdateCustomBotCategoryItemSequence](https://techdocs.akamai.com/bot-manager/reference/put-custom-bot-category-item-sequence) +* BOTMAN + * Added the [GetCustomBotCategoryItemSequence](https://techdocs.akamai.com/bot-manager/reference/get-custom-bot-category-item-sequence) and [UpdateCustomBotCategoryItemSequence](https://techdocs.akamai.com/bot-manager/reference/put-custom-bot-category-item-sequence) methods. * HAPI - * Added method to return certificate for the edge hostname + * Added a new method to return a certificate for an edge hostname. * [GetCertificate](https://techdocs.akamai.com/edge-hostnames/reference/get-edge-hostname-certificate) - * Added fields to `GetEdgeHostnameResponse`: `ProductID`, `MapAlias` and `UseCases` + * Added the `ProductID`, `MapAlias`, and `UseCases` fields to the `GetEdgeHostnameResponse` structure. -#### BUG FIXES: +### BUG FIXES: * APPSEC - * The `Override` field in these structs has been updated from a pointer to a value type within the `AdvancedSettingsAttackPayloadLogging` interface: - * `GetAdvancedSettingsAttackPayloadLoggingResponse`, - * `UpdateAdvancedSettingsAttackPayloadLoggingResponse`, - * `RemoveAdvancedSettingsAttackPayloadLoggingRequest`, + * Updated the `Override` field in these structures from a pointer to a value type within the `AdvancedSettingsAttackPayloadLogging` interface: + * `GetAdvancedSettingsAttackPayloadLoggingResponse` + * `UpdateAdvancedSettingsAttackPayloadLoggingResponse` + * `RemoveAdvancedSettingsAttackPayloadLoggingRequest` * `RemoveAdvancedSettingsAttackPayloadLoggingResponse` - This update was made to address a drift issue related to policy level settings. - * Omit `Prefetch` within `AdvancedOptions` in `GetExportConfigurationResponse` when empty + This update was made to address a drift issue related to the policy level settings. + * Omitted `Prefetch` within `AdvancedOptions` in the `GetExportConfigurationResponse` structure when empty. * CLOUDLETS - * Added validation that `ObjectMatchValue` is not supported with `MatchType` `query` in `MatchRuleER` ([#535](https://github.com/akamai/terraform-provider-akamai/issues/535)) + * Added validation that `ObjectMatchValue` is not supported with `MatchType` `query` in `MatchRuleER` ([#535](https://github.com/akamai/terraform-provider-akamai/issues/535)). ## 8.1.0 (April 11, 2024) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * DNS - * Modified `ParseRData` method to remove priority, weight and port from targets **only** when those values are same for all `SRV` targets. - Otherwise, targets are returned untouched and `priority`, `weight` and `port` in the map are not populated. + * Modified the `ParseRData` method to remove priority, weight, and port from targets **only** when those values are same for all `SRV` targets. + Otherwise, targets are returned untouched and `priority`, `weight`, and `port` in the map are not populated. * Image and Video Manager - * Added `SmartCrop` transformation + * Added `SmartCrop` transformation. ## 8.0.0 (March 19, 2024) -#### BREAKING CHANGES: +### BREAKING CHANGES: -* Migrated to go 1.21 +* Migrated to go 1.21. * CPS - * Split request and response structures for create and update enrollment operations + * Split the request and response structures for create and update enrollment operations. * DNS - * Renamed these structs: + * Renamed these structures: * `RecordsetQueryArgs` into `RecordSetQueryArgs` * `Recordsets` into `RecordSets` * `Recordset` into `RecordSet` @@ -471,8 +474,8 @@ * `Gid` into `GID` in `TSIGQueryString` and `TSIGReportMeta` * `TsigKey` into `TSIGKey` in `ZoneCreate` and `ZoneResponse` * `VersionId` into `VersionID` in `ZoneResponse` - * `RequestId` into `RequestID` in `BulkZonesResponse`, `BulkStatusResponse`, `BulkCreateResultResponse` and `BulkDeleteResultResponse` - * Renamed `RecordSets` interface into `Recordsets` + * `RequestId` into `RequestID` in `BulkZonesResponse`, `BulkStatusResponse`, `BulkCreateResultResponse`, and `BulkDeleteResultResponse` + * Renamed the `RecordSets` interface into `Recordsets`. * Renamed these methods: * `ListTsigKeys` into `ListTSIGKeys` * `GetTsigKeyZones` into `GetTSIGKeyZones` @@ -501,7 +504,7 @@ * `ValidateZone` * GTM - * Renamed these structs: + * Renamed these structures: * `AsAssignment` into `ASAssignment` * `AsMap` into `ASMap` * `AsMapList` into `ASMapList` @@ -516,7 +519,7 @@ * `AsMapItems` into `ASMapItems` in `ASMapList` * `CidrMapItems` into `CIDRMapItems` in `CIDRMapList` * `ChangeId` into `ChangeID` in `ResponseStatus` - * `DatacenterId` into `DatacenterID` in `DatacenterBase`, `Datacenter`, `TrafficTarget` and `ResourceInstance` + * `DatacenterId` into `DatacenterID` in `DatacenterBase`, `Datacenter`, `TrafficTarget`, and `ResourceInstance` * `AsMaps` into `ASMaps` in `Domain` * `DefaultSslClientPrivateKey` into `DefaultSSLClientPrivateKey` in `Domain` * `CnameCoalescingEnabled` into `CNameCoalescingEnabled` in `Domain` @@ -531,7 +534,7 @@ * `HttpHeaders` into `HTTPHeaders` in `LivenessTest` * `Ipv6` into `IPv6` in `Property` * `BackupIp` into `BackupIP` in `Property` - * Renamed `CidrMaps` interface into `CIDRMaps` + * Renamed the `CidrMaps` interface into `CIDRMaps`. * Renamed these methods: * `ListAsMaps` into `ListASMaps` * `GetAsMap` into `GetASMap` @@ -565,48 +568,48 @@ * `NewStaticRRSet` * `NewTrafficTarget` -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: -* Added default value `application/json` for `Accept` header for all requests sent to API +* Added the default value of `application/json` for the `Accept` header for all requests sent to API. -* Appsec - * Added `PenaltyBoxConditions` API - read and update - * Added `EvalPenaltyBoxConditions` API - read and update +* APPSEC + * Added the `PenaltyBoxConditions` API - read and update. + * Added the `EvalPenaltyBoxConditions` API - read and update. * CPS - * Added `ID`, `OrgID`, `ProductionSlots`, `StagingSlots` and `AssignedSlots` to the response structures of `GetEnrollment` and `ListEnrollment` operations + * Added the `ID`, `OrgID`, `ProductionSlots`, `StagingSlots`, and `AssignedSlots` fields to the response structures of the `GetEnrollment` and `ListEnrollment` operations. * GTM * Added new fields: * `SignAndServe` and `SignAndServeAlgorithm` for the `Domain` - * `HTTPMethod`, `HTTPRequestBody`, `Pre2023SecurityPosture` and `AlternateCACertificates` for the `LivenessTest` in `Property` - * `Precedence` for the `TrafficTarget` in `Property` - * Enhanced error details by addition of `Errors` field in `Error` structure - * Added support for the creation of `ranked-failover` properties + * `HTTPMethod`, `HTTPRequestBody`, `Pre2023SecurityPosture`, and `AlternateCACertificates` for the `LivenessTest` in `Property` + * `Precedence` for `TrafficTarget` in `Property` + * Enhanced error details by adding the `Errors` field in the `Error` structure. + * Added support for the creation of the `ranked-failover` properties. -#### BUG FIXES: +### BUG FIXES: * DNS - * Removed not working `DeleteZone` method + * Removed the `DeleteZone` method that was not working. * * PAPI - * Updated documentation link for `GetProperties` method + * Updated the documentation link for the `GetProperties` method. ## 7.6.1 (February 14, 2024) -#### BUG FIXES: +### BUG FIXES: * Edgeworkers - * Fixed case when not providing optional `note` field in `ActivateVersion` would cause activation to fail + * Fixed the case when not providing an optional `note` field in the `ActivateVersion` method would cause activation to fail. ## 7.6.0 (February 8, 2024) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * General * Enhanced error handling when Error is not in standard format. -* Added Cloudlets V3 API support +* Added Cloudlets V3 API support. * Cloudlet Info * [ListCloudlets](https://techdocs.akamai.com/cloudlets/reference/get-cloudlets) * Policies @@ -637,75 +640,75 @@ * Request Control (RC aka IG) * DNS - * Added `ListGroups` method + * Added the `ListGroups` method. * [ListGroups](https://techdocs.akamai.com/edge-dns/reference/get-data-groups) * Edgeworkers - * Added `note` field to `Activation` and `ActivateVersion` structs for EdgeWorkers Activation + * Added the `note` field to the `Activation` and `ActivateVersion` structures for EdgeWorkers Activation. * GTM - * Added new fields to `DomainItem` struct + * Added new fields to the `DomainItem` structure. * IVM - * Extended `OutputImage` for support of `AllowPristineOnDownsize` and `PreferModernFormats` - * Extended `PolicyInputImage` for support of `ServeStaleDuration` - * Extended `RolloutInfo` for support of `ServeStaleEndTime` + * Extended `OutputImage` for support of `AllowPristineOnDownsize` and `PreferModernFormats`. + * Extended `PolicyInputImage` for support of `ServeStaleDuration`. + * Extended `RolloutInfo` for support of `ServeStaleEndTime`. -#### BUG FIXES: +### BUG FIXES: * APPSEC - * Added `updateLatestNetworkStatus` query parameter in GetActivations request to resolve drift on manual changes to infrastructure + * Added the `updateLatestNetworkStatus` query parameter in the `GetActivations` request to resolve drift on manual changes to infrastructure. ## 7.5.0 (November 28, 2023) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Added `ASNControls` field to `UpdateIPGeoRequest` and `IPGeoFirewall` structs to support firewall blocking by ASN client lists + * Added the `ASNControls` field to the UpdateIPGeoRequest` and `IPGeoFirewall` structures to support firewall blocking by ASN client lists. * BOTMAN - * Added API support for Custom Code - read and update + * Added the API support for Custom Code - read and update. ## 7.4.0 (October 24, 2023) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Updated `GetExportConfigurationResponse` struct to export rate policy `burstWindow` and `condition` fields + * Updated the `GetExportConfigurationResponse` structure to export the rate policy `burstWindow` and `condition` fields. * Cloudlets - * Added MatchesAlways field to ER cloudlet + * Added the `MatchesAlways` field to the ER cloudlet. * IAM - * Phone number is no longer required for IAM user for `CreateUser` and `UpdateUserInfo` methods + * Phone number is no longer required for IAM user for the `CreateUser` and `UpdateUserInfo` methods. ## 7.3.0 (September 19, 2023) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * ClientLists - * Updated `GetClientListResponse` and `UpdateClientListResponse` to include `GroupID` + * Updated the `GetClientListResponse` and `UpdateClientListResponse` structures to include the `GroupID` field. * GTM - * Added custom error `ErrNotFound` that can be used to check if GTM api returned 404 not found + * Added a custom error `ErrNotFound` that can be used to check if GTM API returned a 404 not found. * HAPI - * Added `GetChangeRequest` + * Added `GetChangeRequest`. -* Updated `yaml.v3` dependency +* Updated the `yaml.v3` dependency. ## 7.2.1 (August 25, 2023) -#### BUG FIXES: +### BUG FIXES: * CloudWrapper - * Fixed build for 32-bit systems + * Fixed the build for 32-bit systems. ## 7.2.0 (August 22, 2023) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: -* [IMPORTANT] Added CloudWrapper API support +* [IMPORTANT] Added CloudWrapper API support: * Capacities * [ListCapacities](https://techdocs.akamai.com/cloud-wrapper/reference/get-capacity-inventory) * Configurations @@ -738,23 +741,23 @@ * [CreateActivation](https://techdocs.akamai.com/client-lists/reference/post-activate-list) * APPSEC - * Added Bot Management API Support - * Custom Client Sequence - read and update + * Added Bot Management API Support: + * Custom Client Sequence - read and update. ## 7.1.0 (July 25, 2023) ### FEATURES/ENHANCEMENTS: * APPSEC - * Added Bot Management API Support - * Challenge Injection Rules - read, update - * Add `CreateSecurityPolicyWithDefaultProtections` method to the `SecurityPolicy` interface to support creating a security policy with all available protections enabled. - * Update marshaling of PII learning setting + * Added Bot Management API Support: + * Challenge Injection Rules - read and update. + * Added the `CreateSecurityPolicyWithDefaultProtections` method to the `SecurityPolicy` interface to support creating a security policy with all available protections enabled. + * Updated marshaling of the PII learning setting. ### Deprecations -* Challenge Interceptions Rules has been deprecated -* Deprecate these interfaces used to maintain individual policy protections: +* Deprecated the Challenge Interceptions Rules. +* Deprecated these interfaces used to maintain individual policy protections: * `ApiConstraintsProtection` * `IPGeoProtection` * `MalwareProtection` @@ -763,135 +766,136 @@ * `ReputationProtection` * `SlowPostProtection` * `WAFProtection` -* Deprecate the `CreateSecurityPolicy` method of the `SecurityPolicy` interface. +* Deprecated the `CreateSecurityPolicy` method of the `SecurityPolicy` interface. ## 7.0.0 (June 20, 2023) ### BREAKING CHANGES: * DataStream - * Updated `connectors` details in DataStream 2 API v2. - * Updated `GetProperties` and `GetDatasetFields` methods in DataStream 2 API v2. - * Updated `CreateStream`, `GetStream`, `UpdateStream`, `DeleteStream` and `ListStreams` methods in DataStream 2 API v2. - * Updated `Activate`, `Deactivate`, `ActivationHistory` and `Stream` details in DataStream 2 API v2 and also changed their corresponding response objects. + * Updated the `connectors` details in the DataStream 2 API v2. + * Updated the `GetProperties` and `GetDatasetFields` methods in the DataStream 2 API v2. + * Updated the `CreateStream`, `GetStream`, `UpdateStream`, `DeleteStream`, and `ListStreams` methods in the DataStream 2 API v2. + * Updated the `Activate`, `Deactivate`, `ActivationHistory`, and `Stream` details in the DataStream 2 API v2 and changed their corresponding response objects. ### FEATURES/ENHANCEMENTS: * APPSEC - * Update Geo control to include Action for Ukraine. - * Add `AdvancedSettingsPIILearning` interface to support reading and updating the PII learning setting. + * Updated the Geo control to include Action for Ukraine. + * Added the `AdvancedSettingsPIILearning` interface to support reading and updating of the PII learning setting. ### BUG FIXES: * APPSEC - * Add error handling for failed NetworkList client calls. + * Added error handling for the failed NetworkList client calls. ## 6.0.0 (May 23, 2023) ### BREAKING CHANGES: * APPSEC - * Update malware policy `ContentTypes` to include `EncodedContentAttributes`. + * Updated the malware policy `ContentTypes` to include `EncodedContentAttributes`. * Malware policy's `ContentTypes` is reported as part of an individual policy but is no longer included in the bulk report of all policies. * CLOUDLETS - * `ActivatePolicyVersion` also returns list of triggerred activations + * Updated `ActivatePolicyVersion` to also return list of triggered activations. * PAPI - * Fix property variables fields with empty and null values are ignored - * Remove `ProductID` field from `GetEdgeHostname` response + * Fixed the property variables fields – empty and null values are ignored. + * Removed the `ProductID` field from the `GetEdgeHostname` response. ### BUG FIXES: + * APPSEC - * Omit `clientIdentifier` and `additionalMatchOptions` in `GetExportConfigurationResponse` when empty + * Omitted the `clientIdentifier` and `additionalMatchOptions` fields in `GetExportConfigurationResponse` when empty. ## 5.0.0 (March 28, 2023) ### FEATURES/ENHANCEMENTS: * APPSEC - * Add `AdvancedSettingsRequestBody` interface to support configuring request size inspection limit + * Added the `AdvancedSettingsRequestBody` interface to support configuring the request size inspection limit. * EDGEKV * [ListGroupsWithinNamespace](https://techdocs.akamai.com/edgekv/reference/get-groups) * Image and Video Manager - * Add possible value `avif` for `forcedFormats` and `allowedFormats` + * Added a possible value of `avif` for the `forcedFormats` and `allowedFormats` fields. * PAPI - * Add `complianceRecord` field to `Activation` struct for PAPI activation + * Added the `complianceRecord` field to the `Activation` structure for PAPI activation. -#### BREAKING CHANGES: +### BREAKING CHANGES: * APPSEC - * Remove deprecated `EvalHost` and `EvalProtectHost` interfaces. (Use the `WAPSelectedHostnames` interface instead.) - * Remove deprecated `BypassNetworkList` interface. (Use the `WAPBypassNetworkList` interface instead.) + * Removed the deprecated `EvalHost` and `EvalProtectHost` interfaces. (Use the `WAPSelectedHostnames` interface instead.) + * Removed the deprecated `BypassNetworkList` interface. (Use the `WAPBypassNetworkList` interface instead.) ## 4.1.0 (Feb 27, 2023) ### FEATURES/ENHANCEMENTS: * APPSEC - * Added these BotManager fields to GetExportConfigurationResponse - * BotManagement - * CustomBotCategories - * CustomDefinedBots - * CustomBotCategorySequence - * CustomClients - * ResponseActions - * AdvancedSettings - * Added AdvancedSettingsAttackPayloadLogging interface + * Added these BotManager fields to `GetExportConfigurationResponse`: + * `BotManagement` + * `CustomBotCategories` + * `CustomDefinedBots` + * `CustomBotCategorySequence` + * `CustomClients` + * `ResponseActions` + * `AdvancedSettings` + * Added the `AdvancedSettingsAttackPayloadLogging` interface. -#### BUG FIXES: +### BUG FIXES: -* Fix V4 of Edgegrid doesn't parse hostname ([#182](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/pull/182)) +* Fixed an issue in Edgegrid v4 with parsing a hostname ([#182](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/pull/182)). ## 4.0.0 (Jan 31, 2023) -#### BREAKING CHANGES: +### BREAKING CHANGES: -* Migrate to go 1.18 +* Migrated to go 1.18. * PAPI - * Fix response structures for GetAvailableBehaviors and GetAvailableCriteria: + * Fixed the response structures for `GetAvailableBehaviors` and `GetAvailableCriteria`: * [GetAvailableCriteria](https://techdocs.akamai.com/property-mgr/reference/get-available-criteria) * [GetAvailableBehaviors](https://techdocs.akamai.com/property-mgr/reference/get-available-behaviors) * CPS - * Update `Accept` header to the latest schema `application/vnd.akamai.cps.enrollment.v11+json` for these endpoints: + * Updated the `Accept` header to the latest schema `application/vnd.akamai.cps.enrollment.v11+json` for these endpoints: * [ListEnrollments](https://techdocs.akamai.com/cps/reference/get-enrollments) * [GetEnrollment](https://techdocs.akamai.com/cps/reference/get-enrollment) * APPSEC - * Fix incorrect return type structure in `UpdateBypassNetworkListsResponse` - * Return `RatePolicyCondition` via a pointer in response structs of `RatePolicy` APIs + * Fixed an incorrect return type structure in `UpdateBypassNetworkListsResponse`. + * Returned `RatePolicyCondition` via a pointer in the response structures of the `RatePolicy` APIs. -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: -* Replace obsolete APIs documentation links with new one from [https://techdocs.akamai.com](https://techdocs.akamai.com) +* Replaced obsolete APIs documentation links with the new ones from [https://techdocs.akamai.com](https://techdocs.akamai.com). * APPSEC - * Add `burstWindow` and `condition` fields to RatePolicy + * Added the `burstWindow` and `condition` fields to `RatePolicy`. * CPS - * Add `preferredTrustChain` field to `csr` struct ([#351](https://github.com/akamai/terraform-provider-akamai/issues/351)) - * Set `utf-8 charset` in `content-type` header for requests + * Added the `preferredTrustChain` field to the `csr` structure ([#351](https://github.com/akamai/terraform-provider-akamai/issues/351)). + * Set `utf-8 charset` in the `content-type` header for requests. -#### BUG FIXES: +### BUG FIXES: -* Fix code errors in documentation examples ([#177](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/pull/177)) +* Fixed code errors in documentation examples ([#177](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/pull/177)). * IAM - * Issue updating user information - removed validation on user update + * Issued updating user information – removed validation on user update. ## 3.1.0 (Dec 12, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * General - * Add badges to readme and improve code quality + * Added badges to readme and improved code quality. -* [IMPORTANT] Added Property Include API support +* [IMPORTANT] Added Property Include API support: * Includes * [ListIncludes](https://techdocs.akamai.com/property-mgr/reference/get-includes) * [ListIncludeParents](https://techdocs.akamai.com/property-mgr/reference/get-include-parents) @@ -914,88 +918,88 @@ * [ListIncludeVersionAvailableCriteria](https://techdocs.akamai.com/property-mgr/reference/get-include-available-criteria) * [ListIncludeVersionAvailableBehaviors](https://techdocs.akamai.com/property-mgr/reference/get-include-available-behaviors) -#### BREAKING CHANGES: +### BREAKING CHANGES: * APPSEC - * Factor out `PolicySecurityControls` struct + * Factored out the `PolicySecurityControls` structure. ## 3.0.0 (November 28, 2022) ### Deprecations * CPS - * UpdateChange() function has been deprecated + * Deprecated the `UpdateChange()` function. -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * CPS - * ChangeManagementInfo - get or acknowledge change management info, get change deployment info - * Deployments - list deployments, get production deployment, get staging deployment - * DeploymentSchedules - get deployment schedule, update deployment schedule - * History - get DV history, get certificate history, get change history - * PostVerification - get or acknowledge post verification warnings - * ThirdPartyCSR - get third-party CSR, upload certificate + * `ChangeManagementInfo` - get or acknowledge the change management information, get the change deployment information. + * `Deployments` - list deployments, get the production deployment, get the staging deployment. + * `DeploymentSchedules` - get the deployment schedule, update the deployment schedule. + * `History` - get the DV history, get the certificate history, get the change history. + * `PostVerification` - get or acknowledge the post verification warnings. + * `ThirdPartyCSR` - get the third-party CSR, upload a certificate. -#### BREAKING CHANGES: +### BREAKING CHANGES: -* Rename package `configdns` to `dns` -* Rename package `configgtm` to `gtm` +* Renamed the `configdns` package to `dns`. +* Rename the `configgtm` package to `gtm`. * CPS - * Renamed structs: Challenges and ValidationRecords to Challenge and ValidationRecord accordingly - * Type change: `NotAfter` and `NotBefore` fields in `DeploymentSchedule` struct used in response for `GetChangeStatus` are `*string` instead of `string` + * Renamed these structures: `Challenges` to `Challenge` and `ValidationRecords` to `ValidationRecord`. + * Changed the fields' type: `NotAfter` and `NotBefore` fields in the `DeploymentSchedule` structure used in the response for `GetChangeStatus` are `*string` instead of `string`. ## 2.17.0 (October 24, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * Datastream - * Add ListStreams - * Add new connectors: Elasticsearch, NewRelic and Loggly - * Extend Splunk and Custom HTTPS connectors mTLS certificates configuration - * Extend SumoLogic, Splunk and Custom HTTPS connectors with ability to specify custom HTTP headers + * Added the `ListStreams` method. + * Added new connectors: `Elasticsearch`, `NewRelic`, and `Loggly`. + * Extended the Splunk and Custom HTTPS connectors mTLS certificates configuration. + * Extended the SumoLogic, Splunk, and Custom HTTPS connectors with the ability to specify custom HTTP headers. -#### BUG FIXES: +### BUG FIXES: * APPSEC - * Fix incorrect JSON sent when applying appsec_ip_geo resource in allow mode + * Fixed an incorrect JSON sent when applying the `appsec_ip_geo` resource in allow mode. ## 2.16.0 (September 26, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Add interfaces to support file malware scanning (FMS): - * MalwareContentTypes - * MalwarePolicy - * MalwarePolicyAction - * MalwareProtection - * Add GetRuleRecommendations method to TuningRecommendations interface - * Add deprecation notes for these: + * Added new interfaces to support file malware scanning (FMS): + * `MalwareContentTypes` + * `MalwarePolicy` + * `MalwarePolicyAction` + * `MalwareProtection` + * Added the `GetRuleRecommendations` method to the `TuningRecommendations` interface. + * Added the deprecation notes for these: * methods: - * GetIPGeoProtections - * GetNetworkLayerProtections - * GetRateProtections - * GetReputationProtections - * GetSlowPostProtectionSetting - * GetSlowPostProtections - * GetWAFProtections - * RemoveNetworkLayerProtection - * RemovePolicyProtections - * RemoveReputationProtection - * structs: - * GetIPGeoProtectionsRequest - * GetNetworkLayerProtectionsRequest - * GetRateProtectionsRequest - * GetReputationProtectionsRequest - * GetSlowPostProtectionSettingRequest - * GetSlowPostProtectionSettingResponse - * GetSlowPostProtectionsRequest - * GetWAFProtectionsRequest - * RemoveNetworkLayerProtectionRequest - * RemovePolicyProtectionsRequest - * RemoveReputationProtectionRequest - -* [IMPORTANT] Added Bot Management API Support + * `GetIPGeoProtections` + * `GetNetworkLayerProtections` + * `GetRateProtections` + * `GetReputationProtections` + * `GetSlowPostProtectionSetting` + * `GetSlowPostProtections` + * `GetWAFProtections` + * `RemoveNetworkLayerProtection` + * `RemovePolicyProtections` + * `RemoveReputationProtection` + * structures: + * `GetIPGeoProtectionsRequest` + * `GetNetworkLayerProtectionsRequest` + * `GetRateProtectionsRequest` + * `GetReputationProtectionsRequest` + * `GetSlowPostProtectionSettingRequest` + * `GetSlowPostProtectionSettingResponse` + * `GetSlowPostProtectionsRequest` + * `GetWAFProtectionsRequest` + * `RemoveNetworkLayerProtectionRequest` + * `RemovePolicyProtectionsRequest` + * `RemoveReputationProtectionRequest` + +* [IMPORTANT] Added Bot Management API Support: * Akamai Bot Category - read * Akamai Bot Category Action - read, update * Akamai Defined Bot - read @@ -1025,32 +1029,32 @@ ## 2.15.0 (August 22, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Add xff field to custom rule conditions - * Add NotificationEmails to Activation struct + * Added the `xff` field to the custom rule conditions. + * Added the `NotificationEmails` field to the `Activation` structure. * GTM - * Improved error messages + * Improved error messages. * CPS - * Add cps ListEnrollments - * Extend CreateEnrollment with AllowDuplicateCN option + * Added cps ListEnrollments. + * Extended `CreateEnrollment` with the `AllowDuplicateCN` option. ## 2.14.1 (July 26, 2022) -#### BUG FIXES: +### BUG FIXES: * IAM - * Change IAM GroupID type to int64 + * Changed the IAM `GroupID` type to `int64`. ## 2.14.0 (June 28, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Added penalty box support for security policy in evaluation mode + * Added the penalty box support for the security policy in evaluation mode. * HAPI * EdgeHostname - update @@ -1061,42 +1065,43 @@ * Role - create, read, update, delete * User - lock, unlock, TFA, set password, reset password -#### BUG FIXES: +### BUG FIXES: + * APPSEC - * Fixed incorrect error message on activation failure - * The `EffectiveTimePeriod`, `SamplingRate`, `LoggingOptions`, and `Operation` fields of the various `CustomRule` response structs are now marshalled correctly + * Fixed an incorrect error message on the activation failure. + * The `EffectiveTimePeriod`, `SamplingRate`, `LoggingOptions`, and `Operation` fields of the various `CustomRule` response structures are now marshaled correctly. ## 2.13.0 (May 31, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * Image and Video Manager - * Add new `ImQuery` transformation - * New `PostBreakPointTransformationType` + * Added the new `ImQuery` transformation. + * Added the new `PostBreakPointTransformationType`. -#### BUG FIXES: +### BUG FIXES: * Image and Video Manager - * `default_value` field on variable in image policy should not be required - * Change all primitive optional parameters to pointers - * Correct `Anchor` field in `RectangleShapeType` - * Value field for `NumberVariableInline` should be defined as `float64` - * Rename `PointShapeType.True` to `PointShapeType.Y`, to match the OpenAPI definition - * Add `Composite` transformation to `PostBreakpointTransformations` - * Fix `PostBreakpointTransformations.PolicyInputImage` + * The `default_value` field on variable in image policy should not be required. + * Changed all primitive optional parameters to pointers. + * Corrected the `Anchor` field in `RectangleShapeType`. + * Value field for `NumberVariableInline` should be defined as `float64`. + * Renamed `PointShapeType.True` to `PointShapeType.Y`, to match the OpenAPI definition. + * Added the `Composite` transformation to `PostBreakpointTransformations`. + * Fixed `PostBreakpointTransformations.PolicyInputImage`. ## 2.12.0 (Apr. 25, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Add WAPBypassNetworkLists interface, to be used in preference to deprecated BypassNetworkLists interface + * Added the `WAPBypassNetworkLists` interface, to be used in preference to the deprecated `BypassNetworkLists` interface. -* Support for account switch keys from environment ([#149](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/pull/149)) +* Added support for the account switch keys from environment ([#149](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/pull/149)). ## 2.11.0 (March 24, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * [IMPORTANT] Added Image and Video Manager API support * Policy Set - create, read, update, delete @@ -1110,9 +1115,9 @@ ## 2.10.0 (Feb. 28, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: -* [IMPORTANT] Added EdgeWorkers and EdgeKV API support +* [IMPORTANT] Added EdgeWorkers and EdgeKV API support: * EDGEWORKERS * Ids - create, read, update, delete, clone * Versions - create, read, delete, validate version bundle @@ -1131,44 +1136,45 @@ * Access token - create, read, delete * APPSEC - * Source for evasive path match interface updated with links to documentation + * Updated the source for the evasive path match interface with links to documentation. * CLOUDLETS - * Support for AS cloudlet type (Audience Segmentation) + * Added support for the AS (Audience Segmentation) cloudlet type. ## 2.9.1 (Feb. 7, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * APPSEC - * Remove deprecation notes for individual policy protection methods + * Removed the deprecation notes for individual policy protection methods. -#### BUG FIXES: +### BUG FIXES: * CLOUDLETS - * Fixed validation for ALB version DataCenter percent + * Fixed validation for the ALB version DataCenter percent. ## 2.9.0 (Jan. 24, 2022) -#### FEATURES/ENHANCEMENTS: +### FEATURES/ENHANCEMENTS: * CLOUDLETS - * Support for VP cloudlet type (Visitor Prioritization) - * Support for CD cloudlet type (Continuous Deployment / Phased Release) - * Support for FR cloudlet type (Forward Rewrite) - * Support for AP cloudlet type (API Prioritization) + * Added support for VP cloudlet type (Visitor Prioritization). + * Added support for CD cloudlet type (Continuous Deployment / Phased Release). + * Added support for FR cloudlet type (Forward Rewrite). + * Added support for AP cloudlet type (API Prioritization). * APPSEC - * Add support for Evasive Path Match feature - * Deprecate individual policy protection interface methods + * Added support for Evasive Path Match feature. + * Deprecated the individual policy protection interface methods. * NETWORK LISTS - * Include ContractID and GroupID in GetNetworkListResponse + * Included `ContractID` and `GroupID` in `GetNetworkListResponse`. ## 2.8.1 (Nov. 30, 2021) -#### FEATURES/ENHANCEMENTS: -* [IMPORTANT] Added Cloudlets API support +### FEATURES/ENHANCEMENTS: + +* [IMPORTANT] Added Cloudlets API support: * Policy (Application Load Balancer) - create, read, update, delete policy * Policy (Edge Redirector) - create, read, update, delete policy * Policy activation - create, read @@ -1176,99 +1182,108 @@ * Activation for Application Load Balancer configuration - create, read * APPSEC - * Add support for advanced exceptions in ASE rules - * Update bypass-network-list datasource and resource for multi-policy WAP + * Added support for advanced exceptions in ASE rules. + * Updated the `bypass-network-list` data source and resource for the multi-policy WAP. ## 2.7.0 (Oct 19, 2021) -#### FEATURES/ENHANCEMENTS: -* [IMPORTANT] Added DataStream API support +### FEATURES/ENHANCEMENTS: + +* [IMPORTANT] Added the DataStream API support: * Stream operations * Stream activation operations * Read access to various DataStream properties -* Added HAPI v1 support +* Added the HAPI v1 support: * Delete edge hostname ## 2.6.0 (Aug 16, 2021) -#### BUG FIXES: +### BUG FIXES: + * APPSEC - * Fix incorrect comments/URL references in inline documentation + * Fixed incorrect comments/URL references in inline documentation. + +### FEATURES/ENHANCEMENTS -#### FEATURES/ENHANCEMENTS * APPSEC - * Get an evaluation attack group's or risk score group's action + * Got an evaluation attack group's or risk score group's action. * NETWORK LISTS - * Support contract_id and group_id for network list create/update + * Added support for `contract_id` and `group_id` for network list create/update. ## 2.5.0 (Jun 15, 2021) -#### BREAKING CHANGES: +### BREAKING CHANGES: + * APPSEC - * The following have been removed, together with their unit tests and test data: - * pkg/appsec/attack_group_action.go - * pkg/appsec/attack_group_condition_exception.go - * pkg/appsec/eval_rule_action.go - * pkg/appsec/eval_rule_condition_exception.go - * pkg/appsec/rule_action.go - * pkg/appsec/rule_condition_exception.go - -#### BUG FIXES: + * Removed these packages along with their unit tests and test data: + * `pkg/appsec/attack_group_action.go` + * `pkg/appsec/attack_group_condition_exception.go` + * `pkg/appsec/eval_rule_action.go` + * `pkg/appsec/eval_rule_condition_exception.go` + * `pkg/appsec/rule_action.go` + * `pkg/appsec/rule_condition_exception.go` + +### BUG FIXES: + * DNSv2 * Fixed parsing SVCB, HTTPS rdata. -#### FEATURES/ENHANCEMENTS: -* [IMPORTANT] CPS - Added Certificate Provisioning API support +### FEATURES/ENHANCEMENTS: + +* [IMPORTANT] CPS - Added Certificate Provisioning API support: * Enrollments - create, read, update, delete enrollments * Change status API - get change status, cancel change * DV certificate API - get and acknowledge DV challenges * Pre verification warnings - get and acknowledge pre verification warnings * APPSEC - * The following have been added, together with their unit tests and test data: - * pkg/appsec/api_constraints_protection.go - * pkg/appsec/advanced_settings_pragma_header.go - * pkg/appsec/attack_group.go - * pkg/appsec/eval_rule.go - * pkg/appsec/rule.go - * pkg/appsec/ip_geo_protection.go + * Removed these packages along with their unit tests and test data: + * `pkg/appsec/api_constraints_protection.go` + * `pkg/appsec/advanced_settings_pragma_header.go` + * `pkg/appsec/attack_group.go` + * `pkg/appsec/eval_rule.go` + * `pkg/appsec/rule.go` + * `pkg/appsec/ip_geo_protection.go` ## 2.4.1 (Apr 19, 2021) -#### BUG FIXES: +### BUG FIXES: * APPSEC - * Suppress 'null' text on output of empty/false values - * Prevent configuration drift when reapplying configuration after importing or creating resources + * Suppressed the 'null' text on output of empty/false values. + * Prevented configuration drift when reapplying configuration after importing or creating resources. ## 2.4.0 (Mar 29, 2021) PAPI - Secure by default * PAPI - * Support to provision default certs as part of hostnames request - * New cert status object in hostnames response if it exists + * Added support to provision default certs as part of the hostname request. + * Added a new cert status object in the hostname response if it exists. ## 2.3.0 (Mar 15, 2021) Network Lists -Add support for the these operations in the Network Lists API v2: +Added support for the these operations in the Network Lists API v2: -* Create a network list -* Update an existing network list -* Get the existing network lists, including optional filtering by name or type -* Subscribe to a network list -* Activate a network list +* Create a network list. +* Update an existing network list. +* Get the existing network lists, including optional filtering by name or type. +* Subscribe to a network list. +* Activate a network list. ## 2.2.1 (Mar 3, 2021) -* PAPI - Fixed issue with rules causing advanced locked behaviors to fail + +* PAPI - Fixed an issue with rules causing advanced locked behaviors to fail. ## 2.2.0 (Feb 23, 2021) APPSEC - Extended list of supported list endpoints from APPSEC API -#### BUG FIXES: +### BUG FIXES: + * PAPI - * Fixed issue with version and rule comments being dropped - * Fixed client side validation to allow certain PAPI errors to passthrough + * Fixed an issue with the version and rule comments being dropped. + * Fixed client side validation to allow certain PAPI errors to pass through. + +### FEATURES/ENHANCEMENTS: -#### FEATURES/ENHANCEMENTS: * APPSEC * Custom Deny * SIEM Setting @@ -1284,91 +1299,107 @@ Add support for the these operations in the Network Lists API v2: * Clone Security Configuration * Import tool for adding existing resources to Terraform state * DNS - * Add support for HTTPS, SVCB records to ParseRData + * Added support for HTTPS, SVCB records to ParseRData. ## 2.1.1 (Feb 3, 2021) -* PAPI - Fixed validation on empty rule behaviors causing some properties with nested behaviors to fail + +* PAPI - Fixed validation on empty rule behaviors causing some properties with nested behaviors to fail. ## 2.1.0 (Jan 13, 2021) -* [IMPORTANT] IAM - New Identity and Access Management API Support + +* [IMPORTANT] IAM - New Identity and Access Management API Support. ## 2.0.4 (Dec 23, 2020) -* APPSEC - Extended list of supported endpoints from APPSEC API: - * DDoS Protection -- Rate Policy & Action - * DDoS Protection -- Slowpost setting & Action - * Application Layer Protection -- Rule Action, Exceptions & Conditions - * Application Layer Protection -- Rule Evaluation Action, Exceptions & Conditions - * Application Layer Protection -- Attack Group Action, Exceptions & Conditions - * Application Layer Protection -- Rule Upgrade & Change Mode for Rule Eval + +* APPSEC - Extended list of supported endpoints from the APPSEC API: + * DDoS Protection - Rate Policy & Action + * DDoS Protection - Slowpost setting & Action + * Application Layer Protection - Rule Action, Exceptions & Conditions + * Application Layer Protection - Rule Evaluation Action, Exceptions & Conditions + * Application Layer Protection - Attack Group Action, Exceptions & Conditions + * Application Layer Protection - Rule Upgrade & Change Mode for Rule Eval * Reputation Profile & Action - * Network Layer Control -- IP & GEO setting + * Network Layer Control - IP & GEO setting ## 2.0.3 (Dec 7, 2020) -* PAPI - Property hostname validation fix for missing hostnames. -* PAPI - fix minor typo in rules error messages + +* PAPI - fixed property hostname validation for missing hostnames. +* PAPI - fixed minor typos in rules error messages. ## 2.0.2 (Nov 19, 2020) -* [IMPORTANT] APPSEC - Added Application Security API -* [ENHANCEMENT] DNS - Bulk Api endpoints added -* ALL - Re-enabled global account switch key support in edgerc files + +* [IMPORTANT] APPSEC - added the Application Security API. +* [ENHANCEMENT] DNS - added the Bulk API endpoints. +* ALL - re-enabled global account switch key support in the `.edgerc` files. * PAPI - Edgehostname IPV6 support fix. Added enums with allowed values. -* PAPI - Edgehostname blank cname or egdehostname id fix -* PAPI - propertyversion blank etag field fix +* PAPI - Edgehostname blank cname or egdehostname id fix. +* PAPI - propertyversion blank etag field fix. ## 2.0.1 (Oct 15, 2020) -* [IMPORTANT] Breaking changes from earlier clients. Project updated to use v2 directory structure. -* [ENHANCEMENT] PAPI - Api error return to the user when an activation or validation error occurs. -* [NOTE] Project re-organized to prepare for additional APIs to be included in future versions of this library. + +* [IMPORTANT] Breaking changes from earlier clients. Updated the library to use the v2 directory structure. +* [ENHANCEMENT] PAPI - API error returns to the user when an activation or validation error occurs. +* [NOTE] Reorganized the library to prepare for additional APIs to be included in future versions. ## 1.0.0 (Oct 15, 2020) -* Official release for the EdgeGrid Golang library -* DNSv2 - Zone create signature to pass blank instead of nil -* PAPI - Return nil instead of error if no cp code was found -* GTM - Datacenter API requires blank instead of nil + +* Official release for the EdgeGrid Golang library. +* DNSv2 - Zone create signature to pass blank instead of nil. +* PAPI - Return nil instead of error if no cp code was found. +* GTM - Datacenter API requires blank instead of nil. ## 0.9.18 (Jul 13, 2020) -* [AT-40][Add] Preliminary Logging CorrelationID + +* [AT-40][Add] Preliminary Logging CorrelationID. ## 0.9.17 (Jun 9, 2020) -* Corrected AKAMAICDN target parsing -* Added endpoints for list zones, creating and updating multiple recordsets -* Refactored recordsets into separate source file + +* Corrected AKAMAICDN target parsing. +* Addeded endpoints for listing zones, creating, and updating multiple recordsets. +* Refactored recordsets into a separate source file. ## 0.9.16 (May 29, 2020) -* Client-v1, Papi-v1 Updates -* Add lock around http request creation. -* papi - add logging to papi endpoints. + +* Added updates to Client-v1, Papi-v1. +* Added a lock around the http request creation. +* PAPI - added logging to PAPI endpoints. ## 0.9.15 (May 15, 2020) -* DNSv2 - Added CERT, TSLA Record parsing. Removed MX Record parsing + +* DNSv2 - Added CERT and TSLA record parsing. Removed MX record parsing. ## 0.9.14 (May 12, 2020) -* DNSv2 - Enhance RecordError functions + +* DNSv2 - Enhanced the RecordError functions. ## 0.9.13 (Apr 26, 2020) -* DNSv2 - filterZoneCreate check upper case Type + +* DNSv2 - filterZoneCreate check upper case Type. ## 0.9.12 (Apr 21, 2020) -* DNSv2 - Added optional arg to bypass dns record lock for create, update and delete functions. default preserves prior behavior + +* DNSv2 - Added an optional `arg` to bypass dns record lock for the create, update, and delete functions. The default preserves the prior behavior. ## 0.9.11 (Apr 13 , 2020) -* DNSv2 Updates - * Add additional fields, including TSIG, to zone - * Support alias zone types - * Add utility functions for Rdata parsing and process. - * Add GetRecord, GetRecordSet functions - * Add additional Recordset metadata -* Add http request/response logging + +* DNSv2 Updates: + * Added additional fields, including TSIG, to a zone. + * Added support for alias zone types. + * Added the utility functions for rdata parsing and process. + * Added the `GetRecord` and `GetRecordSet` functions. + * Add an additional recordset metadata. +* Added http request/response logging. ## 0.9.10 (Mar 5, 2020) -* Add support for caching Edgehostnames and Products -* Support for cache in papi library for edgehostnames and products to minimize round trips to fetch repeated common data to avoid - WAF deny rule IPBLOCK-BURST4-54013 issue + +* Added support for caching Edgehostnames and Products. +* Added support for cache in PAPI library for edgehostnames and products to minimize round trips to fetch repeated common data to avoid the WAF deny rule IPBLOCK-BURST4-54013 issue. ## 0.9.9 (Feb 29, 2020) -* Add support for caching Contract, Groups, and Cp Codes -* cache to minimize round trips on repeated common data fetches to avoid - WAF deny rule IPBLOCK-BURST4-54013 issue + +* Added support for caching Contract, Groups, and Cp Codes. +* cache to minimize round trips on repeated common data fetches to avoid the WAF deny rule IPBLOCK-BURST4-54013 issue. ## 0.9.0 (Aug 6, 2019) -* Added support for GTM + +* Added support for GTM. diff --git a/LICENSE b/LICENSE index 8dada3ed..4ca16d15 100644 --- a/LICENSE +++ b/LICENSE @@ -186,10 +186,10 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright 2024 Akamai Technologies, Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. + you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 diff --git a/README.md b/README.md index 814c4d22..7c7dbada 100644 --- a/README.md +++ b/README.md @@ -6,23 +6,851 @@ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://pkg.go.dev/badge/github.com/akamai/akamaiOPEN-edgegrid-golang?utm_source=godoc)](https://pkg.go.dev/github.com/akamai/AkamaiOPEN-edgegrid-golang/v9) -This module is presently in active development and provides Akamai REST API support for the Akamai Terraform Provider. +The library implements an Authentication handler for HTTP requests using the [Akamai EdgeGrid Authentication](https://techdocs.akamai.com/developer/docs/authenticate-with-edgegrid) scheme for Go. It also currently provides Akamai REST API support for the Akamai Terraform Provider. -## Backward Compatibility -This module is not backward compatible with the version `v1`. +## Backward compatibility -Originally branch `master` was representing version `v1`. Now it is representing the latest version `v9` and -version `v1` -was moved to dedicated `v1` branch. +This module isn't backward compatible with `v1`. -## Concurrent Usage +The `master` branch isn't representing `v1` anymore, it's currently representing the latest `v9`. `v1` has been moved to a dedicated `v1` branch. -The packages of library can be imported alongside the `v1` library versions without conflict, for example: +## Concurrent usage +You can import the library packages alongside the `v1` library without any conflict. For example: + +```go +import ( + papiv1 "github.com/akamai/AkamaiOPEN-edgegrid-golang/papi-v1" + papi "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/papi" +) ``` + +## Install + +To use the library, you need to have Go 1.21+ installed on your system. + + +## Authentication + +You can obtain the authentication credentials through an API client. Requests to the API are marked with a timestamp and a signature and are executed immediately. + +1. [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials). + +2. Place your credentials in an EdgeGrid file `~/.edgerc`, in the `[default]` section. + + ``` + [default] + client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN= + host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net + access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij + client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj + ``` + +3. Import the `edgegrid` package, then use your local `.edgerc` by providing the path to your resource file and credentials' section header in the `edgegrid.New()` method. + + ```go + package main + + import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + ) + + func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("path/to/.edgerc"), + edgegrid.WithSection("section-header"), + ) + ... + } + ``` + +### Load from environment variables + +Alternatively, you can pass your credentials to the environment variables. The library will look for the environment variables only if you use the `WithEnv()` method and set it to `true`. By default, it uses these variables: + +- `AKAMAI_HOST` +- `AKAMAI_CLIENT_TOKEN` +- `AKAMAI_CLIENT_SECRET` +- `AKAMAI_ACCESS_TOKEN` +- `AKAMAI_MAX_BODY` + +You can define multiple configurations by specifying the credentials' section header as an interfix that you insert between `AKAMAI_` and the credential name. The `WithEnv()` method uses the credentials' section header configured with the `WithSection()` method or it uses `default` if the credentials' section header wasn't configured. + +For example, when passing `ccu` as the credentials' section header in the `WithSection()` method, the function will look for `AKAMAI_CCU_HOST`. + +If the variable doesn't exist but the library was configured to search for it, the function either returns as only partially configured or it falls back to the filing data from the `.edgerc` file if you also used the `WithFile()` method. + +```go +package main + + import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + ) + + func main() { + // Load from AKAMAI_CCU_ + edgerc, err := edgegrid.New( + edgegrid.WithEnv(true), + edgegrid.WithSection("ccu"), + ) + ... + } +``` + +## Use as an auth signer + +Import the `edgegrid` package to sign your requests. Provide the path to your `.edgerc`, your credentials' section header, and the appropriate endpoint information. + +### Example + +```go +package main + +import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) +} +``` + +### Query string parameters + +Pass the query parameters in the url after a question mark ("?") at the end of the main URL path. + +```go +package main + import ( - papiv1 "github.com/akamai/AkamaiOPEN-edgegrid-golang/papi-v1" - papi "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/papi" + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" ) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile?authGrants=true¬ifications=true&actions=true", nil) +... +} ``` + +Alternatively, you can use one of these methods: + +- [`req.URL.Query()`](https://pkg.go.dev/net/url#URL.Query). To add specific query params to an existing query. +- [`url.Values{}`](https://pkg.go.dev/net/url#Values.Add). To build a new set of params. Requires importing the `net/url` package. + +```go +package main + +import ( + "fmt" + "io" + "net/http" + "net/url" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + if err != nil { + fmt.Println(err) + return + } + + // If appending to an existing query + q := req.URL.Query() + q.Add("authGrants", "true") + q.Add("notifications", "true") + q.Add("actions", "true") + + // Or if building a new set of params + q := url.Values{} + q.Add("authGrants", "true") + q.Add("notifications", "true") + q.Add("actions", "true") + + req.URL.RawQuery = q.Encode() + + fmt.Println(req.URL.String()) + // Output: + // /identity-management/v3/user-profile?actions=true&authGrants=true¬ifications=true + + edgerc.SignRequest(req) + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) +} +``` + +### Headers + +Enter request headers using the `req.Header.Add()` method. + +> **Note:** You don't need to include the `Content-Type` and `Accept` headers. The authentication layer adds these values. + +```go +package main + +import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) +... +} +``` + +### Body data + +Import the `strings` package and provide the request body as an object in the `payload` property. + +```go +package main + +import ( + "fmt" + "io" + "net/http" + "strings" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + payload := strings.NewReader(`{ + "contactType": "Billing", + "country": "USA", + "firstName": "John", + "lastName": "Smith", + "preferredLanguage": "English", + "sessionTimeOut": 30, + "timeZone": "GMT", + "phone": "3456788765" + }`) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodPut, "/identity-management/v3/user-profile/basic-info", payload) +... +} +``` + +### Debug + +Enable debugging to get additional information about a request and response. + +You may find using `fmt.Println()` not sufficient, as the output isn't formatted and is difficult to read. + +To pretty-print the HTTP request and response, use these methods: + +- [`httputil.DumpRequest()`](https://pkg.go.dev/net/http/httputil#DumpRequest). To pretty-print the request on the server side. +- [`httputil.DumpRequestOut()`](https://pkg.go.dev/net/http/httputil#DumpRequestOut). To dump the request on the client side. +- [`httputil.DumpResponse()`](https://pkg.go.dev/net/http/httputil#DumpResponse). To log the server response. + +In each of these functions, the second argument is a flag indicating if the body of the request/response should also be returned. + +```go +package main + +import ( + "fmt" + "log" + "net/http" + "net/http/httputil" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + if err != nil { + log.Fatal(err) + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) + + reqDump, err := httputil.DumpRequestOut(req, false) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("REQUEST:\n%s", string(reqDump)) + + res, err := client.Do(req) + if err != nil { + log.Fatal(err) + } + + resDump, err := httputil.DumpResponse(res, true) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("RESPONSE:\n%s", string(resDump)) +} +``` + +## Use with the `session` + +When making a call with the [auth signer approach](#use-as-an-auth-signer), you can add the `session` package to log additional information about the call. You can also define the `struct` for the requested object as a variable in that call, or you can omit the `struct` and define the requested object as an any type variable with the `any` keyword. + +```go +package main + +import ( + "fmt" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, _ := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + var userProfile struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + UserName string `json:"uiUserName"` + TimeZone string `json:"timeZone"` + Country string `json:"country"` + PreferredLanguage string `json:"preferredLanguage"` + SessionTimeOut *int `json:"sessionTimeOut"` + } + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + if err != nil { + fmt.Println(err) + return + } + + result, err := sess.Exec(req, &userProfile) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(result, userProfile) +} +``` + +The `session` package also supports the structured logging interface from `github.com/apex`. Thanks to this, you can create a custom logger in one of these ways: + +- Apply a logger globally to the session with the `session.WithLog()` method. + + > **Note:** This method works also with the [SDK approach](#use-as-an-sdk). + + ```go + package main + + import ( + "fmt" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" + "github.com/apex/log" + ) + + type CustomHandler struct { + } + + func (CustomHandler) HandleLog(entry *log.Entry) error { + fmt.Printf("#|||### %s ###|||#", entry) // It's a dummy handler. Don't use it in your production code. + return nil + } + + func main() { + edgerc, _ := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + l := &log.Logger{ + Handler: CustomHandler{}, + Level: log.InfoLevel, + } + sess, _ := session.New( + session.WithSigner(edgerc), + session.WithLog(l), + ) + + var userProfile struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + UserName string `json:"uiUserName"` + TimeZone string `json:"timeZone"` + Country string `json:"country"` + PreferredLanguage string `json:"preferredLanguage"` + SessionTimeOut *int `json:"sessionTimeOut"` + } + + req, _ := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + + result, err := sess.Exec(req, &userProfile) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(result, userProfile) + } + ``` + +- Overwrite a default logger for a specific request with the `req.WithContext()` method. + + > **Note:** This method doesn't work with the [SDK approach](#use-as-an-sdk). + + ```go + package main + + import ( + "fmt" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" + "github.com/apex/log" + ) + + type CustomHandler struct { + } + + func (CustomHandler) HandleLog(entry *log.Entry) error { + fmt.Printf("#|||### %s ###|||#", entry) // It's a dummy handler. Don't use it in your production code. + return nil + } + + func main() { + edgerc, _ := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + l := &log.Logger{ + Handler: CustomHandler{}, + Level: log.InfoLevel, + } + sess, _ := session.New( + session.WithSigner(edgerc), + ) + + var userProfile struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + UserName string `json:"uiUserName"` + TimeZone string `json:"timeZone"` + Country string `json:"country"` + PreferredLanguage string `json:"preferredLanguage"` + SessionTimeOut *int `json:"sessionTimeOut"` + } + + req, _ := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + + req = req.WithContext(session.ContextWithOptions(req.Context(), session.WithContextLog(l))) + + result, err := sess.Exec(req, &userProfile) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(result, userProfile) + } + ``` + +If you don't provide a custom logger, the library will use its default logger included in the `session.New()` method. + +### Custom request headers + +When using the `session` package with the [auth signer approach](#use-as-an-auth-signer), you can update the context to pass custom request headers in the `session.WithContextHeaders()` method. + +```go +package main + +import ( + "fmt" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, _ := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + sess, _ := session.New( + session.WithSigner(edgerc), + ) + + var userProfile struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + UserName string `json:"uiUserName"` + TimeZone string `json:"timeZone"` + Country string `json:"country"` + PreferredLanguage string `json:"preferredLanguage"` + SessionTimeOut *int `json:"sessionTimeOut"` + } + + req, _ := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + + customHeader := make(http.Header) + customHeader.Set("X-Custom-Header", "some custom value") + + req = req.WithContext(session.ContextWithOptions(req.Context(), session.WithContextHeaders(customHeader))) + + result, err := sess.Exec(req, &userProfile) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(result, userProfile) +} +``` + +### Retries + +With the `session` package, you can use the `session.WithRetries()` option for creating new sessions with global GET retries. You can set up this option using its default configuration or customize it with these parameters: + +- `RetryMax`. The maximum number of API request retries. +- `RetryWaitMin`. The minimum wait time in `time.Duration` between API requests retries. +- `RetryWaitMax`. The maximum wait time in `time.Duration` between API requests retries. +- `ExcludedEndpoints`. The list of path expressions defining endpoints which should be excluded from the retry feature. + +> **Note** This option works also with the [SDK approach](#use-as-an-sdk). + +```go +package main + +import ( + "fmt" + "net/http" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, _ := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + // The retries feature with default configuration. + sess, err := session.New( + session.WithSigner(edgerc), + session.WithRetries(session.NewRetryConfig()), + ) + + // The retries feature with custom configuration. + sess, err := session.New( + session.WithSigner(edgerc), + session.WithRetries(session.RetryConfig{ + RetryMax: 5, + RetryWaitMax: time.Minute * 2, + RetryWaitMin: time.Second * 3, + }), + ) + if err != nil { + fmt.Println(err) + return + } + + var userProfile struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + UserName string `json:"uiUserName"` + TimeZone string `json:"timeZone"` + Country string `json:"country"` + PreferredLanguage string `json:"preferredLanguage"` + SessionTimeOut *int `json:"sessionTimeOut"` + } + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/user-profile", nil) + if err != nil { + fmt.Println(err) + return + } + + result, err := sess.Exec(req, &userProfile) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(result, userProfile) +} +``` + +## Use as an SDK + +Apart from signing the requests with the `edgegrid` package, you can use specific API clients and methods from this library. + +### Overview of packages + +To see what methods you can use within a given package, go to the `pkg` directory and select the package name. Each package contains: + +- A file named after a package name or the package's abbreviated name with a main `interface`. +- The main `interface` can contain its own methods or other `interfaces` with their own methods. +- `struct` blocks distributed across the package's files, each containing a list of parameters you can pass in a given method. + +| Package | Description | +|----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------| +| [Application Security](./pkg/appsec/) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | +| [Bot Manager](./pkg/botman/) | Identify, track, and respond to bot activity on your domain or in your app. | +| [Certificate Provisioning System](./pkg/cps/) | Manage the full life cycle of SSL certificates for your ​Akamai​ CDN applications. | +| [Client Lists](./pkg/clientlists/) | Reduce harmful security attacks by allowing only trusted IP/CIDRs, locations, autonomous system numbers, and TLS fingerprints to access your services and content.| +| [Cloud Access Manager](./pkg/cloudaccess/) | Enable cloud origin authentication and securely store and manage your cloud origin credentials as access keys. | +| [Cloudlets](./pkg/cloudlets/) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | +| [Cloud Wrapper](./pkg/cloudwrapper/) | Provide your customers with a more consistent user experience by adding a custom caching layer that improves the connection between your cloud infrastructure and the Akamai platform.| +| [DataStream](./pkg/datastream/) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | +| [Edge DNS](./pkg/dns/) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | +| [EdgeGrid](./pkg/edgegrid/) | Parse the Akamai `.edgerc` configuration and sign HTTP requests. | +| [EdgeGrid Errors](./pkg/edgegriderr/) | Parse validation errors to make them more readable. | +| [Edge Hostnames](./pkg/hapi/) | Manage how requests for your site, app, or content map to Akamai edge servers. | +| [EdgeWorkers](./pkg/edgeworkers/) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | +| [Errors](./pkg/errs/) | Use utilities for working with errors during JSON data unmarshalling. | +| [Global Traffic Management](./pkg/gtm/) | Use load balancing to manage website and mobile performance demands. | +| [Identity and Access Management](./pkg/iam/) | Create users and groups, and define policies that manage access to your Akamai applications. | +| [Image and Video Manager](./pkg/imaging/) | Automate image and video delivery optimizations for your website visitors. | +| [Network Lists](./pkg/networklists/) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | +| [Pointer Record](./pkg/ptr/) | Create pointers to values of any type. | +| [Property Manager](./pkg/papi/) | Define rules and behaviors that govern your website delivery based on match criteria. | +| [Session](./pkg/session/) | Manage the base secure HTTP client and requests for Akamai APIs. | + +### Example + +To use the library as an SDK, import the `edgegrid` package to sign your requests, the `session` package, and a specific package available in this library (for example, `iam`) to use the methods included in that package. Provide the path to your `.edgerc`, your credentials' section header, and refer to a specific API client and method. + +```go +package main + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/iam" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + if err != nil { + fmt.Println(err) + return + } + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + client := iam.Client(sess) + + resp, err := client.GetUser(context.TODO(), iam.GetUserRequest{IdentityID: "A-BC-1234567"}) + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(resp) +} +``` + +### Headers + +You don't need to add any required or optional headers to a request. The authentication layer adds these values automatically for you. + +### Query string parameters and body data + +Depending on the method type, use `structs` of the provided API `struct` to pass query parameters and body data within a request method. + +```go +package main + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/iam" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + if err != nil { + fmt.Println(err) + return + } + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + client := iam.Client(sess) + + sessTimeOut := 14400 + + resp, err := client.UpdateUserInfo( + context.TODO(), + iam.UpdateUserInfoRequest{ + IdentityID: "A-BC-123456", + User: iam.UserBasicInfo{ + Country: "USA", + FirstName: "John", + LastName: "Smith", + Phone: "3456788765", + PreferredLanguage: "English", + SessionTimeOut: &sessTimeOut, + TimeZone: "GMT", + }, + }, + ) + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(resp) +} +``` + +## Reporting issues + +To report an issue or make a suggestion, create a new [GitHub issue](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/issues). + +## License + +Copyright 2024 Akamai Technologies, Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..41571b31 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,90 @@ +# Examples + +This directory contains executable CRUD examples for Akamai API using the EdgeGrid Go library as an auth signer and SDK. API calls used in these examples are available to all users. But, if you find one of the write examples doesn't work for you, talk with your account's admin about your privilege level. + +## Run + +To run any of the files: + +1. Specify the location of your `.edgerc` file and the section header for the set of credentials you'd like to use. The default is `default`. +2. For update and delete operations, replace the dummy `credentialId` with your valid `credentialId`. + + >**Important:** Don't use your actual credentials for the update (inactivation) and delete operations. Otherwise, you'll block your access to the Akamai APIs. + +3. Open a Terminal or shell instance and run the .go file. + + ``` + $ go run examples///.go + ``` + +## Sample files + +The example in each file contains a call to one of the Identity and Access Management (IAM) API endpoints. See the [IAM API reference](https://techdocs.akamai.com/iam-api/reference/api) doc for more information on each of the calls used. + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OperationMethodEndpoint
+ List your API client credentials. + + + + + +
Run as auth signerRun as SDK
+
GET/identity-management/v3/api-clients/self/credentials
+ Create new API client credentials.
This is a quick client and grants you the default permissions associated with your account. + + + + + +
Run as auth signerRun as SDK
+
POST/identity-management/v3/api-clients/self/credentials
+ Update your credentials by ID. + + + + + +
Run as auth signerRun as SDK
+
PUT/identity-management/v3/api-clients/self/credentials/{credentialId}
+ Delete your credentials by ID. + + + + + +
Run as auth signerRun as SDK
+
DELETE/identity-management/v3/api-clients/self/credentials/{credentialId}
+ +Suggested chained call order: + +1. Get credentials to see your base information. +2. Create a client to create a new set of credentials. +3. Update credentials to inactivate the newly created set from step 2. +4. Delete a client to delete the inactivated credentials. +5. Get credentials to verify if they're gone (the status will be `DELETED`). \ No newline at end of file diff --git a/examples/auth-signer/create/create-credentials.go b/examples/auth-signer/create/create-credentials.go new file mode 100644 index 00000000..0fe1a21e --- /dev/null +++ b/examples/auth-signer/create/create-credentials.go @@ -0,0 +1,55 @@ +// This example creates your new API client credentials. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Open a Terminal or shell instance and run "go run examples/auth-signer/create/create-credentials.go". +// +// A successful call returns a new API client with its `credentialId`. Use this ID in both the update and delete examples. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/post-self-credentials. + +package main + +import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodPost, "/identity-management/v3/api-clients/self/credentials", nil) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) +} diff --git a/examples/auth-signer/delete/delete-credentials.go b/examples/auth-signer/delete/delete-credentials.go new file mode 100644 index 00000000..968bce33 --- /dev/null +++ b/examples/auth-signer/delete/delete-credentials.go @@ -0,0 +1,59 @@ +// This example deletes your API client credentials. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Add the `credentialId` from the update example to the path. You can only delete inactive credentials. Sending the request on an active set will return a 400. Use the update credentials example for deactivation. +// +// **Important:** Don't use your actual credentials for this operation. Otherwise, you'll block your access to the Akamai APIs. +// +// 3. Open a Terminal or shell instance and run "go run examples/auth-signer/delete/delete-credentials.go". +// +// A successful call returns an empty response body. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/delete-self-credential. + +package main + +import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodDelete, "/identity-management/v3/api-clients/self/credentials/123456", nil) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) +} diff --git a/examples/auth-signer/get/get-credentials.go b/examples/auth-signer/get/get-credentials.go new file mode 100644 index 00000000..1082bac8 --- /dev/null +++ b/examples/auth-signer/get/get-credentials.go @@ -0,0 +1,55 @@ +// This example returns a list of your API client credentials. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Open a Terminal or shell instance and run "go run examples/auth-signer/get/get-credentials.go". +// +// A successful call returns your credentials grouped by `credentialId`. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/get-self-credentials. + +package main + +import ( + "fmt" + "io" + "net/http" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodGet, "/identity-management/v3/api-clients/self/credentials", nil) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) +} diff --git a/examples/auth-signer/update/update-credentials.go b/examples/auth-signer/update/update-credentials.go new file mode 100644 index 00000000..611ec9de --- /dev/null +++ b/examples/auth-signer/update/update-credentials.go @@ -0,0 +1,68 @@ +// This example updates the credentials from the create credentials example. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Add the `credentialId` for the set of credentials created using the create example as a path parameter. +// +// 3. Edit the `expiresOn` date to today's date. The date cannot be more than two years out or it will return a 400. Optionally, you can change the `description` value. +// +// **Important:** Don't use your actual credentials when inactivating them. Otherwise, you'll block your access to the Akamai APIs. +// +// 4. Open a Terminal or shell instance and run "go run examples/auth-signer/update/update-credentials.go". +// +// A successful call returns an object with modified credentials. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/put-self-credential. + +package main + +import ( + "fmt" + "io" + "net/http" + "strings" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + + payload := strings.NewReader(`{ + "description": "Update this credential", + "expiresOn": "2025-12-10T23:06:59.000Z", + "status": "INACTIVE" + }`) + + client := http.Client{} + + req, err := http.NewRequest(http.MethodPut, "/identity-management/v3/api-clients/self/credentials/123456", payload) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + edgerc.SignRequest(req) + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) +} diff --git a/examples/sdk/create/create-credentials.go b/examples/sdk/create/create-credentials.go new file mode 100644 index 00000000..24096b86 --- /dev/null +++ b/examples/sdk/create/create-credentials.go @@ -0,0 +1,53 @@ +// This example creates your new API client credentials. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Open a Terminal or shell instance and run "go run examples/sdk/create/create-credentials.go". +// +// A successful call returns a new API client with its `CredentialID`. Use this ID in both the update and delete examples. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/post-self-credentials. + +package main + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/iam" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + if err != nil { + fmt.Println(err) + return + } + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + client := iam.Client(sess) + + resp, err := client.CreateCredential(context.TODO(), iam.CreateCredentialRequest{}) + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(resp) +} diff --git a/examples/sdk/delete/delete-credentials.go b/examples/sdk/delete/delete-credentials.go new file mode 100644 index 00000000..95ff985e --- /dev/null +++ b/examples/sdk/delete/delete-credentials.go @@ -0,0 +1,53 @@ +// This example deletes your API client credentials. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Add the `CredentialID` from the update example to the path. You can only delete inactive credentials. Sending the request on an active set will return a 400. Use the update credentials example for deactivation. +// +// **Important:** Don't use your actual credentials for this operation. Otherwise, you'll block your access to the Akamai APIs. +// +// 3. Open a Terminal or shell instance and run "go run examples/sdk/delete/delete-credentials.go". +// +// A successful call returns an empty response body. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/delete-self-credential. + +package main + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/iam" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + if err != nil { + fmt.Println(err) + return + } + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + client := iam.Client(sess) + + resp := client.DeleteCredential(context.TODO(), iam.DeleteCredentialRequest{CredentialID: 123456}) + + fmt.Println(resp) +} diff --git a/examples/sdk/get/get-credentials.go b/examples/sdk/get/get-credentials.go new file mode 100644 index 00000000..7bd67316 --- /dev/null +++ b/examples/sdk/get/get-credentials.go @@ -0,0 +1,53 @@ +// This example returns a list of your API client credentials. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Open a Terminal or shell instance and run "go run examples/sdk/get/get-credentials.go". +// +// A successful call returns your credentials grouped by `CredentialID`. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/get-self-credentials. + +package main + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/iam" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + if err != nil { + fmt.Println(err) + return + } + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + client := iam.Client(sess) + + resp, err := client.ListCredentials(context.TODO(), iam.ListCredentialsRequest{}) + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(resp) +} diff --git a/examples/sdk/update/update-credentials.go b/examples/sdk/update/update-credentials.go new file mode 100644 index 00000000..1eabf6d9 --- /dev/null +++ b/examples/sdk/update/update-credentials.go @@ -0,0 +1,70 @@ +// This example updates the credentials from the create credentials example. +// +// To run this example: +// +// 1. Specify the path to your `.edgerc` file and the section header for the set of credentials to use. +// +// The defaults here expect the `.edgerc` at your home directory and use the credentials under the heading of `default`. +// +// 2. Add the `CredentialID` for the set of credentials created using the create example as a path parameter. +// +// 3. Edit the `ExpiresOn` date to today's date. The date cannot be more than two years out or it will return a 400. Optionally, you can change the `Description` value. +// +// **Important:** Don't use your actual credentials when inactivating them. Otherwise, you'll block your access to the Akamai APIs. +// +// 4. Open a Terminal or shell instance and run "go run examples/sdk/update/update-credentials.go". +// +// A successful call returns an object with modified credentials. +// +// For more information on the call used in this example, see https://techdocs.akamai.com/iam-api/reference/put-self-credential. + +package main + +import ( + "context" + "fmt" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/edgegrid" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/iam" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session" +) + +func main() { + edgerc, err := edgegrid.New( + edgegrid.WithFile("~/.edgerc"), + edgegrid.WithSection("default"), + ) + if err != nil { + fmt.Println(err) + return + } + + sess, err := session.New( + session.WithSigner(edgerc), + ) + if err != nil { + fmt.Println(err) + return + } + + client := iam.Client(sess) + + resp, err := client.UpdateCredential( + context.TODO(), + iam.UpdateCredentialRequest{ + CredentialID: 123456, + Body: iam.UpdateCredentialRequestBody{ + Description: "Update this credential", + ExpiresOn: time.Date(2025, 05, 6, 11, 45, 04, 0, time.UTC), + Status: iam.CredentialInactive, + }, + }, + ) + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(resp) +} diff --git a/pkg/edgegrid/README.md b/pkg/edgegrid/README.md deleted file mode 100644 index 5f738af1..00000000 --- a/pkg/edgegrid/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# edgegrid authorization library - -This library provides Akamai `.edgerc` configuration parsing and `http.Request` signing. - -## EdgeGrid Configuration Files - -The default location for the `.edgerc` file is `$HOME/.edgerc`. This file has a standard ini-file format. The default section is `default`. Multiple sections can be stored in the same ini-file for other configurations such as production, staging, or development. - -``` -[default] -client_secret = -host = -access_token = -client_token = - -[dev] -client_secret = -host = -access_token = -client_token = -``` - -## Basic Example - -``` -func main() { - edgerc := Must(New()) - - client := http.Client{} - - req, _ := http.NewRequest(http.MethodGet, "/papi/v1/contracts", nil) - - edgerc.SignRequest(req) - - resp, err := client.Do(req) - if err != nil { - log.Fataln(err) - } - - // do something with response -} -``` - -## Using a custom `.edgerc` file and section - -``` - edgerc := Must(New( - WithFile("/some/other/edgerc"), - WithSection("production"), - )) -} -``` - -## Loading from environment variables - -By default, it uses `AKAMAI_HOST`, `AKAMAI_CLIENT_TOKEN`, `AKAMAI_CLIENT_SECRET`, `AKAMAI_ACCESS_TOKEN`, and `AKAMAI_MAX_BODY` variables. - -You can define multiple configurations by prefixing with the section name specified, e.g. passing "ccu" will cause it to look for `AKAMAI_CCU_HOST`, etc. - -If `AKAMAI_{SECTION}` does not exist, it will fall back to just `AKAMAI_`. - -``` - // Load from AKAMA_CCU_ - edgerc := Must(New( - WithEnv(true), - WithSection("ccu"), - )) -} -``` diff --git a/pkg/iam/api_clients_credentials.go b/pkg/iam/api_clients_credentials.go index a5cd603c..27ad5290 100644 --- a/pkg/iam/api_clients_credentials.go +++ b/pkg/iam/api_clients_credentials.go @@ -26,7 +26,7 @@ type ( Actions bool } - // GetCredentialRequest contains request parameters for the GetCredentials endpoint. + // GetCredentialRequest contains request parameters for the GetCredential endpoint. GetCredentialRequest struct { CredentialID int64 ClientID string diff --git a/pkg/iam/user.go b/pkg/iam/user.go index bd901908..09ef4961 100644 --- a/pkg/iam/user.go +++ b/pkg/iam/user.go @@ -39,7 +39,7 @@ type ( Notifications bool } - // UpdateUserInfoRequest contains the request parameters for the UpdateUser endpoint. + // UpdateUserInfoRequest contains the request parameters for the UpdateUserInfo endpoint. UpdateUserInfoRequest struct { IdentityID string User UserBasicInfo diff --git a/pkg/session/README.md b/pkg/session/README.md deleted file mode 100644 index 80368a27..00000000 --- a/pkg/session/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# session package - -This library provides a simple and consistent REST over HTTP library for accessing Akamai Endpoints - -## Depedencies - -This library is dependent on the `github.com/akamai/AkamaiOPEN-edgegrid-golang/pkg/edgegrid` interface. - -## Basic Example - -``` -func main() { - edgerc := Must(New()) - - s, err := session.New( - session.WithConfig(edgerc), - ) - if err != nil { - panic(err) - } - - var contracts struct { - AccountID string `json:"accountId"` - Contracts ContractsItems `json:"contracts"` - Items []struct { - ContractID string `json:"contractId"` - ContractTypeName string `json:"contractTypeName"` - } `json:"items"` - } - - req, _ := http.NewRequest(http.MethodGet, "/papi/v1/contracts", nil) - - _, err := s.Exec(r, &contracts) - if err != nil { - panic(err); - } - - // do something with contracts -} - -``` - -## Library Logging -The session package supports the structured logging interface from `github.com/apex`. These can be applied globally to the session or to the request context. - -### Adding a logger to the session - -``` - s, err := session.New( - session.WithConfig(edgerc), - session.WithLog(log.Log), - ) - if err != nil { - panic(err) - } -``` - -### Request logging -The logger can be overidden for a specific request like this - -``` - req, _ := http.NewRequest(http.MethodGet, "/papi/v1/contracts", nil) - - req = req.WithContext( - session.ContextWithOptions(request.Context(), - session.WithContextLog(otherlog), - ) -``` - -## Custom request headers -The context can also be updated to pass special http headers when necessary - -``` - customHeader := make(http.Header) - customHeader.Set("X-Custom-Header", "some custom value") - - req = req.WithContext( - session.ContextWithOptions(request.Context(), - session.WithContextHeaders(customHeader), - ) -``` \ No newline at end of file diff --git a/pkg/session/session.go b/pkg/session/session.go index c4f5e81c..2ba0e765 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -163,7 +163,7 @@ func WithHTTPTracing(trace bool) Option { } } -// Log will return the context logger, or the session log +// Log returns the context logger, or the session log func (s *session) Log(ctx context.Context) log.Interface { if o := ctx.Value(contextOptionKey); o != nil { if ops, ok := o.(*contextOptions); ok && ops.log != nil { @@ -184,8 +184,8 @@ func (s *session) Client() *http.Client { return s.client } -// ContextWithOptions adds request specific options to the context -// This log will debug the request only using the provided log +// ContextWithOptions adds request-specific options to the context +// This log debugs the request using only the provided log func ContextWithOptions(ctx context.Context, opts ...ContextOption) context.Context { o := new(contextOptions) for _, opt := range opts {