Skip to content

Commit

Permalink
Merge pull request #49 from baest/support_ds_record
Browse files Browse the repository at this point in the history
Add support for the DS record
  • Loading branch information
ross authored Sep 19, 2023
2 parents 6caaf91 + 09fb14a commit bdbc4b7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions octodns_powerdns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PowerDnsBaseProvider(BaseProvider):
'ALIAS',
'CAA',
'CNAME',
'DS',
'LOC',
'MX',
'NAPTR',
Expand Down Expand Up @@ -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']:
Expand Down Expand Up @@ -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}
Expand Down
20 changes: 16 additions & 4 deletions tests/config/unit.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/powerdns-full-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_octodns_provider_powerdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ 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:
mock.get(ANY, status_code=200, text=FULL_TEXT)

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))

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bdbc4b7

Please sign in to comment.