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

Throw error on unsupported continents #89

Merged
merged 2 commits into from
Sep 12, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* DNAME, DS, and TLSA record type support added.
* Validate that healthcheck protocol is supported (HTTP, HTTPS, ICMP, TCP)
* Validate that continent is supported (Antarctica is supported by octoDNS but not by NS1)

## v0.0.7 - 2023-11-14 - Maintenance release

Expand Down
11 changes: 11 additions & 0 deletions octodns_ns1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,17 @@ def _process_desired_zone(self, desired):
# no workable fallbacks so straight error
raise SupportsException(f'{self.id}: {msg}')

# validate supported geos
for rule in record.dynamic.rules:
for geo in rule.data.get('geos', []):
if (
len(geo) == 2
and geo not in self._REGION_TO_CONTINENT.values()
):
msg = f'unsupported continent code {geo} in {record.fqdn}'
# no workable fallbacks so straight error
raise SupportsException(f'{self.id}: {msg}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only potential fallback type behavior I can think of would be ignoring the unsupported continent and letting things match whatever the other rules would do, presumably that'd be a default in the specific case here.

That'd probably require removing the code if there are other valid ones or the whole rule if nothing is valid with the warn if strict stuff. Not sure if that's worth it, but it would at least allow other providers to still target the unsupported stuff while managing things in parallel to NS1 rather than preventing them from being used.

Up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and if the whole rule to be removed points to an exclusively used pool, that would have to be determined and removed too.

Not opposed to it but also don't have enough incentive to implement it that way (yet).


return super()._process_desired_zone(desired)

def _params_for_geo_A(self, record):
Expand Down
32 changes: 32 additions & 0 deletions tests/test_provider_ns1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,38 @@ def test_monitor_is_match(self):
)
)

def test_unsupported_continent(self):
provider = Ns1Provider('test', 'api-key')
desired = Zone('unit.tests.', [])
record = Record.new(
desired,
'a',
{
'ttl': 30,
'type': 'A',
'value': '1.2.3.4',
'dynamic': {
'pools': {
'one': {'values': [{'value': '1.2.3.4'}]},
'two': {'values': [{'value': '2.2.3.4'}]},
},
'rules': [{'geos': ['AN'], 'pool': 'two'}, {'pool': 'one'}],
},
},
lenient=True,
)
desired.add_record(record)
with self.assertRaises(SupportsException) as ctx:
provider._process_desired_zone(desired)
self.assertEqual(
'test: unsupported continent code AN in a.unit.tests.',
str(ctx.exception),
)

record.dynamic.rules[0].data['geos'][0] = 'NA'
got = provider._process_desired_zone(desired)
self.assertEqual(got.records, desired.records)

def test_unsupported_healthcheck_protocol(self):
provider = Ns1Provider('test', 'api-key')
desired = Zone('unit.tests.', [])
Expand Down
Loading