From 46420edcb9195e0e83383c1029f4930673d785d1 Mon Sep 17 00:00:00 2001 From: Martin Frausing Date: Mon, 18 Sep 2023 12:18:07 +0200 Subject: [PATCH 1/2] Add support for the DS record Also updated tests to add a new DS record for a sub zone along with updates since an existing DS records is now handled --- 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..3ee0648 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']: + (flags, protocol, algorithm, public_key) = record['content'].split( + ' ', 3 + ) + values.append( + { + 'flags': flags, + 'protocol': protocol, + 'algorithm': algorithm, + 'public_key': public_key, + } + ) + 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.flags} {v.protocol} {v.algorithm} {v.public_key}', + '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..32ebcb7 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: 2 + flags: 2371 + protocol: 13 + public_key: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF _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: 2 + flags: 12345 + protocol: 13 + public_key: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF 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: From 09fb14ac8d25a1e027c3b1336a558aba59f816e0 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Tue, 19 Sep 2023 15:33:17 -0700 Subject: [PATCH 2/2] DS CHANGELOG.md entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4cd334..f886fd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.0.6 - 2023-??-?? - ??? + +* DS Record support added + ## v0.0.5 - 2023-09-12 - Known your zones * Adds Provider.list_zones to enable new dynamic zone config functionality