Skip to content

Commit

Permalink
Record regions dont omit (#236)
Browse files Browse the repository at this point in the history
* Pass error on 404 instead of nil

Fixes #3

* Don't omit record regions and force them to non-null

* Setting version

* Leave distinction between null and empty

* Add test

* Update date :D

---------

Co-authored-by: Alejandro Figueroa <[email protected]>
Co-authored-by: Tomas Doran <[email protected]>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent 9510333 commit 12abb22
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.12.2 (October 17th, 2024)

BUG FIXES:

* Allowing to wipe the record regions

## 2.12.1 (Sep 23rd, 2024)

BUG FIXES:
Expand Down
2 changes: 1 addition & 1 deletion rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
clientVersion = "2.12.1"
clientVersion = "2.12.2"

defaultEndpoint = "https://api.nsone.net/v1/"
defaultShouldFollowPagination = true
Expand Down
2 changes: 1 addition & 1 deletion rest/model/dns/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Record struct {
// The records' filter chain.
Filters []*filter.Filter `json:"filters"`
// The records' regions.
Regions data.Regions `json:"regions,omitempty"`
Regions data.Regions `json:"regions"`

// Contains the key/value tag information associated to the record
Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI
Expand Down
22 changes: 14 additions & 8 deletions rest/model/dns/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ var marshalRecordCases = []struct {
"marshalCAARecord",
NewRecord("example.com", "caa.example.com", "CAA", nil, nil),
[]*Answer{NewCAAAnswer(0, "issue", "letsencrypt.org")},
[]byte(`{"meta":{},"zone":"example.com","domain":"caa.example.com","type":"CAA","answers":[{"meta":{},"answer":["0","issue","letsencrypt.org"]}],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"caa.example.com","type":"CAA","answers":[{"meta":{},"answer":["0","issue","letsencrypt.org"]}],"filters":[],"regions":{}}`),
},
{
"marshalCAARecord manual",
&Record{Zone: "example.com", Domain: "caa.example.com", Type: "CAA"},
[]*Answer{NewCAAAnswer(0, "issue", "letsencrypt.org")},
[]byte(`{"zone":"example.com","domain":"caa.example.com","type":"CAA","answers":[{"meta":{},"answer":["0","issue","letsencrypt.org"]}],"filters":null,"regions":null}`),
},
{
"marshalURLFWDRecord",
Expand All @@ -27,7 +33,7 @@ var marshalRecordCases = []struct {
NewURLFWDAnswer("/net", "https://example.net", 301, 1, 1),
NewURLFWDAnswer("/org", "https://example.org", 302, 2, 0),
},
[]byte(`{"answers":[{"answer":["/net","https://example.net",301,1,1],"meta":{}},{"answer":["/org","https://example.org",302,2,0],"meta":{}}],"meta":{},"zone":"example.com","domain":"fwd.example.com","type":"URLFWD","filters":[]}`),
[]byte(`{"answers":[{"answer":["/net","https://example.net",301,1,1],"meta":{}},{"answer":["/org","https://example.org",302,2,0],"meta":{}}],"meta":{},"zone":"example.com","domain":"fwd.example.com","type":"URLFWD","filters":[],"regions":{}}`),
},
}

Expand Down Expand Up @@ -60,19 +66,19 @@ func TestMarshalRecordsOverrideTTL(t *testing.T) {
"marshalOverrideTTLNil",
NewRecord("example.com", "example.com", "ALIAS", make(map[string]string), []string{}),
nil,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","answers":[],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","answers":[],"filters":[],"regions":{}}`),
},
{
"marshalOverrideTTLTrue",
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
&trueb,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":true,"answers":[],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":true,"answers":[],"filters":[],"regions":{}}`),
},
{
"marshalOverrideTTLFalse",
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
&falseb,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":false,"answers":[],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":false,"answers":[],"filters":[],"regions":{}}`),
},
}
for _, tt := range marshalALIASRecordCases {
Expand Down Expand Up @@ -104,21 +110,21 @@ func TestMarshalRecordsOverrideAddressRecords(t *testing.T) {
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
nil,
nil,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","answers":[],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","answers":[],"filters":[],"regions":{}}`),
},
{
"marshalOverrideAddressRecordsTrue",
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
&trueb,
&trueb,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":true,"override_address_records":true,"answers":[],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":true,"override_address_records":true,"answers":[],"filters":[],"regions":{}}`),
},
{
"marshalOverrideAddressRecordsFalse",
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
&falseb,
&falseb,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":false,"override_address_records":false,"answers":[],"filters":[]}`),
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":false,"override_address_records":false,"answers":[],"filters":[],"regions":{}}`),
},
}
for _, tt := range marshalALIASRecordCases {
Expand Down
16 changes: 8 additions & 8 deletions rest/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (s *RecordsService) Get(zone, domain, t string) (*dns.Record, *http.Respons
var r dns.Record
resp, err := s.client.Do(req, &r)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
if err.(*Error).Message == "record not found" {
if err.Message == "record not found" {
return nil, resp, ErrRecordMissing
}
}
Expand All @@ -52,9 +52,9 @@ func (s *RecordsService) Create(r *dns.Record) (*http.Response, error) {
// Update record fields with data from api(ensure consistent)
resp, err := s.client.Do(req, &r)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
switch err.(*Error).Message {
switch err.Message {
case "zone not found":
return resp, ErrZoneMissing
case "record already exists":
Expand Down Expand Up @@ -82,9 +82,9 @@ func (s *RecordsService) Update(r *dns.Record) (*http.Response, error) {
// Update records fields with data from api(ensure consistent)
resp, err := s.client.Do(req, &r)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
switch err.(*Error).Message {
switch err.Message {
case "zone not found":
return resp, ErrZoneMissing
case "record not found":
Expand Down Expand Up @@ -112,9 +112,9 @@ func (s *RecordsService) Delete(zone string, domain string, t string) (*http.Res

resp, err := s.client.Do(req, nil)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
if err.(*Error).Message == "record not found" {
if err.Message == "record not found" {
return resp, ErrRecordMissing
}
}
Expand Down

0 comments on commit 12abb22

Please sign in to comment.