Skip to content

Commit

Permalink
DXE-3436 Merge pull request #198 from akamai/release/v7.6.0
Browse files Browse the repository at this point in the history
Release/v7.6.0
  • Loading branch information
mimazaka authored Feb 8, 2024
2 parents 8f8b577 + 23b4afe commit 4eba719
Show file tree
Hide file tree
Showing 69 changed files with 11,664 additions and 128 deletions.
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
# EDGEGRID GOLANG RELEASE NOTES

## 7.6.0 (February 8, 2024)

#### FEATURES/ENHANCEMENTS:

* General
* Enhanced error handling when Error is not in standard format.

* Added Cloudlets V3 API support
* Cloudlet Info
* [ListCloudlets](https://techdocs.akamai.com/cloudlets/reference/get-cloudlets)
* Policies
* [ListPolicies](https://techdocs.akamai.com/cloudlets/reference/get-policies)
* [CreatePolicy](https://techdocs.akamai.com/cloudlets/reference/post-policy)
* [DeletePolicy](https://techdocs.akamai.com/cloudlets/reference/delete-policy)
* [GetPolicy](https://techdocs.akamai.com/cloudlets/reference/get-policy)
* [UpdatePolicy](https://techdocs.akamai.com/cloudlets/reference/put-policy)
* [ClonePolicy](https://techdocs.akamai.com/cloudlets/reference/post-policy-clone)
* Policy Properties
* [ListActivePolicyProperties](https://techdocs.akamai.com/cloudlets/reference/get-policy-properties)
* Policy Versions
* [ListPolicyVersions](https://techdocs.akamai.com/cloudlets/reference/get-policy-versions)
* [GetPolicyVersion](https://techdocs.akamai.com/cloudlets/reference/get-policy-version)
* [CreatePolicyVersion](https://techdocs.akamai.com/cloudlets/reference/post-policy-version)
* [DeletePolicyVersion](https://techdocs.akamai.com/cloudlets/reference/delete-policy-version)
* [UpdatePolicyVersion](https://techdocs.akamai.com/cloudlets/reference/put-policy-version)
* Policy Activations
* [ListPolicyActivations](https://techdocs.akamai.com/cloudlets/reference/get-policy-activations)
* [GetPolicyActivation](https://techdocs.akamai.com/cloudlets/reference/get-policy-activation)
* [ActivatePolicy and DeactivatePolicy](https://techdocs.akamai.com/cloudlets/reference/post-policy-activations)
* Supported cloudlet types
* API Prioritization (AP)
* Application Segmentation (AS)
* Edge Redirector (ER)
* Forward Rewrite (FR)
* Phased Release (PR aka CD)
* Request Control (RC aka IG)

* DNS
* Added `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

* GTM
* Added new fields to `DomainItem` struct

* IVM
* Extended `OutputImage` for support of `AllowPristineOnDownsize` and `PreferModernFormats`
* Extended `PolicyInputImage` for support of `ServeStaleDuration`
* Extended `RolloutInfo` for support of `ServeStaleEndTime`

#### BUG FIXES:

* APPSEC
* Added `updateLatestNetworkStatus` query parameter in GetActivations request to resolve drift on manual changes to infrastructure

## 7.5.0 (November 28, 2023)

#### FEATURES/ENHANCEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COMMIT_SHA=$(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --tags --always | grep '^v\d' || \
echo $(FILEVERSION)-$(COMMIT_SHA))
BIN = $(CURDIR)/bin
GOLANGCI_LINT_VERSION = v1.52.2
GOLANGCI_LINT_VERSION = v1.55.2
GO = go
TIMEOUT = 15
V = 0
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ require (
github.com/google/uuid v1.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.8.4
github.com/tj/assert v0.0.3
go.uber.org/ratelimit v0.2.0
golang.org/x/net v0.20.0
gopkg.in/ini.v1 v1.51.1
)

Expand All @@ -23,7 +24,9 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/objx v0.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
19 changes: 15 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
Expand All @@ -82,10 +87,14 @@ go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA=
go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -95,6 +104,8 @@ 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=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
Expand All @@ -107,5 +118,5 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 11 additions & 4 deletions pkg/appsec/activations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
"time"

validation "github.com/go-ozzo/ozzo-validation/v4"
Expand Down Expand Up @@ -168,11 +170,16 @@ func (p *appsec) GetActivations(ctx context.Context, params GetActivationsReques
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}

uri := fmt.Sprintf(
"/appsec/v1/activations/%d",
params.ActivationID)
uri, err := url.Parse(fmt.Sprintf("/appsec/v1/activations/%d", params.ActivationID))
if err != nil {
return nil, fmt.Errorf("failed to parse url: %s", err)
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
q := uri.Query()
q.Add("updateLatestNetworkStatus", strconv.FormatBool(true))
uri.RawQuery = q.Encode()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri.String(), nil)
if err != nil {
return nil, fmt.Errorf("failed to create GetActivations request: %w", err)
}
Expand Down
78 changes: 78 additions & 0 deletions pkg/appsec/activations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,81 @@ func TestAppSec_ListActivations(t *testing.T) {
})
}
}

func TestAppSec_GetActivations(t *testing.T) {

result := GetActivationsResponse{}

respData := compactJSON(loadFixtureBytes("testdata/TestActivations/Activations.json"))
err := json.Unmarshal([]byte(respData), &result)
require.NoError(t, err)

tests := map[string]struct {
params GetActivationsRequest
responseStatus int
responseBody string
expectedPath string
expectedResponse *GetActivationsResponse
withError error
headers http.Header
}{
"200 OK": {
params: GetActivationsRequest{
ActivationID: 32415,
},
headers: http.Header{
"Content-Type": []string{"application/json"},
},
responseStatus: http.StatusOK,
responseBody: string(respData),
expectedPath: "/appsec/v1/activations/32415?updateLatestNetworkStatus=true",
expectedResponse: &result,
},
"500 internal server error": {
params: GetActivationsRequest{
ActivationID: 32415,
},
headers: http.Header{},
responseStatus: http.StatusInternalServerError,
responseBody: `
{
"type": "internal_error",
"title": "Internal Server Error",
"detail": "Error fetching activations",
"status": 500
}`,
expectedPath: "/appsec/v1/activations/32415?updateLatestNetworkStatus=true",
withError: &Error{
Type: "internal_error",
Title: "Internal Server Error",
Detail: "Error fetching activations",
StatusCode: http.StatusInternalServerError,
},
},
}

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))
assert.NoError(t, err)
}))
client := mockAPIClient(t, mockServer)
result, err := client.GetActivations(
session.ContextWithOptions(
context.Background(),
session.WithContextHeaders(test.headers),
),
test.params)
if test.withError != nil {
assert.True(t, errors.Is(err, test.withError), "want: %s; got: %s", test.withError, err)
return
}
require.NoError(t, err)
assert.Equal(t, test.expectedResponse, result)
})
}
}
6 changes: 4 additions & 2 deletions pkg/appsec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io/ioutil"
"net/http"

"github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/errs"
)

var (
Expand Down Expand Up @@ -42,8 +44,8 @@ func (p *appsec) Error(r *http.Response) error {

if err := json.Unmarshal(body, &e); err != nil {
p.Log(r.Request.Context()).Errorf("could not unmarshal API error: %s", err)
e.Title = "Failed to unmarshal error body"
e.Detail = err.Error()
e.Title = "Failed to unmarshal error body. Application Security API failed. Check details for more information."
e.Detail = errs.UnescapeContent(string(body))
}

e.StatusCode = r.StatusCode
Expand Down
61 changes: 59 additions & 2 deletions pkg/appsec/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestNewError(t *testing.T) {
Request: req,
},
expected: &Error{
Title: "Failed to unmarshal error body",
Detail: "invalid character 'e' in literal true (expecting 'r')",
Title: "Failed to unmarshal error body. Application Security API failed. Check details for more information.",
Detail: "test",
StatusCode: http.StatusInternalServerError,
},
},
Expand All @@ -66,3 +66,60 @@ func TestNewError(t *testing.T) {
})
}
}

func TestJsonErrorUnmarshalling(t *testing.T) {
req, err := http.NewRequestWithContext(
context.TODO(),
http.MethodHead,
"/",
nil)
require.NoError(t, err)
tests := map[string]struct {
input *http.Response
expected *Error
}{
"API failure with HTML response": {
input: &http.Response{
Request: req,
Status: "OK",
Body: ioutil.NopCloser(strings.NewReader(`<HTML><HEAD>...</HEAD><BODY>...</BODY></HTML>`))},
expected: &Error{
Type: "",
Title: "Failed to unmarshal error body. Application Security API failed. Check details for more information.",
Detail: "<HTML><HEAD>...</HEAD><BODY>...</BODY></HTML>",
},
},
"API failure with plain text response": {
input: &http.Response{
Request: req,
Status: "OK",
Body: ioutil.NopCloser(strings.NewReader("Your request did not succeed as this operation has reached the limit for your account. Please try after 2024-01-16T15:20:55.945Z"))},
expected: &Error{
Type: "",
Title: "Failed to unmarshal error body. Application Security API failed. Check details for more information.",
Detail: "Your request did not succeed as this operation has reached the limit for your account. Please try after 2024-01-16T15:20:55.945Z",
},
},
"API failure with XML response": {
input: &http.Response{
Request: req,
Status: "OK",
Body: ioutil.NopCloser(strings.NewReader(`<Root><Item id="1" name="Example" /></Root>`))},
expected: &Error{
Type: "",
Title: "Failed to unmarshal error body. Application Security API failed. Check details for more information.",
Detail: "<Root><Item id=\"1\" name=\"Example\" /></Root>",
},
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
sess, _ := session.New()
as := appsec{
Session: sess,
}
assert.Equal(t, test.expected, as.Error(test.input))
})
}
}
18 changes: 18 additions & 0 deletions pkg/appsec/testdata/TestActivations/Activations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dispatchCount" : 1,
"activationId" : 32415,
"action" : "deny",
"status" : "ACTIVATED",
"network" : "STAGING",
"estimate" : "test",
"createdBy" : "test_user",
"createDate" : "2022-05-05T14:19:17Z",
"activationConfigs" : [
{
"configId" : 43253,
"ConfigName" : "activationConfig",
"ConfigVersion": 1,
"PreviousConfigVersion": 1
}
]
}
6 changes: 4 additions & 2 deletions pkg/botman/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io/ioutil"
"net/http"
"strings"

"github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/errs"
)

type (
Expand Down Expand Up @@ -35,8 +37,8 @@ func (b *botman) Error(r *http.Response) error {

if err := json.Unmarshal(body, &e); err != nil {
b.Log(r.Request.Context()).Errorf("could not unmarshal API error: %s", err)
e.Title = "Failed to unmarshal error body"
e.Detail = err.Error()
e.Title = "Failed to unmarshal error body. Bot Manager API failed. Check details for more information."
e.Detail = errs.UnescapeContent(string(body))
}

e.StatusCode = r.StatusCode
Expand Down
Loading

0 comments on commit 4eba719

Please sign in to comment.