summaryrefslogtreecommitdiff
path: root/designate/objects/fields.py
diff options
context:
space:
mode:
authordekehn <dekehn@gmail.com>2022-01-20 20:38:06 +0000
committerDon Kehn <dekehn@gmail.com>2022-02-03 19:08:10 +0000
commitee678b69c4e320846c9f49913e16e5a161225b23 (patch)
tree27118583b76a763bd81b42711a411c588cdff3c5 /designate/objects/fields.py
parenta9ab61bc1d98248af108d895ce2cb7696818dcda (diff)
downloaddesignate-ee678b69c4e320846c9f49913e16e5a161225b23.tar.gz
Checks for invalid denylist regex patterns
Adds new field check method DenyListFields to validate the pattern string. in addition, check for a zero length string as well. Closes-Bug: #1934252 Change-Id: I2b69025fc11125bb73a4e0f8c0dedad951399cbf
Diffstat (limited to 'designate/objects/fields.py')
-rw-r--r--designate/objects/fields.py22
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