Skip to content

Commit ff6ce1f

Browse files
authored
m Merge pull request #4 from tonysurfly/caa
Add CAA records support
2 parents f06818d + d6f69e8 commit ff6ce1f

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ functionality can easily be extended to support other Constellix resources.
3131
- [x] A
3232
- [x] AAAA
3333
- [x] ANAME
34-
- [ ] CAA
34+
- [x] CAA
3535
- [ ] CERT
3636
- [x] CNAME
3737
- [ ] HINFO

cmd/dns_domain_record_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,60 @@ notes: ""
655655
Compare(objJ, expectedValue, t)
656656
Compare(objY, expectedValue, t)
657657
}
658+
659+
func TestExpectedDNSRecord_CAA_Unmarshal(t *testing.T) {
660+
dataY := `
661+
name: ""
662+
type: CAA
663+
ttl: 18
664+
mode: standard
665+
region: default
666+
enabled: true
667+
value:
668+
- tag: issue
669+
data: letsencrypt.org
670+
flags: 0
671+
enabled: true
672+
- tag: issue
673+
data: pki.goog; cansignhttpexchanges=yes
674+
flags: 0
675+
enabled: true
676+
`
677+
dataJ := `{"id":58345378,"name":"","type":"CAA","ttl":18,"mode":"standard","region":"default","enabled":true,"value":[{"tag":"issue","data":"letsencrypt.org","flags":0,"enabled":true},{"tag":"issue","data":"pki.goog; cansignhttpexchanges=yes","flags":0,"enabled":true}]}`
678+
679+
expectedValue := []*DNSCAAStandardItemValue{
680+
{Tag: "issue", Data: "letsencrypt.org", Flags: 0, Enabled: true},
681+
{Tag: "issue", Data: "pki.goog; cansignhttpexchanges=yes", Flags: 0, Enabled: true},
682+
}
683+
684+
var objY ExpectedDNSRecord
685+
err := yaml.Unmarshal([]byte(dataY), &objY)
686+
if err != nil {
687+
t.Fatal(err)
688+
}
689+
690+
var objJ ExpectedDNSRecord
691+
err = json.Unmarshal([]byte(dataJ), &objJ)
692+
if err != nil {
693+
t.Fatal(err)
694+
}
695+
696+
if objJ.Type != "CAA" {
697+
t.Errorf("expected %q, got %q", "CAA", objJ.Type)
698+
}
699+
700+
res, ok := objJ.Value.([]*DNSCAAStandardItemValue)
701+
if !ok {
702+
t.Fatalf("unexpected type %T", objJ.Value)
703+
}
704+
705+
if len(res) != len(expectedValue) {
706+
t.Errorf("expected %d items, got %d", len(expectedValue), len(res))
707+
}
708+
709+
for i, v := range res {
710+
if !reflect.DeepEqual(v, expectedValue[i]) {
711+
t.Errorf("item %d: expected %+v, got %+v", i, expectedValue[i], v)
712+
}
713+
}
714+
}

cmd/dns_domain_record_value.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ type DNSMXStandardItemValue struct {
2929
Enabled bool `json:"enabled" yaml:"enabled"`
3030
}
3131

32+
type DNSCAAStandardItemValue struct {
33+
Tag string `json:"tag" yaml:"tag"`
34+
Data string `json:"data" yaml:"data"`
35+
Flags int `json:"flags" yaml:"flags"`
36+
Enabled bool `json:"enabled" yaml:"enabled"`
37+
}
38+
3239
type DNSHTTPStandardItemValue struct {
3340
Hard bool `json:"hard" yaml:"hard"`
3441
RedirectType string `json:"redirectType" yaml:"redirectType"`
@@ -202,6 +209,29 @@ func populateDNSRecordValue(record interface{}) error {
202209
valueObj.Keywords, _ = m["keywords"].(string)
203210
valueObj.Description, _ = m["description"].(string)
204211
s.Value = valueObj
212+
case "CAA":
213+
if s.Mode != "standard" {
214+
return fmt.Errorf("unsupported mode %q for CAA record", s.Mode)
215+
}
216+
m, ok := s.Value.([]interface{})
217+
if !ok {
218+
return fmt.Errorf("unable to parse value for CAA record in standard mode, expected an array")
219+
}
220+
valueObj := make([]*DNSCAAStandardItemValue, 0)
221+
for _, el := range m {
222+
elMap, ok := el.(map[string]interface{})
223+
if !ok {
224+
return fmt.Errorf("unable to parse value for CAA record in standard mode, expected a map")
225+
}
226+
valueEl := DNSCAAStandardItemValue{
227+
Tag: elMap["tag"].(string),
228+
Data: elMap["data"].(string),
229+
Flags: toInt(elMap["flags"]),
230+
Enabled: elMap["enabled"].(bool),
231+
}
232+
valueObj = append(valueObj, &valueEl)
233+
}
234+
s.Value = valueObj
205235
default:
206236
return fmt.Errorf("unsupported record type %q", s.Type)
207237
}

0 commit comments

Comments
 (0)