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

Switch to an explicit SUPPORTS setup

This commit is contained in:
Ross McFarland
2017-06-21 17:08:16 -07:00
parent a316bf578c
commit 852c101388
11 changed files with 32 additions and 16 deletions

View File

@@ -36,7 +36,7 @@ class CloudflareProvider(BaseProvider):
'''
SUPPORTS_GEO = False
# TODO: support SRV
UNSUPPORTED_TYPES = ('ALIAS', 'NAPTR', 'PTR', 'SOA', 'SRV', 'SSHFP')
SUPPORTS = set(('A', 'AAAA', 'CNAME', 'MX', 'NS', 'SPF', 'TXT'))
MIN_TTL = 120
TIMEOUT = 15
@@ -56,9 +56,6 @@ class CloudflareProvider(BaseProvider):
self._zones = None
self._zone_records = {}
def supports(self, record):
return record._type not in self.UNSUPPORTED_TYPES
def _request(self, method, path, params=None, data=None):
self.log.debug('_request: method=%s, path=%s', method, path)
@@ -167,7 +164,7 @@ class CloudflareProvider(BaseProvider):
for record in records:
name = zone.hostname_from_fqdn(record['name'])
_type = record['type']
if _type not in self.UNSUPPORTED_TYPES:
if _type in self.SUPPORTS:
values[name][record['type']].append(record)
for name, types in values.items():

View File

@@ -91,6 +91,8 @@ class DnsimpleProvider(BaseProvider):
account: 42
'''
SUPPORTS_GEO = False
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR',
'SPF', 'SRV', 'SSHFP', 'TXT'))
def __init__(self, id, token, account, *args, **kwargs):
self.log = logging.getLogger('DnsimpleProvider[{}]'.format(id))

View File

@@ -106,6 +106,7 @@ class DynProvider(BaseProvider):
than one account active at a time. See DynProvider._check_dyn_sess for some
related bits.
'''
RECORDS_TO_TYPE = {
'a_records': 'A',
'aaaa_records': 'AAAA',
@@ -121,6 +122,7 @@ class DynProvider(BaseProvider):
'txt_records': 'TXT',
}
TYPE_TO_RECORDS = {v: k for k, v in RECORDS_TO_TYPE.items()}
SUPPORTS = set(TYPE_TO_RECORDS.keys())
# https://help.dyn.com/predefined-geotm-regions-groups/
REGION_CODES = {

View File

@@ -22,6 +22,9 @@ class Ns1Provider(BaseProvider):
api_key: env/NS1_API_KEY
'''
SUPPORTS_GEO = False
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR',
'SPF', 'SRV', 'TXT'))
ZONE_NOT_FOUND_MESSAGE = 'server error: zone not found'
def __init__(self, id, api_key, *args, **kwargs):
@@ -30,9 +33,6 @@ class Ns1Provider(BaseProvider):
super(Ns1Provider, self).__init__(id, *args, **kwargs)
self._client = NSONE(apiKey=api_key)
def supports(self, record):
return record._type != 'SSHFP'
def _data_for_A(self, _type, record):
return {
'ttl': record['ttl'],

View File

@@ -14,6 +14,8 @@ from .base import BaseProvider
class PowerDnsBaseProvider(BaseProvider):
SUPPORTS_GEO = False
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR',
'SPF', 'SSHFP', 'SRV', 'TXT'))
TIMEOUT = 5
def __init__(self, id, host, api_key, port=8081, *args, **kwargs):

View File

@@ -220,6 +220,8 @@ class Route53Provider(BaseProvider):
In general the account used will need full permissions on Route53.
'''
SUPPORTS_GEO = True
SUPPORTS = set(('A', 'AAAA', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR', 'SPF',
'SRV', 'TXT'))
# This should be bumped when there are underlying changes made to the
# health check config.
@@ -239,9 +241,6 @@ class Route53Provider(BaseProvider):
self._r53_rrsets = {}
self._health_checks = None
def supports(self, record):
return record._type not in ('ALIAS', 'SSHFP')
@property
def r53_zones(self):
if self._r53_zones is None:

View File

@@ -31,6 +31,8 @@ class YamlProvider(BaseProvider):
enforce_order: True
'''
SUPPORTS_GEO = True
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR',
'SSHFP', 'SPF', 'SRV', 'TXT'))
def __init__(self, id, directory, default_ttl=3600, enforce_order=True,
*args, **kwargs):

View File

@@ -16,6 +16,9 @@ class BaseSource(object):
if not hasattr(self, 'SUPPORTS_GEO'):
raise NotImplementedError('Abstract base class, SUPPORTS_GEO '
'property missing')
if not hasattr(self, 'SUPPORTS'):
raise NotImplementedError('Abstract base class, SUPPORTS '
'property missing')
def populate(self, zone, target=False):
'''
@@ -25,9 +28,7 @@ class BaseSource(object):
'missing')
def supports(self, record):
# Unless overriden and handled appropriaitely we'll assume that all
# record types are supported
return True
return record._type in self.SUPPORTS
def __repr__(self):
return self.__class__.__name__

View File

@@ -19,6 +19,7 @@ from .base import BaseSource
class TinyDnsBaseSource(BaseSource):
SUPPORTS_GEO = False
SUPPORTS = set(('A', 'CNAME', 'MX', 'NS'))
split_re = re.compile(r':+')

View File

@@ -17,6 +17,7 @@ class SimpleSource(object):
class SimpleProvider(object):
SUPPORTS_GEO = False
SUPPORTS = set(('A',))
def __init__(self, id='test'):
pass

View File

@@ -16,6 +16,8 @@ from octodns.zone import Zone
class HelperProvider(BaseProvider):
log = getLogger('HelperProvider')
SUPPORTS = set(('A',))
def __init__(self, extra_changes, apply_disabled=False,
include_change_callback=None):
self.__extra_changes = extra_changes
@@ -58,10 +60,17 @@ class TestBaseProvider(TestCase):
zone = Zone('unit.tests.', [])
with self.assertRaises(NotImplementedError) as ctx:
HasSupportsGeo('hassupportesgeo').populate(zone)
self.assertEquals('Abstract base class, SUPPORTS property missing',
ctx.exception.message)
class HasSupports(HasSupportsGeo):
SUPPORTS = set(('A',))
with self.assertRaises(NotImplementedError) as ctx:
HasSupports('hassupportes').populate(zone)
self.assertEquals('Abstract base class, populate method missing',
ctx.exception.message)
class HasPopulate(HasSupportsGeo):
class HasPopulate(HasSupports):
def populate(self, zone, target=False):
zone.add_record(Record.new(zone, '', {
@@ -81,7 +90,7 @@ class TestBaseProvider(TestCase):
'value': '1.2.3.4'
}))
self.assertTrue(HasSupportsGeo('hassupportesgeo')
self.assertTrue(HasSupports('hassupportesgeo')
.supports(list(zone.records)[0]))
plan = HasPopulate('haspopulate').plan(zone)