Skip to content

Commit

Permalink
Merge pull request #114 from akamai/release/v2.0.3
Browse files Browse the repository at this point in the history
Release/v2.0.3
  • Loading branch information
zstlaw authored Dec 7, 2020
2 parents 8d67373 + 5350e29 commit 15d3260
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# EDGEGRID GOLANG RELEASE NOTES

## 2.0.3 (Dec 7, 2020)
* PAPI - Property hostname validation fix for missing hostnames.
* PAPI - fix minor typo in rules error messages

## 2.0.2 (Nov 19, 2020)
* [IMPORTANT] APPSEC - Added Application Security API
* [ENHANCEMENT] DNS - Bulk Api endpoints added
Expand Down
7 changes: 5 additions & 2 deletions pkg/papi/propertyhostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func (ch UpdatePropertyVersionHostnamesRequest) Validate() error {
return validation.Errors{
"PropertyID": validation.Validate(ch.PropertyID, validation.Required),
"PropertyVersion": validation.Validate(ch.PropertyVersion, validation.Required),
"Hostnames": validation.Validate(ch.Hostnames, validation.Required),
}.Filter()
}

Expand Down Expand Up @@ -163,7 +162,11 @@ func (p *papi) UpdatePropertyVersionHostnames(ctx context.Context, params Update
}

var hostnames UpdatePropertyVersionHostnamesResponse
resp, err := p.Exec(req, &hostnames, params.Hostnames)
newHostnames := params.Hostnames
if newHostnames == nil {
newHostnames = []Hostname{}
}
resp, err := p.Exec(req, &hostnames, newHostnames)
if err != nil {
return nil, fmt.Errorf("%w: request failed: %s", ErrUpdatePropertyVersionHostnames, err)
}
Expand Down
102 changes: 85 additions & 17 deletions pkg/papi/propertyhostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func TestPapi_UpdatePropertyVersionHostnames(t *testing.T) {
]
}
}
`,
expectedPath: "/papi/v1/properties/prp_175780/versions/3/hostnames?contractId=ctr_1-1TJZH5&groupId=grp_15225&validateHostnames=false",
expectedResponse: &UpdatePropertyVersionHostnamesResponse{
Expand Down Expand Up @@ -289,7 +288,6 @@ func TestPapi_UpdatePropertyVersionHostnames(t *testing.T) {
"items": []
}
}
`,
expectedPath: "/papi/v1/properties/prp_175780/versions/3/hostnames?contractId=ctr_1-1TJZH5&groupId=grp_15225&validateHostnames=true",
expectedResponse: &UpdatePropertyVersionHostnamesResponse{
Expand Down Expand Up @@ -326,38 +324,108 @@ func TestPapi_UpdatePropertyVersionHostnames(t *testing.T) {
assert.Contains(t, err.Error(), "PropertyVersion")
},
},
"validation error Hostnames missing": {
"200 Hostnames missing": {
params: UpdatePropertyVersionHostnamesRequest{
PropertyID: "prp_175780",
PropertyVersion: 3,
GroupID: "grp_15225",
ContractID: "ctr_1-1TJZH5",
},
withError: func(t *testing.T, err error) {
want := ErrStructValidation
assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
assert.Contains(t, err.Error(), "Hostnames")
responseStatus: http.StatusOK,
responseBody: `
{
"accountId": "act_1-1TJZFB",
"contractId": "ctr_1-1TJZH5",
"groupId": "grp_15225",
"propertyId": "prp_175780",
"propertyVersion": 3,
"etag": "6aed418629b4e5c0",
"validateHostnames": false,
"hostnames": {
"items": []
}
}`,
expectedPath: "/papi/v1/properties/prp_175780/versions/3/hostnames?contractId=ctr_1-1TJZH5&groupId=grp_15225&validateHostnames=false",
expectedResponse: &UpdatePropertyVersionHostnamesResponse{
AccountID: "act_1-1TJZFB",
ContractID: "ctr_1-1TJZH5",
GroupID: "grp_15225",
PropertyID: "prp_175780",
PropertyVersion: 3,
Etag: "6aed418629b4e5c0",
Hostnames: HostnameResponseItems{
Items: []Hostname{},
},
},
},
"validation error Hostnames items missing": {
"200 Hostnames items missing": {
params: UpdatePropertyVersionHostnamesRequest{
PropertyID: "prp_175780",
PropertyVersion: 3,
GroupID: "grp_15225",
ContractID: "ctr_1-1TJZH5",
Hostnames: nil,
},
withError: func(t *testing.T, err error) {
want := ErrStructValidation
assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
assert.Contains(t, err.Error(), "Hostnames")
responseStatus: http.StatusOK,
responseBody: `
{
"accountId": "act_1-1TJZFB",
"contractId": "ctr_1-1TJZH5",
"groupId": "grp_15225",
"propertyId": "prp_175780",
"propertyVersion": 3,
"etag": "6aed418629b4e5c0",
"validateHostnames": false,
"hostnames": {
"items": []
}
}`,
expectedPath: "/papi/v1/properties/prp_175780/versions/3/hostnames?contractId=ctr_1-1TJZH5&groupId=grp_15225&validateHostnames=false",
expectedResponse: &UpdatePropertyVersionHostnamesResponse{
AccountID: "act_1-1TJZFB",
ContractID: "ctr_1-1TJZH5",
GroupID: "grp_15225",
PropertyID: "prp_175780",
PropertyVersion: 3,
Etag: "6aed418629b4e5c0",
Hostnames: HostnameResponseItems{
Items: []Hostname{},
},
},
},
"validation error Hostnames items empty": {
"200 Hostnames items empty": {
params: UpdatePropertyVersionHostnamesRequest{
PropertyID: "prp_175780",
PropertyVersion: 3,
GroupID: "grp_15225",
ContractID: "ctr_1-1TJZH5",
Hostnames: []Hostname{},
},
withError: func(t *testing.T, err error) {
want := ErrStructValidation
assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
assert.Contains(t, err.Error(), "Hostnames")
responseStatus: http.StatusOK,
responseBody: `
{
"accountId": "act_1-1TJZFB",
"contractId": "ctr_1-1TJZH5",
"groupId": "grp_15225",
"propertyId": "prp_175780",
"propertyVersion": 3,
"etag": "6aed418629b4e5c0",
"validateHostnames": false,
"hostnames": {
"items": []
}
}`,
expectedPath: "/papi/v1/properties/prp_175780/versions/3/hostnames?contractId=ctr_1-1TJZH5&groupId=grp_15225&validateHostnames=false",
expectedResponse: &UpdatePropertyVersionHostnamesResponse{
AccountID: "act_1-1TJZFB",
ContractID: "ctr_1-1TJZH5",
GroupID: "grp_15225",
PropertyID: "prp_175780",
PropertyVersion: 3,
Etag: "6aed418629b4e5c0",
Hostnames: HostnameResponseItems{
Items: []Hostname{},
},
},
},
"500 internal server status error": {
Expand Down
2 changes: 2 additions & 0 deletions pkg/papi/propertyversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ const (
VersionStatusInactive VersionStatus = "INACTIVE"
// VersionStatusPending const
VersionStatusPending VersionStatus = "PENDING"
// ActivationStatusDeactivated is deactivated
VersionStatusDeactivated VersionStatus = "DEACTIVATED"
// VersionProduction const
VersionProduction = "PRODUCTION"
// VersionStaging const
Expand Down
2 changes: 1 addition & 1 deletion pkg/papi/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (v RuleVariable) Validate() error {
}

var (
ErrGetRuleTree = errors.New("fetchign rule tree")
ErrGetRuleTree = errors.New("fetching rule tree")
ErrUpdateRuleTree = errors.New("updating rule tree")
)

Expand Down

0 comments on commit 15d3260

Please sign in to comment.