Browse Source

YamlProvider.SUPPORTS dynamically returns the list of registered types

pull/924/head
Ross McFarland 3 years ago
parent
commit
2e3d325f71
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
4 changed files with 34 additions and 22 deletions
  1. +8
    -20
      octodns/provider/yaml.py
  2. +4
    -0
      octodns/record/__init__.py
  3. +18
    -2
      tests/test_octodns_provider_yaml.py
  4. +4
    -0
      tests/test_octodns_record.py

+ 8
- 20
octodns/provider/yaml.py View File

@ -111,26 +111,6 @@ class YamlProvider(BaseProvider):
SUPPORTS_DYNAMIC = True SUPPORTS_DYNAMIC = True
SUPPORTS_POOL_VALUE_STATUS = True SUPPORTS_POOL_VALUE_STATUS = True
SUPPORTS_MULTIVALUE_PTR = True SUPPORTS_MULTIVALUE_PTR = True
SUPPORTS = set(
(
'A',
'AAAA',
'ALIAS',
'CAA',
'CNAME',
'DNAME',
'LOC',
'MX',
'NAPTR',
'NS',
'PTR',
'SSHFP',
'SPF',
'SRV',
'TXT',
'URLFWD',
)
)
def __init__( def __init__(
self, self,
@ -167,6 +147,14 @@ class YamlProvider(BaseProvider):
del args['log'] del args['log']
return self.__class__(**args) return self.__class__(**args)
@property
def SUPPORTS(self):
# The yaml provider supports all record types even those defined by 3rd
# party modules that we know nothing about, thus we dynamically return
# the types list that is registered in Record, everything that's know as
# of the point in time we're asked
return set(Record.registered_types().keys())
def supports(self, record): def supports(self, record):
# We're overriding this as a performance tweak, namely to avoid calling # We're overriding this as a performance tweak, namely to avoid calling
# the implementation of the SUPPORTS property to create a set from a # the implementation of the SUPPORTS property to create a set from a


+ 4
- 0
octodns/record/__init__.py View File

@ -102,6 +102,10 @@ class Record(EqualityTupleMixin):
raise RecordException(msg) raise RecordException(msg)
cls._CLASSES[_type] = _class cls._CLASSES[_type] = _class
@classmethod
def registered_types(cls):
return cls._CLASSES
@classmethod @classmethod
def new(cls, zone, name, data, source=None, lenient=False): def new(cls, zone, name, data, source=None, lenient=False):
name = str(name).lower() name = str(name).lower()


+ 18
- 2
tests/test_octodns_provider_yaml.py View File

@ -15,7 +15,7 @@ from unittest import TestCase
from yaml import safe_load from yaml import safe_load
from yaml.constructor import ConstructorError from yaml.constructor import ConstructorError
from octodns.record import Create
from octodns.record import _NsValue, Create, Record, ValuesMixin
from octodns.provider.base import Plan from octodns.provider.base import Plan
from octodns.provider.yaml import ( from octodns.provider.yaml import (
_list_all_yaml_files, _list_all_yaml_files,
@ -217,7 +217,23 @@ class TestYamlProvider(TestCase):
str(ctx.exception), str(ctx.exception),
) )
def test_supports_everything(self):
def test_SUPPORTS(self):
source = YamlProvider('test', join(dirname(__file__), 'config'))
# make sure the provider supports all the registered types
self.assertEqual(Record.registered_types().keys(), source.SUPPORTS)
class YamlRecord(ValuesMixin, Record):
_type = 'YAML'
_value_type = _NsValue
# don't know anything about a yaml type
self.assertTrue('YAML' not in source.SUPPORTS)
# register it
Record.register_type(YamlRecord)
# when asked again we'll now include it in our list of supports
self.assertTrue('YAML' in source.SUPPORTS)
def test_supports(self):
source = YamlProvider('test', join(dirname(__file__), 'config')) source = YamlProvider('test', join(dirname(__file__), 'config'))
class DummyType(object): class DummyType(object):


+ 4
- 0
tests/test_octodns_record.py View File

@ -69,6 +69,8 @@ class TestRecord(TestCase):
_type = 'AA' _type = 'AA'
_value_type = _NsValue _value_type = _NsValue
self.assertTrue('AA' not in Record.registered_types())
Record.register_type(AaRecord) Record.register_type(AaRecord)
aa = Record.new( aa = Record.new(
self.zone, self.zone,
@ -77,6 +79,8 @@ class TestRecord(TestCase):
) )
self.assertEqual(AaRecord, aa.__class__) self.assertEqual(AaRecord, aa.__class__)
self.assertTrue('AA' in Record.registered_types())
def test_lowering(self): def test_lowering(self):
record = ARecord( record = ARecord(
self.zone, 'MiXeDcAsE', {'ttl': 30, 'type': 'A', 'value': '1.2.3.4'} self.zone, 'MiXeDcAsE', {'ttl': 30, 'type': 'A', 'value': '1.2.3.4'}


Loading…
Cancel
Save