@@ -52,6 +52,16 @@ def _inner(*args, **kwargs):
5252 return _inner
5353
5454
55+ def validate_app_structure (value ):
56+ """Error if the dict values aren't ints >= 0."""
57+ try :
58+ for k , v in value .iteritems ():
59+ if int (v ) < 0 :
60+ raise ValueError ("Must be greater than or equal to zero" )
61+ except ValueError , err :
62+ raise ValidationError (err )
63+
64+
5565def validate_comma_separated (value ):
5666 """Error if the value doesn't look like a list of hostnames or IP addresses
5767 separated by commas.
@@ -61,14 +71,10 @@ def validate_comma_separated(value):
6171 "{} should be a comma-separated list" .format (value ))
6272
6373
64- def validate_app_structure (value ):
65- """Error if the dict values aren't ints >= 0."""
66- try :
67- for k , v in value .iteritems ():
68- if int (v ) < 0 :
69- raise ValueError ("Must be greater than or equal to zero" )
70- except ValueError , err :
71- raise ValidationError (err )
74+ def validate_domain (value ):
75+ """Error if the domain contains unexpected characters."""
76+ if not re .search (r'^[a-zA-Z0-9-\.]+$' , value ):
77+ raise ValidationError ('"{}" contains unexpected characters' .format (value ))
7278
7379
7480class AuditedModel (models .Model ):
@@ -106,7 +112,7 @@ class Cluster(UuidAuditedModel):
106112 id = models .CharField (max_length = 128 , unique = True )
107113 type = models .CharField (max_length = 16 , choices = CLUSTER_TYPES , default = 'coreos' )
108114
109- domain = models .CharField (max_length = 128 )
115+ domain = models .CharField (max_length = 128 , validators = [ validate_domain ] )
110116 hosts = models .CharField (max_length = 256 , validators = [validate_comma_separated ])
111117 auth = models .TextField ()
112118 options = JSONField (default = {}, blank = True )
0 commit comments