diff --git a/CHANGELOG.md b/CHANGELOG.md index fe1a30d..8601be1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/octodns_ns1/__init__.py b/octodns_ns1/__init__.py index 324eb8a..6f73be6 100644 --- a/octodns_ns1/__init__.py +++ b/octodns_ns1/__init__.py @@ -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): diff --git a/tests/test_provider_ns1.py b/tests/test_provider_ns1.py index 5246553..395e522 100644 --- a/tests/test_provider_ns1.py +++ b/tests/test_provider_ns1.py @@ -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.', [])