Skip to content

Commit

Permalink
Merge branch 'main' into update_makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay07GIT authored Jun 13, 2024
2 parents b3cc5fb + a38e17c commit 8a1f31e
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 59 deletions.
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ SHELL=bash
VERSION=0.9.16
SOURCE?=./...
VINYLDNS_REPO=github.com/vinyldns/vinyldns
VINYLDNS_VERSION=0.9.10
VINYLDNS_DIR="$(GOPATH)/src/$(VINYLDNS_REPO)/"
VINYLDNS_VERSION=latest

# Check that the required version of make is being used
REQ_MAKE_VER:=3.82
Expand Down Expand Up @@ -42,22 +43,26 @@ integration: start-api
validate-version:
cat vinyldns/version.go | grep 'var Version = "$(VERSION)"'

.PHONY: start-api
start-api:
if [ ! -d "$(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)" ]; then \
echo "$(VINYLDNS_REPO)-$(VINYLDNS_VERSION) not found in your GOPATH (necessary for acceptance tests), getting..."; \
.PHONY: clone-vinyl
clone-vinyl:
if [ ! -d $(VINYLDNS_DIR) ]; then \
echo "$(VINYLDNS_REPO) not found in your GOPATH (necessary for acceptance tests), getting..."; \
git clone \
--branch v$(VINYLDNS_VERSION) \
https://$(VINYLDNS_REPO) \
$(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION); \
$(VINYLDNS_DIR); \
else \
git -C $(VINYLDNS_DIR) pull ; \
fi
$(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)/bin/docker-up-vinyldns.sh \
--api-only \
--version $(VINYLDNS_VERSION)

.PHONY: start-api
start-api: clone-vinyl stop-api
$(GOPATH)/src/$(VINYLDNS_REPO)/quickstart/quickstart-vinyldns.sh \
--api --version-tag $(VINYLDNS_VERSION)

.PHONY: stop-api
stop-api:
$(GOPATH)/src/$(VINYLDNS_REPO)-$(VINYLDNS_VERSION)/bin/remove-vinyl-containers.sh
$(GOPATH)/src/$(VINYLDNS_REPO)/quickstart/quickstart-vinyldns.sh \
--clean

.PHONY: build
build:
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=
23 changes: 21 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 ListFilterRecordSetChanges) string {
query := buildRecordSetChangesQuery(f)

return concatStrs("", zoneEP(c, zoneID), "/recordsetchanges", query)
}
Expand Down Expand Up @@ -133,6 +133,25 @@ func buildQuery(f ListFilter, nameFilterName string) string {
return query + strings.Join(params, "&")
}

func buildRecordSetChangesQuery(f ListFilterRecordSetChanges) string {
params := []string{}
query := "?"

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", ListFilterRecordSetChanges{})
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", ListFilterRecordSetChanges{
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, ListFilterRecordSetChanges{})
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, ListFilterRecordSetChanges{
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, ListFilterRecordSetChanges{})
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 ListFilterRecordSetChanges) (*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 ListFilterRecordSetChanges) ([]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 int `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", ListFilterRecordSetChanges{})
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", ListFilterRecordSetChanges{
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", ListFilterRecordSetChanges{
MaxItems: 1,
})
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions vinyldns/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ type ListFilter struct {
MaxItems int
}

// ListFilterRecordSetChanges represents the list query parameters that may be passed to
// VinylDNS API endpoint /zones/${zone_id}/recordsetchanges
type ListFilterRecordSetChanges struct {
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
Loading

0 comments on commit 8a1f31e

Please sign in to comment.