Skip to content

Commit

Permalink
Support caa records
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei38 committed Aug 12, 2024
1 parent 00be767 commit e26af80
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
27 changes: 26 additions & 1 deletion octodns_edgecenter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _BaseProvider(BaseProvider):
SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = True
SUPPORTS_ROOT_NS = True
SUPPORTS = {"A", "AAAA", "NS", "MX", "TXT", "SRV", "CNAME", "PTR"}
SUPPORTS = {"A", "AAAA", "NS", "MX", "TXT", "SRV", "CNAME", "PTR", "CAA"}
DEFAULT_POOL = "other"
WEIGHT_POOL = "weight"
BACKUP_POOL = "backup"
Expand Down Expand Up @@ -358,6 +358,22 @@ def _data_for_CNAME(self, _type, record):
"value": self._add_dot_if_need(defaults[0]),
}

def _data_for_CAA(self, _type, record):
values = []
for rr in record["resource_records"]:
values.append(
{
"flags": rr["content"][0],
"tag": rr["content"][1],
"value": rr["content"][2],
}
)
return {
"ttl": record["ttl"],
"type": _type,
"value": values,
}

def _data_for_multiple(self, _type, record):
if record.get("filters") is not None:
pools, rules, defaults = self._data_for_dynamic(record)
Expand Down Expand Up @@ -674,6 +690,15 @@ def _params_for_CNAME(self, record):

return {"ttl": record.ttl, **extra}

def _params_for_CAA(self, record):
return {
"ttl": record.ttl,
"resource_records": [
{"content": [value.flags, value.tag, value.value]}
for value in record.values
],
}

def _params_for_multiple(self, record):
extra = dict()
if record.dynamic:
Expand Down
11 changes: 6 additions & 5 deletions tests/config/unit.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
values:
- ns1.edgedns.ru.
- ns2.edgedns.ru.
- type: CAA
values:
- flags: 0
tag: issue
value: ca.unit.tests
_imap._tcp:
ttl: 600
type: SRV
Expand Down Expand Up @@ -69,6 +64,12 @@ aaaa:
ttl: 600
type: AAAA
value: 2601:644:500:e210:62f8:1dff:feb8:947a
caa:
type: CAA
values:
- flags: 0
tag: issue
value: ca.unit.tests
cname:
ttl: 300
type: CNAME
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/edgecenter-no-changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@
}
]
},
{
"name": "caa.unit.tests",
"resource_records": [
{
"content": [
0,
"issue",
"ca.unit.tests"
]
}
],
"ttl": 3600,
"type": "CAA"
},
{
"name": "cname.unit.tests",
"type": "CNAME",
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/edgecenter-records.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@
}
]
},
{
"name": "caa.unit.tests",
"resource_records": [
{
"content": [
0,
"issue",
"ca.unit.tests"
]
}
],
"ttl": 3600,
"type": "CAA"
},
{
"name": "cname.unit.tests",
"type": "CNAME",
Expand Down
19 changes: 14 additions & 5 deletions tests/test_octodns_provider_edgecenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ def match_body(request):

zone = Zone("unit.tests.", [])
provider.populate(zone)
self.assertEqual(14, len(zone.records))
self.assertEqual(15, len(zone.records))
self.assertEqual(
{
"",
"_imap._tcp",
"_pop3._tcp",
"_srv._tcp",
"aaaa",
"caa",
"cname",
"excluded",
"mx",
Expand All @@ -143,7 +144,7 @@ def match_body(request):

zone = Zone("unit.tests.", [])
provider.populate(zone, lenient=True)
self.assertEqual(16, len(zone.records))
self.assertEqual(17, len(zone.records))
changes = self.expected.changes(zone, provider)
self.assertEqual(11, len(changes))
self.assertEqual(
Expand Down Expand Up @@ -234,8 +235,8 @@ def test_apply(self):
plan = provider.plan(self.expected)

# TC: create all
self.assertEqual(14, len(plan.changes))
self.assertEqual(14, provider.apply(plan))
self.assertEqual(15, len(plan.changes))
self.assertEqual(15, provider.apply(plan))
self.assertFalse(plan.exists)

provider._client._request.assert_has_calls(
Expand Down Expand Up @@ -310,6 +311,14 @@ def test_apply(self):
],
},
),
call(
'POST',
'http://api/zones/unit.tests/caa.unit.tests./CAA',
data={
'ttl': 3600,
'resource_records': [{'content': [0, 'issue', 'ca.unit.tests']}]
}
),
call(
"POST",
"http://api/zones/unit.tests/cname.unit.tests./CNAME",
Expand Down Expand Up @@ -394,7 +403,7 @@ def test_apply(self):
]
)
# expected number of total calls
self.assertEqual(17, provider._client._request.call_count)
self.assertEqual(18, provider._client._request.call_count)

# TC: delete 1 and update 1
provider._client._request.reset_mock()
Expand Down

0 comments on commit e26af80

Please sign in to comment.