Skip to content

Commit

Permalink
record tag support
Browse files Browse the repository at this point in the history
  • Loading branch information
ponbiki committed Oct 10, 2023
1 parent b69b849 commit 7be307b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 10 additions & 8 deletions rest/model/dns/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ func (r *Record) String() string {

// NewRecord takes a zone, domain and record type t and creates a *Record with
// UseClientSubnet: true & empty Answers.
func NewRecord(zone string, domain string, t string) *Record {
func NewRecord(zone string, domain string, t string, tags map[string]string, blockedTags []string) *Record {
if !strings.HasSuffix(strings.ToLower(domain), strings.ToLower(zone)) {
domain = fmt.Sprintf("%s.%s", domain, zone)
}
return &Record{
Meta: &data.Meta{},
Zone: zone,
Domain: domain,
Type: t,
Answers: []*Answer{},
Filters: []*filter.Filter{},
Regions: data.Regions{},
Meta: &data.Meta{},
Zone: zone,
Domain: domain,
Type: t,
Answers: []*Answer{},
Filters: []*filter.Filter{},
Regions: data.Regions{},
Tags: tags,
BlockedTags: blockedTags,
}
}

Expand Down
18 changes: 9 additions & 9 deletions rest/model/dns/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ var marshalRecordCases = []struct {
}{
{
"marshalCAARecord",
NewRecord("example.com", "caa.example.com", "CAA"),
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":[]}`),
},
{
"marshalURLFWDRecord",
NewRecord("example.com", "fwd.example.com", "URLFWD"),
NewRecord("example.com", "fwd.example.com", "URLFWD", nil, nil),
[]*Answer{
NewURLFWDAnswer("/net", "https://example.net", 301, 1, 1),
NewURLFWDAnswer("/org", "https://example.org", 302, 2, 0),
Expand Down Expand Up @@ -58,19 +58,19 @@ func TestMarshalRecordsOverrideTTL(t *testing.T) {
}{
{
"marshalOverrideTTLNil",
NewRecord("example.com", "example.com", "ALIAS"),
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
nil,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","answers":[],"filters":[]}`),
},
{
"marshalOverrideTTLTrue",
NewRecord("example.com", "example.com", "ALIAS"),
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
&trueb,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":true,"answers":[],"filters":[]}`),
},
{
"marshalOverrideTTLFalse",
NewRecord("example.com", "example.com", "ALIAS"),
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
&falseb,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","override_ttl":false,"answers":[],"filters":[]}`),
},
Expand Down Expand Up @@ -101,21 +101,21 @@ func TestMarshalRecordsOverrideAddressRecords(t *testing.T) {
}{
{
"marshalOverrideAddressRecordsNil",
NewRecord("example.com", "example.com", "ALIAS"),
NewRecord("example.com", "example.com", "ALIAS", nil, nil),
nil,
nil,
[]byte(`{"meta":{},"zone":"example.com","domain":"example.com","type":"ALIAS","answers":[],"filters":[]}`),
},
{
"marshalOverrideAddressRecordsTrue",
NewRecord("example.com", "example.com", "ALIAS"),
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":[]}`),
},
{
"marshalOverrideAddressRecordsFalse",
NewRecord("example.com", "example.com", "ALIAS"),
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":[]}`),
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestNewRecord(t *testing.T) {
}
for _, tt := range CapitalLettersCases {
t.Run(tt.name, func(t *testing.T) {
record := NewRecord(tt.zone, tt.domain, "A")
record := NewRecord(tt.zone, tt.domain, "A", nil, nil)
assert.Equal(t, tt.ExpectedDomain, record.Domain)
assert.Equal(t, tt.ExpectedZone, record.Zone)
})
Expand Down

0 comments on commit 7be307b

Please sign in to comment.