clearml-server/apiserver/apimodels/custom_validators/__init__.py
allegroai b97a6084ce Refactor configuration infrastructure
Remove untracked files left from previous commit
2021-01-05 18:25:18 +02:00

35 lines
910 B
Python

import validators
from jsonmodels.errors import ValidationError
class ForEach(object):
def __init__(self, validator):
self.validator = validator
def validate(self, values):
for value in values:
self.validator.validate(value)
def modify_schema(self, field_schema):
return self.validator.modify_schema(field_schema)
class Hostname(object):
def validate(self, value):
if validators.domain(value) is not True:
raise ValidationError(f"Value '{value}' is not a valid hostname")
def modify_schema(self, field_schema):
field_schema["format"] = "hostname"
class Email(object):
def validate(self, value):
if validators.email(value) is not True:
raise ValidationError(f"Value '{value}' is not a valid email address")
def modify_schema(self, field_schema):
field_schema["format"] = "email"