2424PROCTYPE_MATCH = re .compile (r'^(?P<type>[a-z0-9]+(\-[a-z0-9]+)*)$' )
2525PROCTYPE_MISMATCH_MSG = "Process types can only contain lowercase alphanumeric characters"
2626MEMLIMIT_MATCH = re .compile (
27- r'^(?P<mem>(( [0-9]+(MB|KB|GB|[BKMG])|0)(/([0-9]+(MB|KB|GB|[BKMG])))? ))$' , re .IGNORECASE )
27+ r'^(?P<mem>([0-9]+(MB|KB|GB|[BKMG])|0))$' , re .IGNORECASE )
2828CPUSHARE_MATCH = re .compile (
29- r'^(?P<cpu>(( [-+]?[0-9]*\.?[0-9]+[m]?)(/([-+]?[0-9]*\.?[0-9]+[m]?)) ?))$' )
29+ r'^(?P<cpu>([-+]?[0-9]*\.?[0-9]+[m]?))$' )
3030TAGVAL_MATCH = re .compile (r'^(?:[a-zA-Z\d][-\.\w]{0,61})?[a-zA-Z\d]$' )
3131CONFIGKEY_MATCH = re .compile (r'^[a-z_]+[a-z0-9_]*$' , re .IGNORECASE )
3232TERMINATION_GRACE_PERIOD_MATCH = re .compile (r'^[0-9]*$' )
3333VOLUME_SIZE_MATCH = re .compile (
34- r'^(?P<mem>(( [0-9]+(MB|KB|GB|[BKMG])|0)(/([0-9]+(MB|KB|GB|[BKMG])))? ))$' , re .IGNORECASE )
34+ r'^(?P<mem>([0-9]+(MB|KB|GB|[BKMG])|0))$' , re .IGNORECASE )
3535VOLUME_PATH = re .compile (r'^\/(\w+\/?)+$' , re .IGNORECASE )
3636
3737PROBE_SCHEMA = {
@@ -201,7 +201,8 @@ class Meta:
201201 fields = ['owner' , 'app' , 'image' , 'stack' , 'sha' , 'procfile' ,
202202 'dockerfile' , 'created' , 'updated' , 'uuid' ]
203203
204- def validate_procfile (self , data ):
204+ @staticmethod
205+ def validate_procfile (data ):
205206 for key , value in data .items ():
206207 if value is None or value == "" :
207208 raise serializers .ValidationError ("Command can't be empty for process type" )
@@ -233,7 +234,8 @@ class Meta:
233234 model = models .Config
234235 fields = '__all__'
235236
236- def validate_values (self , data ):
237+ @staticmethod
238+ def validate_values (data ):
237239 for key , value in data .items ():
238240 if value is None : # use NoneType to unset an item
239241 continue
@@ -278,7 +280,8 @@ def validate_values(self, data):
278280
279281 return data
280282
281- def validate_memory (self , data ):
283+ @staticmethod
284+ def validate_memory (data ):
282285 for key , value in data .items ():
283286 if value is None : # use NoneType to unset an item
284287 continue
@@ -288,12 +291,13 @@ def validate_memory(self, data):
288291
289292 if not re .match (MEMLIMIT_MATCH , str (value )):
290293 raise serializers .ValidationError (
291- "Memory limit format: <number><unit> or <number><unit>/<number><unit> , "
294+ "Memory limit format: <number><unit>, "
292295 "where unit = B, K, M or G" )
293296
294297 return data
295298
296- def validate_cpu (self , data ):
299+ @staticmethod
300+ def validate_cpu (data ):
297301 for key , value in data .items ():
298302 if value is None : # use NoneType to unset an item
299303 continue
@@ -304,11 +308,12 @@ def validate_cpu(self, data):
304308 shares = re .match (CPUSHARE_MATCH , str (value ))
305309 if not shares :
306310 raise serializers .ValidationError (
307- "CPU limit format: <value> or <value>/<value> , where value must be a numeric" )
311+ "CPU limit format: <value>, where value must be a numeric" )
308312
309313 return data
310314
311- def validate_termination_grace_period (self , data ):
315+ @staticmethod
316+ def validate_termination_grace_period (data ):
312317 for key , value in data .items ():
313318 if value is None : # use NoneType to unset an item
314319 continue
@@ -323,7 +328,8 @@ def validate_termination_grace_period(self, data):
323328
324329 return data
325330
326- def validate_tags (self , data ):
331+ @staticmethod
332+ def validate_tags (data ):
327333 for key , value in data .items ():
328334 if value is None : # use NoneType to unset an item
329335 continue
@@ -357,7 +363,8 @@ def validate_tags(self, data):
357363
358364 return data
359365
360- def validate_registry (self , data ):
366+ @staticmethod
367+ def validate_registry (data ):
361368 for key , value in data .items ():
362369 if value is None : # use NoneType to unset an item
363370 continue
@@ -369,7 +376,8 @@ def validate_registry(self, data):
369376
370377 return data
371378
372- def validate_healthcheck (self , data ):
379+ @staticmethod
380+ def validate_healthcheck (data ):
373381 for procType , healthcheck in data .items ():
374382 if healthcheck is None :
375383 continue
@@ -432,7 +440,8 @@ class Meta:
432440 fields = ['owner' , 'created' , 'updated' , 'app' , 'domain' ]
433441 read_only_fields = ['uuid' ]
434442
435- def validate_domain (self , value ):
443+ @staticmethod
444+ def validate_domain (value ):
436445 """
437446 Check that the hostname is valid
438447 """
@@ -496,13 +505,15 @@ class Meta:
496505 fields = ['owner' , 'created' , 'updated' , 'app' , 'procfile_type' , 'path_pattern' ]
497506 read_only_fields = ['uuid' ]
498507
499- def validate_procfile_type (self , value ):
508+ @staticmethod
509+ def validate_procfile_type (value ):
500510 if not re .match (PROCTYPE_MATCH , value ):
501511 raise serializers .ValidationError (PROCTYPE_MISMATCH_MSG )
502512
503513 return value
504514
505- def validate_path_pattern (self , value ):
515+ @staticmethod
516+ def validate_path_pattern (value ):
506517 for pattern in str (value ).split ("," ):
507518 if not pattern .strip ():
508519 raise serializers .ValidationError (
@@ -561,7 +572,8 @@ class Meta:
561572 model = models .AppSettings
562573 fields = '__all__'
563574
564- def validate_whitelist (self , data ):
575+ @staticmethod
576+ def validate_whitelist (data ):
565577 for address in data :
566578 try :
567579 ipaddress .ip_address (address )
@@ -577,7 +589,8 @@ def validate_whitelist(self, data):
577589
578590 return data
579591
580- def validate_autoscale (self , data ):
592+ @staticmethod
593+ def validate_autoscale (data ):
581594 schema = {
582595 "$schema" : "http://json-schema.org/schema#" ,
583596 "type" : "object" ,
@@ -632,14 +645,16 @@ class Meta:
632645 model = models .Volume
633646 fields = '__all__'
634647
635- def validate_size (self , data ):
648+ @staticmethod
649+ def validate_size (data ):
636650 if not re .match (VOLUME_SIZE_MATCH , str (data )):
637651 raise serializers .ValidationError (
638652 "Volume size limit format: <number><unit> or <number><unit>/<number><unit>, "
639653 "where unit = B, K, M or G" )
640654 return data
641655
642- def validate_path (self , data ):
656+ @staticmethod
657+ def validate_path (data ):
643658 for key , value in data .items ():
644659 if value is None : # use NoneType to unset an item
645660 continue
0 commit comments