From 79a4af04556d904f9f4e4b9d9a91b54652b9f287 Mon Sep 17 00:00:00 2001 From: James Li Date: Wed, 27 Jan 2016 05:03:48 +0000 Subject: [PATCH] Make supported record type configurable Also made the distinction between 'valid' and 'supported' record types. For example an error of "'foo' is not a valid record type" will return when user tries to create a record type of 'foo'. User will get "'SPF' is not a supported record type" if operator chooses not to expose SPF. Implements blueprint configurable-record-type Change-Id: I22410a760a5ec78270162496ee03f2b2b8ba7d25 --- designate/__init__.py | 5 +++ designate/objects/recordset.py | 36 +++++++++++++------- doc/source/examples/basic-config-sample.conf | 3 ++ etc/designate/designate.conf.sample | 3 ++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/designate/__init__.py b/designate/__init__.py index 85a8970a7..6295de4a7 100644 --- a/designate/__init__.py +++ b/designate/__init__.py @@ -58,6 +58,11 @@ cfg.CONF.register_opts([ cfg.IntOpt('default-soa-retry', default=600), cfg.IntOpt('default-soa-expire', default=86400), cfg.IntOpt('default-soa-minimum', default=3600), + + # Supported record types + cfg.ListOpt('supported-record-type', help='Supported record types', + default=['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF', 'NS', + 'PTR', 'SSHFP', 'SOA']), ]) # Set some Oslo Log defaults diff --git a/designate/objects/recordset.py b/designate/objects/recordset.py index 38682248c..c2aca26ce 100644 --- a/designate/objects/recordset.py +++ b/designate/objects/recordset.py @@ -16,6 +16,7 @@ import logging from copy import deepcopy +from oslo_config import cfg import six from designate import exceptions @@ -27,6 +28,8 @@ from designate.objects.validation_error import ValidationErrorList LOG = logging.getLogger(__name__) +cfg.CONF.import_opt('supported_record_type', 'designate') + class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin, base.DesignateObject): @@ -105,8 +108,6 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin, 'schema': { 'type': 'string', 'description': 'RecordSet type (TODO: Make types extensible)', - 'enum': ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF', 'NS', - 'PTR', 'SSHFP', 'SOA'] }, 'required': True, 'immutable': True @@ -137,6 +138,18 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin, # }, } + def _validate_fail(self, errors, msg): + e = ValidationError() + e.path = ['recordset', 'type'] + e.validator = 'value' + e.validator_value = [self.type] + e.message = msg + # Add it to the list for later + errors.append(e) + raise exceptions.InvalidObject( + "Provided object does not match " + "schema", errors=errors, object=self) + def validate(self): LOG.debug("Validating '%(name)s' object with values: %(values)r", { @@ -151,17 +164,14 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin, record_list_cls = self.obj_cls_from_name('%sList' % self.type) record_cls = self.obj_cls_from_name(self.type) except KeyError as e: - e = ValidationError() - e.path = ['recordset', 'type'] - e.validator = 'value' - e.validator_value = [self.type] - e.message = ("'%(type)s' is not a supported Record type" - % {'type': self.type}) - # Add it to the list for later - errors.append(e) - raise exceptions.InvalidObject( - "Provided object does not match " - "schema", errors=errors, object=self) + err_msg = ("'%(type)s' is not a valid record type" + % {'type': self.type}) + self._validate_fail(errors, err_msg) + + if self.type not in cfg.CONF.supported_record_type: + err_msg = ("'%(type)s' is not a supported record type" + % {'type': self.type}) + self._validate_fail(errors, err_msg) # Get any rules that the record type imposes on the record changes = record_cls.get_recordset_schema_changes() diff --git a/doc/source/examples/basic-config-sample.conf b/doc/source/examples/basic-config-sample.conf index fbde0aa8f..592007158 100644 --- a/doc/source/examples/basic-config-sample.conf +++ b/doc/source/examples/basic-config-sample.conf @@ -22,6 +22,9 @@ notification_driver = messaging # Change to "sudo" to skip the filtering and just run the command directly # root_helper = sudo +# Supported record types +#supported_record_type = A, AAAA, CNAME, MX, SRV, TXT, SPF, NS, PTR, SSHFP, SOA + # RabbitMQ Config rabbit_userid = designate rabbit_password = designate diff --git a/etc/designate/designate.conf.sample b/etc/designate/designate.conf.sample index 8acc51176..315a36b41 100644 --- a/etc/designate/designate.conf.sample +++ b/etc/designate/designate.conf.sample @@ -34,6 +34,9 @@ debug = False # Which networking API to use, Defaults to neutron #network_api = neutron +# Supported record types +#supported_record_type = A, AAAA, CNAME, MX, SRV, TXT, SPF, NS, PTR, SSHFP, SOA + #----------------------- # RabbitMQ Config #-----------------------