Skip to content

Commit

Permalink
update dependencies & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brucedewald committed Jun 10, 2024
1 parent 98968c0 commit 2f9e673
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 54 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
27 changes: 25 additions & 2 deletions vinyldns/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 := "?"
Expand Down
6 changes: 3 additions & 3 deletions vinyldns/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion vinyldns/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
16 changes: 8 additions & 8 deletions vinyldns/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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))
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions vinyldns/mock_testing_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package vinyldns
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
)

type testToolsConfig struct {
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions vinyldns/recordsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions vinyldns/recordsets_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
12 changes: 6 additions & 6 deletions vinyldns/recordsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -548,21 +548,21 @@ 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,
},
})

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 {
Expand Down
9 changes: 9 additions & 0 deletions vinyldns/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"zoneId": "123",
"startFrom": "1",
"nextId": "2",
"startFrom": 1,
"nextId": 2,
"maxItems": 1,
"recordSetChanges": [{
"status": "Complete",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"zoneId": "123",
"startFrom": "2",
"startFrom": 2,
"maxItems": 1,
"recordSetChanges": [{
"status": "Complete",
Expand Down
24 changes: 17 additions & 7 deletions vinyldns/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit 2f9e673

Please sign in to comment.