Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record regions dont omit #236

Merged
merged 9 commits into from
Oct 17, 2024
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
Loading