From db62f099a3c98a00fcdaf35d8daed67f7329875b Mon Sep 17 00:00:00 2001 From: Martin Frausing Date: Mon, 18 Sep 2023 13:32:27 +0200 Subject: [PATCH] Add support for the DS record (with updated field names) Also updated tests to add a new DS record for a sub zone along with updates since an existing DS records is now handled Depends on https://github.com/octodns/octodns/pull/1065 --- octodns_powerdns/__init__.py | 26 +++++++++++++++++++++++++ tests/config/unit.tests.yaml | 20 +++++++++++++++---- tests/fixtures/powerdns-full-data.json | 12 ++++++++++++ tests/test_octodns_provider_powerdns.py | 6 +++--- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/octodns_powerdns/__init__.py b/octodns_powerdns/__init__.py index 4efd4af..240a113 100644 --- a/octodns_powerdns/__init__.py +++ b/octodns_powerdns/__init__.py @@ -38,6 +38,7 @@ class PowerDnsBaseProvider(BaseProvider): 'ALIAS', 'CAA', 'CNAME', + 'DS', 'LOC', 'MX', 'NAPTR', @@ -170,6 +171,22 @@ def _data_for_TLSA(self, rrset): ) return {'type': rrset['type'], 'values': values, 'ttl': rrset['ttl']} + def _data_for_DS(self, rrset): + values = [] + for record in rrset['records']: + (key_tag, algorithm, digest_type, digest) = record['content'].split( + ' ', 3 + ) + values.append( + { + 'key_tag': key_tag, + 'algorithm': algorithm, + 'digest_type': digest_type, + 'digest': digest, + } + ) + return {'type': rrset['type'], 'values': values, 'ttl': rrset['ttl']} + def _data_for_CAA(self, rrset): values = [] for record in rrset['records']: @@ -466,6 +483,15 @@ def _records_for_TLSA(self, record): for v in record.values ], record._type + def _records_for_DS(self, record): + return [ + { + 'content': f'{v.key_tag} {v.algorithm} {v.digest_type} {v.digest}', + 'disabled': False, + } + for v in record.values + ], record._type + def _records_for_CAA(self, record): return [ {'content': f'{v.flags} {v.tag} "{v.value}"', 'disabled': False} diff --git a/tests/config/unit.tests.yaml b/tests/config/unit.tests.yaml index 61ba9cb..ef7bfcb 100644 --- a/tests/config/unit.tests.yaml +++ b/tests/config/unit.tests.yaml @@ -37,6 +37,12 @@ - flags: 0 tag: issue value: ca.unit.tests + - type: 'DS' + values: + - algorithm: 13 + digest: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF + digest_type: 2 + key_tag: 2371 _853._tcp: type: TLSA values: @@ -174,10 +180,16 @@ spf: type: SPF value: v=spf1 ip4:192.168.0.1/16-all sub: - type: 'NS' - values: - - 6.2.3.4. - - 7.2.3.4. + - type: 'NS' + values: + - 6.2.3.4. + - 7.2.3.4. + - type: 'DS' + values: + - algorithm: 13 + digest: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF + digest_type: 2 + key_tag: 12345 txt: ttl: 600 type: TXT diff --git a/tests/fixtures/powerdns-full-data.json b/tests/fixtures/powerdns-full-data.json index 0efbdd8..9081fcf 100644 --- a/tests/fixtures/powerdns-full-data.json +++ b/tests/fixtures/powerdns-full-data.json @@ -335,6 +335,18 @@ "ttl": 42, "type": "LUA" + }, + { + "comments": [], + "name": "sub.unit.tests.", + "records": [ + { + "content": "12345 13 2 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF", + "disabled": false + } + ], + "ttl": 3600, + "type": "DS" } ], "serial": 2017012803, diff --git a/tests/test_octodns_provider_powerdns.py b/tests/test_octodns_provider_powerdns.py index abde3b5..28fbdd9 100644 --- a/tests/test_octodns_provider_powerdns.py +++ b/tests/test_octodns_provider_powerdns.py @@ -288,7 +288,7 @@ def test_provider(self): ) source.populate(expected) expected_n = len(expected.records) - 4 - self.assertEqual(21, expected_n) + self.assertEqual(23, expected_n) # No diffs == no changes with requests_mock() as mock: @@ -296,7 +296,7 @@ def test_provider(self): zone = Zone('unit.tests.', []) provider.populate(zone) - self.assertEqual(21, len(zone.records)) + self.assertEqual(23, len(zone.records)) changes = expected.changes(zone, provider) self.assertEqual(0, len(changes)) @@ -393,7 +393,7 @@ def test_small_change(self): 'test', join(dirname(__file__), 'config'), supports_root_ns=False ) source.populate(expected) - self.assertEqual(25, len(expected.records)) + self.assertEqual(27, len(expected.records)) # A small change to a single record with requests_mock() as mock: