From 553b6a031ee74322e1471e4cc1a195bf7c41f847 Mon Sep 17 00:00:00 2001 From: Darek Stopka Date: Fri, 21 Jan 2022 15:23:38 +0100 Subject: [PATCH 1/3] DXE-375 Fix validation for DataCenter --- pkg/cloudlets/loadbalancer_version.go | 14 +-- pkg/cloudlets/loadbalancer_version_test.go | 111 ++++++++++++++++----- 2 files changed, 94 insertions(+), 31 deletions(-) diff --git a/pkg/cloudlets/loadbalancer_version.go b/pkg/cloudlets/loadbalancer_version.go index 71c8aa28..5f9a75f9 100644 --- a/pkg/cloudlets/loadbalancer_version.go +++ b/pkg/cloudlets/loadbalancer_version.go @@ -46,11 +46,11 @@ type ( Continent string `json:"continent"` Country string `json:"country"` Hostname string `json:"hostname,omitempty"` - Latitude float64 `json:"latitude"` + Latitude *float64 `json:"latitude"` LivenessHosts []string `json:"livenessHosts,omitempty"` - Longitude float64 `json:"longitude"` + Longitude *float64 `json:"longitude"` OriginID string `json:"originId"` - Percent float64 `json:"percent"` + Percent *float64 `json:"percent"` StateOrProvince *string `json:"stateOrProvince,omitempty"` } @@ -143,11 +143,11 @@ func (v DataCenter) Validate() error { fmt.Sprintf("value '%s' is invalid. Must be one of: 'AF', 'AS', 'EU', 'NA', 'OC', 'OT' or 'SA'", (&v).Continent))), "Country": validation.Validate(v.Country, validation.Required, validation.Length(2, 2)), "Hostname": validation.Validate(v.Hostname, validation.Length(0, 256)), - "Latitude": validation.Validate(v.Latitude, validation.Required, validation.Min(-180.0), validation.Max(180.0)), - "LivenessHosts": validation.Validate(v.LivenessHosts, validation.Length(1, 0)), // max is 0, it means there is no upper bound for the length - "Longitude": validation.Validate(v.Longitude, validation.Required, validation.Min(-180.0), validation.Max(180.0)), + "Latitude": validation.Validate(v.Latitude, validation.NotNil, validation.Min(-180.0), validation.Max(180.0)), + "LivenessHosts": validation.Validate(v.LivenessHosts, validation.Required, validation.Length(1, 0)), // max is 0, it means there is no upper bound for the length + "Longitude": validation.Validate(v.Longitude, validation.NotNil, validation.Min(-180.0), validation.Max(180.0)), "OriginID": validation.Validate(v.OriginID, validation.Required, validation.Length(1, 128)), - "Percent": validation.Validate(v.Percent, validation.Required, validation.Min(0.0), validation.Max(100.0)), + "Percent": validation.Validate(v.Percent, validation.NotNil, validation.Min(0.0), validation.Max(100.0)), }.Filter() } diff --git a/pkg/cloudlets/loadbalancer_version_test.go b/pkg/cloudlets/loadbalancer_version_test.go index add2c532..8e665ba8 100644 --- a/pkg/cloudlets/loadbalancer_version_test.go +++ b/pkg/cloudlets/loadbalancer_version_test.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "testing" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v2/pkg/cloudlets/tools" validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/stretchr/testify/require" @@ -35,12 +36,12 @@ func TestCreateLoadBalancerVersion(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, @@ -122,12 +123,12 @@ func TestCreateLoadBalancerVersion(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, @@ -264,6 +265,68 @@ func TestCreateLoadBalancerVersion(t *testing.T) { } } +func TestDataCenterValidate(t *testing.T) { + tests := map[string]struct { + DataCenter + withError error + }{ + "valid data center": { + DataCenter: DataCenter{ + CloudService: false, + Hostname: "clorigin.example.com", + LivenessHosts: []string{ + "clorigin3.www.example.com", + }, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), + Continent: "NA", + Country: "US", + OriginID: "clorigin3", + Percent: tools.Float64Ptr(100.0), + }, + }, + "longitude, latitude and percent can be 0": { + DataCenter: DataCenter{ + CloudService: false, + Hostname: "clorigin.example.com", + LivenessHosts: []string{ + "clorigin3.www.example.com", + }, + Latitude: tools.Float64Ptr(0), + Longitude: tools.Float64Ptr(0), + Continent: "NA", + Country: "US", + OriginID: "clorigin3", + Percent: tools.Float64Ptr(0), + }, + }, + "missing all required parameters error": { + DataCenter: DataCenter{}, + withError: validation.Errors{ + "Continent": validation.ErrRequired, + "Country": validation.ErrRequired, + "Latitude": validation.ErrNotNilRequired, + "LivenessHosts": validation.ErrRequired, + "Longitude": validation.ErrNotNilRequired, + "OriginID": validation.ErrRequired, + "Percent": validation.ErrNotNilRequired, + }, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + err := test.DataCenter.Validate() + if test.withError != nil { + require.Error(t, err) + assert.Equal(t, test.withError.Error(), err.Error(), "want: %s; got %s", test.withError, err) + return + } + require.NoError(t, err) + }) + } +} + func TestLivenessSettingsValidate(t *testing.T) { tests := map[string]struct { LivenessSettings *LivenessSettings @@ -366,12 +429,12 @@ func TestGetLoadBalancerVersion(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, @@ -461,12 +524,12 @@ func TestUpdateLoadBalancerVersion(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, @@ -539,12 +602,12 @@ func TestUpdateLoadBalancerVersion(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, @@ -579,12 +642,12 @@ func TestUpdateLoadBalancerVersion(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Description: "Test load balancing configuration.", @@ -739,12 +802,12 @@ func TestListLoadBalancerVersions(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, @@ -770,12 +833,12 @@ func TestListLoadBalancerVersions(t *testing.T) { LivenessHosts: []string{ "clorigin3.www.example.com", }, - Latitude: 102.78108, - Longitude: -116.07064, + Latitude: tools.Float64Ptr(102.78108), + Longitude: tools.Float64Ptr(-116.07064), Continent: "NA", Country: "US", OriginID: "clorigin3", - Percent: 100.0, + Percent: tools.Float64Ptr(100.0), }, }, Deleted: false, From 77f0f85efd9e9a95fc3b535c13ddd813ed511ac4 Mon Sep 17 00:00:00 2001 From: Roberto Lopez Lopez Date: Wed, 2 Feb 2022 15:53:16 +0000 Subject: [PATCH 2/3] SECKSD-13178 Allow multiple protection setting resources --- CHANGELOG.md | 7 +++++++ pkg/appsec/api_constraints_protection.go | 2 -- pkg/appsec/ip_geo_protection.go | 20 +++++++++----------- pkg/appsec/network_layer_protection.go | 2 -- pkg/appsec/reputation_protection.go | 2 -- pkg/appsec/slowpost_protection.go | 2 -- pkg/appsec/waf_protection.go | 2 -- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53aeaf75..0271d368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # EDGEGRID GOLANG RELEASE NOTES +## 2.9.1 (Feb. 2, 2022) + +#### FEATURES/ENHANCEMENTS: + +* APPSEC + * Remove deprecation notes for individual policy protection methods + ## 2.9.0 (Jan. 24, 2022) #### FEATURES/ENHANCEMENTS: diff --git a/pkg/appsec/api_constraints_protection.go b/pkg/appsec/api_constraints_protection.go index 463750b4..2dd49cd2 100644 --- a/pkg/appsec/api_constraints_protection.go +++ b/pkg/appsec/api_constraints_protection.go @@ -12,8 +12,6 @@ type ( // The APIConstraintsProtection interface supports retrieving and updating API request constraints // for a configuration and policy. // - // Deprecated: this interface will be removed in a future release. Use the PolicyProtections interface instead. - // // https://developer.akamai.com/api/cloud_security/application_security/v1.html#protections APIConstraintsProtection interface { // https://developer.akamai.com/api/cloud_security/application_security/v1.html#getapirequestconstraints diff --git a/pkg/appsec/ip_geo_protection.go b/pkg/appsec/ip_geo_protection.go index 9c5ce981..e0dce705 100644 --- a/pkg/appsec/ip_geo_protection.go +++ b/pkg/appsec/ip_geo_protection.go @@ -12,8 +12,6 @@ type ( // The IPGeoProtection interface supports retrieving and modifying the protections for a policy, // and whether each is enabled or disabled. // - // Deprecated: this interface will be removed in a future release. Use the PolicyProtections interface instead. - // // https://developer.akamai.com/api/cloud_security/application_security/v1.html#protections IPGeoProtection interface { // https://developer.akamai.com/api/cloud_security/application_security/v1.html#getprotections @@ -64,7 +62,15 @@ type ( ApplySlowPostControls bool `json:"applySlowPostControls,omitempty"` } - // UpdateIPGeoProtectionResponse is used to modify the IPGeo protection settings. + // UpdateIPGeoProtectionRequest is used to modify the IPGeo protection settings. + UpdateIPGeoProtectionRequest struct { + ConfigID int `json:"-"` + Version int `json:"-"` + PolicyID string `json:"-"` + ApplyNetworkLayerControls bool `json:"applyNetworkLayerControls"` + } + + // UpdateIPGeoProtectionResponse is returned from a call to UpdateIPGeoProtection. UpdateIPGeoProtectionResponse struct { ApplyAPIConstraints bool `json:"applyApiConstraints"` ApplyApplicationLayerControls bool `json:"applyApplicationLayerControls"` @@ -74,14 +80,6 @@ type ( ApplyReputationControls bool `json:"applyReputationControls"` ApplySlowPostControls bool `json:"applySlowPostControls"` } - - // UpdateIPGeoProtectionRequest is returned from a call to UpdateIPGeoProtection. - UpdateIPGeoProtectionRequest struct { - ConfigID int `json:"-"` - Version int `json:"-"` - PolicyID string `json:"-"` - ApplyNetworkLayerControls bool `json:"applyNetworkLayerControls"` - } ) // Validate validates a GetIPGeoProtectionRequest. diff --git a/pkg/appsec/network_layer_protection.go b/pkg/appsec/network_layer_protection.go index 6bb2ee47..224ab941 100644 --- a/pkg/appsec/network_layer_protection.go +++ b/pkg/appsec/network_layer_protection.go @@ -11,8 +11,6 @@ import ( type ( // The NetworkLayerProtection interface supports retrieving, modifying and removing network layer protection. // - // Deprecated: this interface will be removed in a future release. Use the PolicyProtections interface instead. - // // https://developer.akamai.com/api/cloud_security/application_security/v1.html#protections NetworkLayerProtection interface { // https://developer.akamai.com/api/cloud_security/application_security/v1.html#getprotections diff --git a/pkg/appsec/reputation_protection.go b/pkg/appsec/reputation_protection.go index a21e1149..7cc8564a 100644 --- a/pkg/appsec/reputation_protection.go +++ b/pkg/appsec/reputation_protection.go @@ -12,8 +12,6 @@ type ( // The ReputationProtection interface supports retrieving, modifying and removing reputation // protection. // - // Deprecated: this interface will be removed in a future release. Use the PolicyProtections interface instead. - // // https://developer.akamai.com/api/cloud_security/application_security/v1.html#protections ReputationProtection interface { // https://developer.akamai.com/api/cloud_security/application_security/v1.html#getprotections diff --git a/pkg/appsec/slowpost_protection.go b/pkg/appsec/slowpost_protection.go index 88929777..cbaacad1 100644 --- a/pkg/appsec/slowpost_protection.go +++ b/pkg/appsec/slowpost_protection.go @@ -12,8 +12,6 @@ type ( // The SlowPostProtection interface supports retrieving and updating slow post protection // for a configuration and policy. // - // Deprecated: this interface will be removed in a future release. Use the PolicyProtections interface instead. - // // https://developer.akamai.com/api/cloud_security/application_security/v1.html#slowpostprotection SlowPostProtection interface { // https://developer.akamai.com/api/cloud_security/application_security/v1.html#getprotections diff --git a/pkg/appsec/waf_protection.go b/pkg/appsec/waf_protection.go index 75a58c29..c4af9959 100644 --- a/pkg/appsec/waf_protection.go +++ b/pkg/appsec/waf_protection.go @@ -12,8 +12,6 @@ type ( // The WAFProtection interface supports retrieving, modifying and removing protections for a // security policy. // - // Deprecated: this interface will be removed in a future release. Use the PolicyProtections interface instead. - // // https://developer.akamai.com/api/cloud_security/application_security/v1.html#protections WAFProtection interface { // https://developer.akamai.com/api/cloud_security/application_security/v1.html#getprotections From a48ab7ae51467619c304592d4ce9c6f9cde3d079 Mon Sep 17 00:00:00 2001 From: Roberto Lopez Lopez Date: Thu, 3 Feb 2022 12:00:18 +0000 Subject: [PATCH 3/3] DXE-515 changelog entry for v2.9.1 --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0271d368..a187d5a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,17 @@ # EDGEGRID GOLANG RELEASE NOTES -## 2.9.1 (Feb. 2, 2022) +## 2.9.1 (Feb. 7, 2022) #### FEATURES/ENHANCEMENTS: * APPSEC * Remove deprecation notes for individual policy protection methods +#### BUG FIXES: + +* CLOUDLETS + * Fixed validation for ALB version DataCenter percent + ## 2.9.0 (Jan. 24, 2022) #### FEATURES/ENHANCEMENTS: