From 36bac85ad808fbcb90fb527a18d31f3fd21d5109 Mon Sep 17 00:00:00 2001 From: Rob Rodriguez Date: Fri, 16 Oct 2020 09:59:54 -0700 Subject: [PATCH 1/5] only unmarshal if resp.StatusCode is less than 300 --- pkg/session/request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/session/request.go b/pkg/session/request.go index 32fdb68d..d1525997 100644 --- a/pkg/session/request.go +++ b/pkg/session/request.go @@ -87,7 +87,7 @@ func (s *session) Exec(r *http.Request, out interface{}, in ...interface{}) (*ht } } - if out != nil { + if out != nil && resp.StatusCode < http.StatusMultipleChoices { data, err := ioutil.ReadAll(resp.Body) resp.Body = ioutil.NopCloser(bytes.NewBuffer(data)) if err != nil { From 19257a9213c775ce1fa33a51c64bfd2f042d7618 Mon Sep 17 00:00:00 2001 From: Rob Rodriguez Date: Fri, 16 Oct 2020 10:43:01 -0700 Subject: [PATCH 2/5] ensure status is in valid range before processing entity --- pkg/session/request.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/session/request.go b/pkg/session/request.go index d1525997..cd8ca856 100644 --- a/pkg/session/request.go +++ b/pkg/session/request.go @@ -87,7 +87,9 @@ func (s *session) Exec(r *http.Request, out interface{}, in ...interface{}) (*ht } } - if out != nil && resp.StatusCode < http.StatusMultipleChoices { + if out != nil && + resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices && + resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusResetContent { data, err := ioutil.ReadAll(resp.Body) resp.Body = ioutil.NopCloser(bytes.NewBuffer(data)) if err != nil { From 1382b774eb39b7ee29bc33fd7a3e3a7bcef0d8f7 Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Fri, 16 Oct 2020 15:23:44 -0400 Subject: [PATCH 3/5] correct default datacenter create --- pkg/configgtm/datacenter.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/configgtm/datacenter.go b/pkg/configgtm/datacenter.go index 0285b8fd..313df6b1 100644 --- a/pkg/configgtm/datacenter.go +++ b/pkg/configgtm/datacenter.go @@ -6,7 +6,6 @@ import ( "net/http" "strconv" - "strings" ) // @@ -209,7 +208,9 @@ func createDefaultDC(ctx context.Context, p *gtm, defaultID int, domainName stri if err == nil { return dc, err } else { - if !strings.Contains(err.Error(), "not found") || !strings.Contains(err.Error(), "Datacenter") { + apiError, ok := err.(*Error) + //if !strings.Contains(err.Error(), "not found") || !strings.Contains(err.Error(), "Datacenter") { + if !ok || apiError.StatusCode != http.StatusNotFound { return nil, err } } From a1b081116f3df4d93d6cea5e22df6decf9f49264 Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Fri, 16 Oct 2020 15:28:02 -0400 Subject: [PATCH 4/5] minor oversight. typo --- pkg/configdns/zone.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/configdns/zone.go b/pkg/configdns/zone.go index 3d85b694..9dc6b3fd 100644 --- a/pkg/configdns/zone.go +++ b/pkg/configdns/zone.go @@ -163,7 +163,7 @@ var zoneStructMap map[string]string = map[string]string{ "SignAndServeAlgorithm": "signAndServeAlgorithm", "TsigKey": "tsigKey", "Target": "target", - "EndCustomerId": "endCustomerId", + "EndCustomerID": "endCustomerId", "ContractId": "contractId"} // Util to convert struct to http request body, eg. io.reader From c66c8bac244663d58bb0ab33e0ed96513056f457 Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Tue, 20 Oct 2020 09:57:42 -0400 Subject: [PATCH 5/5] TFP-282 fix tests in dns package with wrong argument order --- pkg/configdns/record_lookup_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/configdns/record_lookup_test.go b/pkg/configdns/record_lookup_test.go index fac80f9f..4a5cc911 100644 --- a/pkg/configdns/record_lookup_test.go +++ b/pkg/configdns/record_lookup_test.go @@ -128,7 +128,7 @@ func TestDns_GetRecordList(t *testing.T) { } ] }`, - expectedPath: "/config-dns/v2/zones/example.com/recordsets?types=A&showAll=true", + expectedPath: "/config-dns/v2/zones/example.com/recordsets?showAll=true&types=A", expectedResponse: &RecordSetResponse{ Metadata: MetadataH{ LastPage: 0, @@ -158,7 +158,7 @@ func TestDns_GetRecordList(t *testing.T) { "detail": "Error fetching authorities", "status": 500 }`, - expectedPath: "/config-dns/v2/zones/example.com/recordsets?types=A&showAll=true", + expectedPath: "/config-dns/v2/zones/example.com/recordsets?showAll=true&types=A", withError: &Error{ Type: "internal_error", Title: "Internal Server Error", @@ -227,7 +227,7 @@ func TestDns_GetRdata(t *testing.T) { } ] }`, - expectedPath: "/config-dns/v2/zones/example.com/recordsets?types=AAAA&showAll=true", + expectedPath: "/config-dns/v2/zones/example.com/recordsets?showAll=true&types=AAAA", expectedResponse: []string{"2001:0db8:85a3:0000:0000:8a2e:0370:7334"}, }, "loc test": { @@ -257,7 +257,7 @@ func TestDns_GetRdata(t *testing.T) { } ] }`, - expectedPath: "/config-dns/v2/zones/example.com/recordsets?types=LOC&showAll=true", + expectedPath: "/config-dns/v2/zones/example.com/recordsets?showAll=true&types=LOC", expectedResponse: []string{"52 22 23.000 N 4 53 32.000 E -2.00m 0.00m 10000.00m 10.00m"}, }, "500 internal server error": { @@ -271,7 +271,7 @@ func TestDns_GetRdata(t *testing.T) { "detail": "Error fetching authorities", "status": 500 }`, - expectedPath: "/config-dns/v2/zones/example.com/recordsets?types=A&showAll=true", + expectedPath: "/config-dns/v2/zones/example.com/recordsets?showAll=true&types=A", withError: &Error{ Type: "internal_error", Title: "Internal Server Error",