diff options
Diffstat (limited to 'designate/objects/fields.py')
-rw-r--r-- | designate/objects/fields.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/designate/objects/fields.py b/designate/objects/fields.py index 19a52c0d..7f2f76ff 100644 --- a/designate/objects/fields.py +++ b/designate/objects/fields.py @@ -425,3 +425,25 @@ class IPOrHost(IPV4AndV6AddressField): if not re.match(StringFields.RE_ZONENAME, value): raise ValueError("%s is not IP address or host name" % value) return value + + +class DenylistFields(StringFields): + def __init__(self, **kwargs): + super(DenylistFields, self).__init__(**kwargs) + + def coerce(self, obj, attr, value): + value = super(DenylistFields, self).coerce(obj, attr, value) + + if value is None: + return self._null(obj, attr) + + # determine the validity if a regex expression filter has been used. + msg = ("%s is not a valid regular expression" % value) + if not len(value): + raise ValueError(msg) + try: + re.compile(value) + except Exception: + raise ValueError(msg) + + return value |