From 9fa5bac24881e9a29107d4aad29f70f5943d5b46 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Sun, 8 Sep 2024 14:18:51 -0700 Subject: [PATCH 1/2] Throw error on unsupported continents --- octodns_ns1/__init__.py | 11 +++++++++++ tests/test_provider_ns1.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) 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.', []) From 0e33b69084d0549e4b3cdfc05af46d406c6f4ef4 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Sun, 8 Sep 2024 14:21:58 -0700 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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