Skip to content

Commit

Permalink
Merge pull request #89 from octodns/invalid-continent
Browse files Browse the repository at this point in the history
Throw error on unsupported continents
  • Loading branch information
viranch authored Sep 12, 2024
2 parents de8828c + 0e33b69 commit 5070452
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
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}')

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

0 comments on commit 5070452

Please sign in to comment.