1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Update endpoint for Constellix provider to only include /domains when working on domain and record resources.

In order to add support for pools and other API resources from Constellix, we need to update the base URL to not contain domains and instead specify this where it's needed.
This commit is contained in:
mintopia
2020-09-10 23:52:23 +01:00
parent 6b0d9e2274
commit 5158d28b03
2 changed files with 14 additions and 13 deletions

View File

@@ -44,7 +44,7 @@ class ConstellixClientNotFound(ConstellixClientException):
class ConstellixClient(object):
BASE = 'https://api.dns.constellix.com/v1/domains'
BASE = 'https://api.dns.constellix.com/v1'
def __init__(self, api_key, secret_key, ratelimit_delay=0.0):
self.api_key = api_key
@@ -88,7 +88,7 @@ class ConstellixClient(object):
if self._domains is None:
zones = []
resp = self._request('GET', '').json()
resp = self._request('GET', '/domains').json()
zones += resp
self._domains = {'{}.'.format(z['name']): z['id'] for z in zones}
@@ -103,7 +103,7 @@ class ConstellixClient(object):
return self._request('GET', path).json()
def domain_create(self, name):
resp = self._request('POST', '/', data={'names': [name]})
resp = self._request('POST', '/domains', data={'names': [name]})
# Add newly created zone to domain cache
self._domains['{}.'.format(name)] = resp.json()[0]['id']
@@ -119,7 +119,7 @@ class ConstellixClient(object):
zone_id = self.domains.get(zone_name, False)
if not zone_id:
raise ConstellixClientNotFound()
path = '/{}/records'.format(zone_id)
path = '/domains/{}/records'.format(zone_id)
resp = self._request('GET', path).json()
for record in resp:
@@ -151,7 +151,7 @@ class ConstellixClient(object):
record_type = 'ANAME'
zone_id = self.domains.get(zone_name, False)
path = '/{}/records/{}'.format(zone_id, record_type)
path = '/domains/{}/records/{}'.format(zone_id, record_type)
self._request('POST', path, data=params)
@@ -161,7 +161,8 @@ class ConstellixClient(object):
record_type = 'ANAME'
zone_id = self.domains.get(zone_name, False)
path = '/{}/records/{}/{}'.format(zone_id, record_type, record_id)
path = '/domains/{}/records/{}/{}'.format(zone_id, record_type,
record_id)
self._request('DELETE', path)

View File

@@ -144,15 +144,15 @@ class TestConstellixProvider(TestCase):
provider._client._request.assert_has_calls([
# get all domains to build the cache
call('GET', ''),
call('GET', '/domains'),
# created the domain
call('POST', '/', data={'names': ['unit.tests']})
call('POST', '/domains', data={'names': ['unit.tests']})
])
# These two checks are broken up so that ordering doesn't break things.
# Python3 doesn't make the calls in a consistent order so different
# things follow the GET / on different runs
provider._client._request.assert_has_calls([
call('POST', '/123123/records/SRV', data={
call('POST', '/domains/123123/records/SRV', data={
'roundRobin': [{
'priority': 10,
'weight': 20,
@@ -218,14 +218,14 @@ class TestConstellixProvider(TestCase):
# recreate for update, and deletes for the 2 parts of the other
provider._client._request.assert_has_calls([
call('POST', '/123123/records/A', data={
call('POST', '/domains/123123/records/A', data={
'roundRobin': [{
'value': '3.2.3.4'
}],
'name': 'ttl',
'ttl': 300
}),
call('DELETE', '/123123/records/A/11189897'),
call('DELETE', '/123123/records/A/11189898'),
call('DELETE', '/123123/records/ANAME/11189899')
call('DELETE', '/domains/123123/records/A/11189897'),
call('DELETE', '/domains/123123/records/A/11189898'),
call('DELETE', '/domains/123123/records/ANAME/11189899')
], any_order=True)