[node-patches] Change in ovirt-node[master]: Make FQDN validator abide by RFC1035
rbarry at redhat.com
rbarry at redhat.com
Tue Jun 11 22:59:59 UTC 2013
Ryan Barry has uploaded a new change for review.
Change subject: Make FQDN validator abide by RFC1035
......................................................................
Make FQDN validator abide by RFC1035
Check for the length of each field as well as the entire
hostname to make sure it's not too long
Change-Id: I30c2b822070bee3452071bf29d111cc12bda02d4
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/valid.py
1 file changed, 36 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/82/15582/1
diff --git a/src/ovirt/node/valid.py b/src/ovirt/node/valid.py
index d9928b0..91c5a60 100644
--- a/src/ovirt/node/valid.py
+++ b/src/ovirt/node/valid.py
@@ -279,6 +279,42 @@
pattern = ("^(([0-9]\.)?([a-z]|[a-z][a-z0-9\-]*[a-z0-9])\.)*" +
"([a-z]|[a-z][a-z0-9\-]*[a-z0-9])$", re.I)
+ def validate(self, value):
+ FQDNLength()(value)
+ return super(FQDN, self).validate(value)
+
+
+class FQDNLength(Validator):
+ """Matches a FQDN and ensures that fields are 63 character or less
+ per level
+
+ >>> FQDNLength().validate(r'1234567890123456789012345678901234567890123456\
+78901234567890123.com')
+ True
+ >>> FQDNLength().validate('1234567890123456789012345678901234567890123456\
+789012345678901234.com')
+ False
+ """
+
+ description = "a field less than 64 characters"
+
+ def validate(self, value):
+ is_valid = True
+ fields = {k: value.split(".")[k] for k in range(len(value.split(".")))}
+ for k, v in fields.items():
+ valid = True if len(v) < 64 else False
+ if valid is False:
+ self.description = "less than 64 characters in the {index}" + \
+ "section".format(index=self.ordinal(k))
+ is_valid = False
+ return is_valid
+
+ def ordinal(self, n):
+ if 10 <= n % 100 < 20:
+ return str(n) + 'th'
+ else:
+ return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, "th")
+
class IPv4Address(Validator):
"""Matches IPv4 addresses
--
To view, visit http://gerrit.ovirt.org/15582
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I30c2b822070bee3452071bf29d111cc12bda02d4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>
More information about the node-patches
mailing list