From 2f9e67341a53684e1d6bc714e1200d8136cb4bd8 Mon Sep 17 00:00:00 2001 From: Bruce DeWald Date: Mon, 8 Apr 2024 17:24:55 -0700 Subject: [PATCH] update dependencies & tests --- Makefile | 13 ++++----- go.mod | 8 +++--- go.sum | 12 ++++----- vinyldns/endpoints.go | 27 +++++++++++++++++-- vinyldns/endpoints_test.go | 6 ++--- vinyldns/groups_test.go | 2 +- vinyldns/integration_test.go | 16 +++++------ vinyldns/mock_testing_server_test.go | 4 +-- vinyldns/recordsets.go | 6 ++--- vinyldns/recordsets_resources.go | 4 +-- vinyldns/recordsets_test.go | 12 ++++----- vinyldns/resources.go | 9 +++++++ .../recordsets/recordset-changes-list-1.json | 4 +-- .../recordsets/recordset-changes-list-2.json | 2 +- vinyldns/util.go | 24 ++++++++++++----- vinyldns/zones_test.go | 4 +-- 16 files changed, 99 insertions(+), 54 deletions(-) diff --git a/Makefile b/Makefile index 2fa23e6..b82d437 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION=0.9.16 SOURCE?=./... VINYLDNS_REPO=github.com/vinyldns/vinyldns -VINYLDNS_VERSION=0.9.10 +VINYLDNS_VERSION=0.20.0 ifndef $(GOPATH) GOPATH=$(shell go env GOPATH) @@ -20,7 +20,7 @@ test: go vet $(SOURCE) GO111MODULE=on go test $(SOURCE) -cover -integration: start-api +integration: stop-api start-api GO111MODULE=on go test $(SOURCE) -tags=integration validate-version: @@ -34,12 +34,13 @@ start-api: https://$(VINYLDNS_REPO) \ $(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION); \ fi - $(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)/bin/docker-up-vinyldns.sh \ - --api-only \ - --version $(VINYLDNS_VERSION) + $(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)/quickstart/quickstart-vinyldns.sh \ + --api \ + --version-tag $(VINYLDNS_VERSION) stop-api: - $(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)/bin/remove-vinyl-containers.sh + $(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)/quickstart/quickstart-vinyldns.sh \ + --clean build: GO111MODULE=on go build -ldflags "-X main.version=$(VERSION)" $(SOURCE) diff --git a/go.mod b/go.mod index 93306df..c6fa3d9 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,11 @@ module github.com/vinyldns/go-vinyldns -go 1.17 +go 1.21 require ( + github.com/aws/aws-sdk-go-v2 v1.26.1 + github.com/aws/aws-sdk-go-v2/credentials v1.17.11 github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b - github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 - github.com/smartystreets/gunit v1.0.4 // indirect ) + +require github.com/aws/smithy-go v1.20.2 // indirect diff --git a/go.sum b/go.sum index 30248a6..72004bb 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ +github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA= +github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= +github.com/aws/aws-sdk-go-v2/credentials v1.17.11 h1:YuIB1dJNf1Re822rriUOTxopaHHvIq0l/pX3fwO+Tzs= +github.com/aws/aws-sdk-go-v2/credentials v1.17.11/go.mod h1:AQtFPsDH9bI2O+71anW6EKL+NcD7LG3dpKGMV4SShgo= +github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= +github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b h1:/vQ+oYKu+JoyaMPDsv5FzwuL2wwWBgBbtj/YLCi4LuA= github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b/go.mod h1:Xo4aNUOrJnVruqWQJBtW6+bTBDTniY8yZum5rF3b5jw= -github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= -github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 h1:hp2CYQUINdZMHdvTdXtPOY2ainKl4IoMcpAXEf2xj3Q= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= -github.com/smartystreets/gunit v1.0.4 h1:tpTjnuH7MLlqhoD21vRoMZbMIi5GmBsAJDFyF67GhZA= -github.com/smartystreets/gunit v1.0.4/go.mod h1:EH5qMBab2UclzXUcpR8b93eHsIlp9u+pDQIRp5DZNzQ= diff --git a/vinyldns/endpoints.go b/vinyldns/endpoints.go index 925210d..02ea636 100644 --- a/vinyldns/endpoints.go +++ b/vinyldns/endpoints.go @@ -66,8 +66,8 @@ func recordSetEP(c *Client, zoneID, recordSetID string) string { return concatStrs("", recordSetsEP(c, zoneID), "/", recordSetID) } -func recordSetChangesEP(c *Client, zoneID string, f ListFilter) string { - query := buildQuery(f, "nameFilter") +func recordSetChangesEP(c *Client, zoneID string, f ListFilterInt) string { + query := buildQueryInt(f, "nameFilter") return concatStrs("", zoneEP(c, zoneID), "/recordsetchanges", query) } @@ -133,6 +133,29 @@ func buildQuery(f ListFilter, nameFilterName string) string { return query + strings.Join(params, "&") } +func buildQueryInt(f ListFilterInt, nameFilterName string) string { + params := []string{} + query := "?" + + if f.NameFilter != "" { + params = append(params, fmt.Sprintf("%s=%s", nameFilterName, f.NameFilter)) + } + + if f.StartFrom != 0 { + params = append(params, fmt.Sprintf("startFrom=%d", f.StartFrom)) + } + + if f.MaxItems != 0 { + params = append(params, fmt.Sprintf("maxItems=%d", f.MaxItems)) + } + + if len(params) == 0 { + query = "" + } + + return query + strings.Join(params, "&") +} + func buildGlobalListQuery(f GlobalListFilter) string { params := []string{} query := "?" diff --git a/vinyldns/endpoints_test.go b/vinyldns/endpoints_test.go index 85465c8..e3f7fa5 100644 --- a/vinyldns/endpoints_test.go +++ b/vinyldns/endpoints_test.go @@ -227,7 +227,7 @@ func TestRecordSetEP(t *testing.T) { } func TestRecordSetChangesEP(t *testing.T) { - rsc := recordSetChangesEP(c, "123", ListFilter{}) + rsc := recordSetChangesEP(c, "123", ListFilterInt{}) expected := "http://host.com/zones/123/recordsetchanges" if rsc != expected { @@ -238,9 +238,9 @@ func TestRecordSetChangesEP(t *testing.T) { } func TestRecordSetChangesEPWithQuery(t *testing.T) { - rsc := recordSetChangesEP(c, "123", ListFilter{ + rsc := recordSetChangesEP(c, "123", ListFilterInt{ MaxItems: 3, - StartFrom: "1", + StartFrom: 1, }) expected := "http://host.com/zones/123/recordsetchanges?startFrom=1&maxItems=3" diff --git a/vinyldns/groups_test.go b/vinyldns/groups_test.go index b0649bd..89240cc 100644 --- a/vinyldns/groups_test.go +++ b/vinyldns/groups_test.go @@ -182,7 +182,7 @@ func TestGroupsListAll(t *testing.T) { body: groupsListJSON1, }, { - endpoint: "http://host.com/groups?startFrom=2&maxItems=1", + endpoint: "http://host.com/groups?maxItems=1&startFrom=2", code: 200, body: groupsListJSON2, }, diff --git a/vinyldns/integration_test.go b/vinyldns/integration_test.go index 7b286cf..b4c429b 100644 --- a/vinyldns/integration_test.go +++ b/vinyldns/integration_test.go @@ -46,7 +46,7 @@ func TestGroupCreateIntegration(t *testing.T) { gc, err := c.GroupCreate(&Group{ Name: "test-group", Description: "a test group", - Email: "test@vinyldns.com", + Email: "test@test.com", Admins: users, Members: users, }) @@ -91,7 +91,7 @@ func TestGroupAdminsIntegration(t *testing.T) { t.Error(err) } - if admins[0].UserName != "ok" { + if admins[0].UserName != "ok" && admins[0].UserName != "dummy" { t.Error(fmt.Sprintf("unable to get group admins for group %s", gID)) } } @@ -117,12 +117,12 @@ func TestZoneCreateIntegration(t *testing.T) { Name: "ok.", KeyName: "vinyldns.", Key: "nzisn+4G2ldMn0q1CV3vsg==", - PrimaryServer: "vinyldns-bind9", + PrimaryServer: "vinyldns-integration:19001", } zone := &Zone{ Name: "ok.", - Email: "email@email.com", + Email: "email@test.com", AdminGroupID: groups[0].ID, Connection: connection, TransferConnection: connection, @@ -403,7 +403,7 @@ func TestRecordSetsGlobalListAllIntegrationFilterForExistentName(t *testing.T) { rName := "foo" records, err := c.RecordSetsGlobalListAll(GlobalListFilter{ - RecordNameFilter: "*" + rName + "*", + RecordNameFilter: rName + "*", }) if err != nil { t.Error(err) @@ -466,7 +466,7 @@ func TestRecordSetChangesIntegration(t *testing.T) { t.Error(err) } - changes, err := c.RecordSetChanges(zones[0].ID, ListFilter{}) + changes, err := c.RecordSetChanges(zones[0].ID, ListFilterInt{}) if err != nil { t.Error(err) } @@ -483,7 +483,7 @@ func TestRecordSetChangesIntegrationWithMaxItems(t *testing.T) { t.Error(err) } - changes, err := c.RecordSetChanges(zones[0].ID, ListFilter{ + changes, err := c.RecordSetChanges(zones[0].ID, ListFilterInt{ MaxItems: 1, }) if err != nil { @@ -502,7 +502,7 @@ func TestRecordSetChangesListAllIntegration(t *testing.T) { t.Error(err) } - changes, err := c.RecordSetChangesListAll(zones[0].ID, ListFilter{}) + changes, err := c.RecordSetChangesListAll(zones[0].ID, ListFilterInt{}) if err != nil { t.Error(err) } diff --git a/vinyldns/mock_testing_server_test.go b/vinyldns/mock_testing_server_test.go index e0e6338..c416af9 100644 --- a/vinyldns/mock_testing_server_test.go +++ b/vinyldns/mock_testing_server_test.go @@ -15,10 +15,10 @@ package vinyldns import ( "crypto/tls" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/url" + "os" ) type testToolsConfig struct { @@ -28,7 +28,7 @@ type testToolsConfig struct { } func readFile(file string) (string, error) { - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { return "", err } diff --git a/vinyldns/recordsets.go b/vinyldns/recordsets.go index d6ba9af..be1acf4 100644 --- a/vinyldns/recordsets.go +++ b/vinyldns/recordsets.go @@ -209,7 +209,7 @@ func (c *Client) RecordSetDelete(zoneID, recordSetID string) (*RecordSetUpdateRe } // RecordSetChanges retrieves the RecordSetChanges response for the Zone and ListFilter it's passed. -func (c *Client) RecordSetChanges(zoneID string, f ListFilter) (*RecordSetChanges, error) { +func (c *Client) RecordSetChanges(zoneID string, f ListFilterInt) (*RecordSetChanges, error) { rsc := &RecordSetChanges{} err := resourceRequest(c, recordSetChangesEP(c, zoneID, f), "GET", nil, rsc) if err != nil { @@ -221,7 +221,7 @@ func (c *Client) RecordSetChanges(zoneID string, f ListFilter) (*RecordSetChange // RecordSetChangesListAll retrieves the complete list of record set changes for the Zone ListFilter criteria passed. // Handles paging through results on the user's behalf. -func (c *Client) RecordSetChangesListAll(zoneID string, filter ListFilter) ([]RecordSetChange, error) { +func (c *Client) RecordSetChangesListAll(zoneID string, filter ListFilterInt) ([]RecordSetChange, error) { if filter.MaxItems > 100 { return nil, fmt.Errorf("MaxItems must be between 1 and 100") } @@ -237,7 +237,7 @@ func (c *Client) RecordSetChangesListAll(zoneID string, filter ListFilter) ([]Re rsc = append(rsc, resp.RecordSetChanges...) filter.StartFrom = resp.NextID - if len(filter.StartFrom) == 0 { + if filter.StartFrom == 0 { return rsc, nil } } diff --git a/vinyldns/recordsets_resources.go b/vinyldns/recordsets_resources.go index f8eac05..e297eed 100644 --- a/vinyldns/recordsets_resources.go +++ b/vinyldns/recordsets_resources.go @@ -28,8 +28,8 @@ type RecordSetChange struct { type RecordSetChanges struct { RecordSetChanges []RecordSetChange `json:"recordSetChanges"` ZoneID string `json:"zoneId,omitempty"` - StartFrom string `json:"startFrom,omitempty"` - NextID string `json:"nextId,omitempty"` + StartFrom any `json:"startFrom,omitempty"` + NextID int `json:"nextId,omitempty"` MaxItems int `json:"maxItems,omitempty"` Status string `json:"status,omitempty"` } diff --git a/vinyldns/recordsets_test.go b/vinyldns/recordsets_test.go index fd2aa03..2128593 100644 --- a/vinyldns/recordsets_test.go +++ b/vinyldns/recordsets_test.go @@ -65,7 +65,7 @@ func TestRecordSetsListAll(t *testing.T) { body: recordSetsListJSON1, }, { - endpoint: "http://host.com/zones/123/recordsets?startFrom=2&maxItems=1", + endpoint: "http://host.com/zones/123/recordsets?maxItems=1&startFrom=2", code: 200, body: recordSetsListJSON2, }, @@ -149,7 +149,7 @@ func TestRecordSetsGlobalListAll(t *testing.T) { body: recordSetsListJSON1, }, { - endpoint: "http://host.com/recordsets?startFrom=2&maxItems=1", + endpoint: "http://host.com/recordsets?maxItems=1&startFrom=2", code: 200, body: recordSetsListJSON2, }, @@ -513,7 +513,7 @@ func TestRecordSetChangessListAllWhenNoneExist(t *testing.T) { defer server.Close() - changes, err := client.RecordSetChangesListAll("123", ListFilter{}) + changes, err := client.RecordSetChangesListAll("123", ListFilterInt{}) if err != nil { t.Error(err) } @@ -548,7 +548,7 @@ func TestRecordSetChangesListAll(t *testing.T) { body: recordSetChangesJSON1, }, { - endpoint: "http://host.com/zones/123/recordsetchanges?startFrom=2&maxItems=1", + endpoint: "http://host.com/zones/123/recordsetchanges?maxItems=1&startFrom=2", code: 200, body: recordSetChangesJSON2, }, @@ -556,13 +556,13 @@ func TestRecordSetChangesListAll(t *testing.T) { defer server.Close() - if _, err := client.RecordSetChangesListAll("123", ListFilter{ + if _, err := client.RecordSetChangesListAll("123", ListFilterInt{ MaxItems: 200, }); err == nil { t.Error("Expected error -- MaxItems must be between 1 and 100") } - changes, err := client.RecordSetChangesListAll("123", ListFilter{ + changes, err := client.RecordSetChangesListAll("123", ListFilterInt{ MaxItems: 1, }) if err != nil { diff --git a/vinyldns/resources.go b/vinyldns/resources.go index a3b6d3b..7b0303b 100644 --- a/vinyldns/resources.go +++ b/vinyldns/resources.go @@ -50,6 +50,15 @@ type ListFilter struct { MaxItems int } +// ListFilterInt represents the list query parameters that may be passed to +// VinylDNS API endpoints such as /zones and /zones/${zone_id}/recordsets +// Same as ListFilter except for resources where StartFrom is an int instead of string +type ListFilterInt struct { + NameFilter string + StartFrom int + MaxItems int +} + // NameSort specifies the name sort order for record sets returned by the global list record set response. // Valid values are ASC (ascending; default) and DESC (descending). type NameSort string diff --git a/vinyldns/test-fixtures/recordsets/recordset-changes-list-1.json b/vinyldns/test-fixtures/recordsets/recordset-changes-list-1.json index df80988..00e95d8 100644 --- a/vinyldns/test-fixtures/recordsets/recordset-changes-list-1.json +++ b/vinyldns/test-fixtures/recordsets/recordset-changes-list-1.json @@ -1,7 +1,7 @@ { "zoneId": "123", - "startFrom": "1", - "nextId": "2", + "startFrom": 1, + "nextId": 2, "maxItems": 1, "recordSetChanges": [{ "status": "Complete", diff --git a/vinyldns/test-fixtures/recordsets/recordset-changes-list-2.json b/vinyldns/test-fixtures/recordsets/recordset-changes-list-2.json index 53d0e1b..e4cadf4 100644 --- a/vinyldns/test-fixtures/recordsets/recordset-changes-list-2.json +++ b/vinyldns/test-fixtures/recordsets/recordset-changes-list-2.json @@ -1,6 +1,6 @@ { "zoneId": "123", - "startFrom": "2", + "startFrom": 2, "maxItems": 1, "recordSetChanges": [{ "status": "Complete", diff --git a/vinyldns/util.go b/vinyldns/util.go index cf6ad31..e213735 100644 --- a/vinyldns/util.go +++ b/vinyldns/util.go @@ -14,13 +14,17 @@ package vinyldns import ( "bytes" + "crypto/sha256" + "encoding/hex" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" + "time" - awsauth "github.com/smartystreets/go-aws-auth" + awsauth "github.com/aws/aws-sdk-go-v2/aws/signer/v4" + awscred "github.com/aws/aws-sdk-go-v2/credentials" ) func concat(arr []string) string { @@ -49,17 +53,23 @@ func resourceRequest(c *Client, url, method string, body []byte, responseStruct req.Header.Set("User-Agent", c.UserAgent) req.Header.Set("Content-Type", "application/json") - awsauth.Sign4(req, awsauth.Credentials{ - AccessKeyID: c.AccessKey, - SecretAccessKey: c.SecretKey, - }) + signer := awsauth.NewSigner() + creds := awscred.NewStaticCredentialsProvider(c.AccessKey, c.SecretKey, "") + + h := sha256.New() + _, _ = io.Copy(h, bytes.NewReader(body)) + payloadHash := hex.EncodeToString(h.Sum(nil)) + err = signer.SignHTTP(nil, creds.Value, req, payloadHash, "VinylDNS", "us-east-1", time.Now()) + if err != nil { + return err + } resp, err := c.HTTPClient.Do(req) if err != nil { return err } - bodyContents, err := ioutil.ReadAll(resp.Body) + bodyContents, err := io.ReadAll(resp.Body) if logRequests() { fmt.Printf("Response status: \n\t%d\nresponse body: \n\t%s \n\n", resp.StatusCode, bodyContents) } diff --git a/vinyldns/zones_test.go b/vinyldns/zones_test.go index 8b7a9f9..7a3f456 100644 --- a/vinyldns/zones_test.go +++ b/vinyldns/zones_test.go @@ -88,7 +88,7 @@ func TestZonesListAll(t *testing.T) { body: zonesListJSON1, }, { - endpoint: "http://host.com/zones?startFrom=2&maxItems=1", + endpoint: "http://host.com/zones?maxItems=1&startFrom=2", code: 200, body: zonesListJSON2, }, @@ -656,7 +656,7 @@ func TestZoneChangesListAll(t *testing.T) { body: zoneChangesListJSON1, }, { - endpoint: "http://host.com/zones/123/changes?startFrom=2&maxItems=1", + endpoint: "http://host.com/zones/123/changes?maxItems=1&startFrom=2", code: 200, body: zoneChangesListJSON2, },