Skip to content

Commit

Permalink
Throw error on unsupported continents
Browse files Browse the repository at this point in the history
  • Loading branch information
viranch committed Sep 8, 2024
1 parent de8828c commit 9fa5bac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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 9fa5bac

Please sign in to comment.