Browse Source

Merge branch 'master' into dependabot/pip/boto3-1.11.13

pull/484/head
Ross McFarland 6 years ago
committed by GitHub
parent
commit
67d69153a5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions
  1. +10
    -5
      octodns/provider/dnsimple.py
  2. +6
    -0
      tests/test_octodns_provider_dnsimple.py

+ 10
- 5
octodns/provider/dnsimple.py View File

@ -30,16 +30,19 @@ class DnsimpleClientUnauthorized(DnsimpleClientException):
class DnsimpleClient(object):
BASE = 'https://api.dnsimple.com/v2/'
def __init__(self, token, account):
def __init__(self, token, account, sandbox):
self.account = account
sess = Session()
sess.headers.update({'Authorization': 'Bearer {}'.format(token)})
self._sess = sess
if sandbox:
self.base = 'https://api.sandbox.dnsimple.com/v2/'
else:
self.base = 'https://api.dnsimple.com/v2/'
def _request(self, method, path, params=None, data=None):
url = '{}{}{}'.format(self.BASE, self.account, path)
url = '{}{}{}'.format(self.base, self.account, path)
resp = self._sess.request(method, url, params=params, json=data)
if resp.status_code == 401:
raise DnsimpleClientUnauthorized()
@ -89,17 +92,19 @@ class DnsimpleProvider(BaseProvider):
token: letmein
# Your account number (required)
account: 42
# Use sandbox (optional)
sandbox: true
'''
SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = False
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'NAPTR', 'NS',
'PTR', 'SPF', 'SRV', 'SSHFP', 'TXT'))
def __init__(self, id, token, account, *args, **kwargs):
def __init__(self, id, token, account, sandbox=False, *args, **kwargs):
self.log = logging.getLogger('DnsimpleProvider[{}]'.format(id))
self.log.debug('__init__: id=%s, token=***, account=%s', id, account)
super(DnsimpleProvider, self).__init__(id, *args, **kwargs)
self._client = DnsimpleClient(token, account)
self._client = DnsimpleClient(token, account, sandbox)
self._zone_records = {}


+ 6
- 0
tests/test_octodns_provider_dnsimple.py View File

@ -38,7 +38,13 @@ class TestDnsimpleProvider(TestCase):
break
def test_populate(self):
# Sandbox
provider = DnsimpleProvider('test', 'token', 42, 'true')
self.assertTrue('sandbox' in provider._client.base)
provider = DnsimpleProvider('test', 'token', 42)
self.assertFalse('sandbox' in provider._client.base)
# Bad auth
with requests_mock() as mock:


Loading…
Cancel
Save