diff --git a/octodns_edgecenter/__init__.py b/octodns_edgecenter/__init__.py index bea6fdf..5554649 100644 --- a/octodns_edgecenter/__init__.py +++ b/octodns_edgecenter/__init__.py @@ -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" @@ -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) @@ -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: diff --git a/tests/config/unit.tests.yaml b/tests/config/unit.tests.yaml index 0397d43..fdd0296 100644 --- a/tests/config/unit.tests.yaml +++ b/tests/config/unit.tests.yaml @@ -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 @@ -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 diff --git a/tests/fixtures/edgecenter-no-changes.json b/tests/fixtures/edgecenter-no-changes.json index 573f9da..0423efc 100644 --- a/tests/fixtures/edgecenter-no-changes.json +++ b/tests/fixtures/edgecenter-no-changes.json @@ -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", diff --git a/tests/fixtures/edgecenter-records.json b/tests/fixtures/edgecenter-records.json index 655c4f4..2c77694 100644 --- a/tests/fixtures/edgecenter-records.json +++ b/tests/fixtures/edgecenter-records.json @@ -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", diff --git a/tests/test_octodns_provider_edgecenter.py b/tests/test_octodns_provider_edgecenter.py index e611f9e..75280d0 100644 --- a/tests/test_octodns_provider_edgecenter.py +++ b/tests/test_octodns_provider_edgecenter.py @@ -113,7 +113,7 @@ 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( { "", @@ -121,6 +121,7 @@ def match_body(request): "_pop3._tcp", "_srv._tcp", "aaaa", + "caa", "cname", "excluded", "mx", @@ -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( @@ -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( @@ -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", @@ -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()