Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVCB and HTTPS record type support #70

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions octodns_powerdns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
from octodns.record import Record
from octodns.record.ds import DsValue

try: # pragma: no cover
from octodns.record.https import HttpsValue
from octodns.record.svcb import SvcbValue

SUPPORTS_SVCB = True
except ImportError: # pragma: no cover
SUPPORTS_SVCB = False

from .record import PowerDnsLuaRecord

# TODO: remove __VERSION__ with the next major version release
Expand Down Expand Up @@ -55,6 +63,11 @@ class PowerDnsBaseProvider(BaseProvider):
PowerDnsLuaRecord._type,
)
)
# These are only supported if we have a new enough octoDNS core
if SUPPORTS_SVCB: # pragma: no cover
SUPPORTS.add('HTTPS')
SUPPORTS.add('SVCB')

TIMEOUT = 5

POWERDNS_MODES_OF_OPERATION = {
Expand Down Expand Up @@ -327,6 +340,20 @@ def _data_for_SRV(self, rrset):
)
return {'type': rrset['type'], 'values': values, 'ttl': rrset['ttl']}

def _data_for_HTTPS(self, rrset):
values = []
for record in rrset['records']:
value = HttpsValue.parse_rdata_text(record['content'])
values.append(value)
return {'type': rrset['type'], 'values': values, 'ttl': rrset['ttl']}

def _data_for_SVCB(self, rrset):
values = []
for record in rrset['records']:
value = SvcbValue.parse_rdata_text(record['content'])
values.append(value)
return {'type': rrset['type'], 'values': values, 'ttl': rrset['ttl']}

def _data_for_LUA(self, rrset):
values = []
for record in rrset['records']:
Expand Down Expand Up @@ -593,6 +620,13 @@ def _records_for_SRV(self, record):
for v in record.values
], record._type

def _records_for_SVCB(self, record):
return [
{'content': v.rdata_text, 'disabled': False} for v in record.values
], record._type

_records_for_HTTPS = _records_for_SVCB

def _records_for_PowerDnsProvider_LUA(self, record):
return [
{'content': f'{v._type} "{v.script}"', 'disabled': False}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dnspython==2.6.1
fqdn==1.5.1
idna==3.7
natsort==8.4.0
octodns==1.7.0
octodns==1.9.1
python-dateutil==2.9.0.post0
requests==2.32.2
six==1.16.0
Expand Down
12 changes: 12 additions & 0 deletions tests/config/unit.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ excluded:
- test
type: CNAME
value: unit.tests.
https:
type: HTTPS
value:
svcpriority: 1
targetname: www.unit.tests.
ignored:
octodns:
ignored: true
Expand Down Expand Up @@ -190,6 +195,13 @@ sub:
flags: 12345
protocol: 13
public_key: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
svcb:
type: SVCB
values:
- svcpriority: 1
targetname: www.unit.tests.
- svcpriority: 2
targetname: backups.unit.tests.
txt:
ttl: 600
type: TXT
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/powerdns-full-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@
],
"ttl": 3600,
"type": "DS"
},
{
"comments": [],
"name": "https.unit.tests.",
"records": [
{
"content": "1 www.unit.tests.",
"disabled": false
}
],
"ttl": 3600,
"type": "HTTPS"
},
{
"comments": [],
"name": "svcb.unit.tests.",
"records": [
{
"content": "1 www.unit.tests.",
"disabled": false
},
{
"content": "2 backups.unit.tests.",
"disabled": false
}
],
"ttl": 3600,
"type": "SVCB"
}
],
"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 @@ -294,15 +294,15 @@ def test_provider(self):
)
source.populate(expected)
expected_n = len(expected.records) - 4
self.assertEqual(23, expected_n)
self.assertEqual(25, 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(23, len(zone.records))
self.assertEqual(25, len(zone.records))
changes = expected.changes(zone, provider)
self.assertEqual(0, len(changes))

Expand Down Expand Up @@ -399,7 +399,7 @@ def test_small_change(self):
'test', join(dirname(__file__), 'config'), supports_root_ns=False
)
source.populate(expected)
self.assertEqual(27, len(expected.records))
self.assertEqual(29, len(expected.records))

# A small change to a single record
with requests_mock() as mock:
Expand Down
Loading