Skip to content

Commit

Permalink
DXE-3660 Add response body close
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilskiAkam committed Nov 8, 2024
1 parent b8ffd93 commit 2844291
Show file tree
Hide file tree
Showing 206 changed files with 1,084 additions and 24 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@



* General
* Added logic responsible for closing the response body in each method.










Expand Down
9 changes: 9 additions & 0 deletions pkg/appsec/activations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"time"

"github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session"
validation "github.com/go-ozzo/ozzo-validation/v4"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/appsec/advanced_settings_attack_payload_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/advanced_settings_evasive_path_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/appsec/advanced_settings_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/advanced_settings_pii_learning.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/advanced_settings_pragma_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/advanced_settings_prefetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/appsec/advanced_settings_request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/api_constraints_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/api_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/appsec/api_hostname_coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"net/http"

"github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session"
)

type (
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/api_hostname_coverage_match_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/appsec/api_hostname_coverage_overlapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/appsec/api_request_constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 2844291

Please sign in to comment.