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 CAA support. Fixes #35 #36

Merged
merged 1 commit into from
Sep 28, 2023
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
23 changes: 22 additions & 1 deletion octodns_gcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class _BaseProvider(BaseProvider):
SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = True
SUPPORTS = set(
("A", "AAAA", 'ALIAS', "NS", "MX", "TXT", "SRV", "CNAME", "PTR")
("A", "AAAA", "ALIAS", "CAA", "NS", "MX", "TXT", "SRV", "CNAME", "PTR")
)

def __init__(self, id, api_url, auth_url, *args, **kwargs):
Expand Down Expand Up @@ -354,6 +354,18 @@ def _data_for_SRV(self, _type, record):
],
}

def _data_for_CAA(self, _type, record):
return {
"ttl": record["ttl"],
"type": _type,
"values": [
dict(flags=flags, tag=tag, value=value)
for flags, tag, value in map(
lambda x: x["content"], record["resource_records"]
)
],
}

def zone_records(self, zone):
try:
return self._client.zone_records(zone.name[:-1]), True
Expand Down Expand Up @@ -559,6 +571,15 @@ def _params_for_SRV(self, record):
],
}

def _params_for_CAA(self, record):
return {
"ttl": record.ttl,
"resource_records": [
{"content": [rec.flags, rec.tag, rec.value]}
for rec in record.values
],
}

def _apply_create(self, change):
self.log.info("creating: %s", change)
new = change.new
Expand Down
3 changes: 2 additions & 1 deletion tests/config/unit.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
values:
- ns1.gcorelabs.net.
- ns2.gcdn.services.
- type: CAA
- ttl: 300
type: CAA
values:
- flags: 0
tag: issue
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/gcore-no-changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
}
]
},
{
"name": "unit.tests",
"type": "CAA",
"ttl": 300,
"resource_records": [
{
"content": [
0,
"issue",
"ca.unit.tests"
]
}
]
},
{
"name": "unit.tests",
"type": "NS",
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/gcore-records.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
}
]
},
{
"name": "unit.tests",
"type": "CAA",
"ttl": 300,
"resource_records": [
{
"content": [
0,
"issue",
"ca.unit.tests"
]
}
]
},
{
"name": "unit.tests",
"type": "NS",
Expand Down
20 changes: 15 additions & 5 deletions tests/test_octodns_provider_gcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
"",
Expand Down Expand Up @@ -143,7 +143,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(
Expand Down Expand Up @@ -257,8 +257,8 @@ def test_apply(self):
plan = provider.plan(self.expected)

# TC: create all
self.assertEqual(13, len(plan.changes))
self.assertEqual(13, provider.apply(plan))
self.assertEqual(14, len(plan.changes))
self.assertEqual(14, provider.apply(plan))
self.assertFalse(plan.exists)

provider._client._request.assert_has_calls(
Expand All @@ -281,6 +281,16 @@ def test_apply(self):
],
},
),
call(
"POST",
"http://api/zones/unit.tests/unit.tests./CAA",
data={
"ttl": 300,
"resource_records": [
{"content": [0, "issue", "ca.unit.tests"]}
],
},
),
call(
"POST",
"http://api/zones/unit.tests/_imap._tcp.unit.tests./SRV",
Expand Down Expand Up @@ -406,7 +416,7 @@ def test_apply(self):
]
)
# expected number of total calls
self.assertEqual(16, provider._client._request.call_count)
self.assertEqual(17, provider._client._request.call_count)

# TC: delete 1 and update 1
provider._client._request.reset_mock()
Expand Down
Loading