class PetitionParams(params.ParamSet): __datatype__ = "json" privilege_id = params.IntegerField(required=True) privilege_name = params.RegexField(pattern=r'[\w_-]+', required=True) node_id = params.Field() privilege_model = params.Field() def validate_privilege_id(self, pid): self.data['privilege_model'] = PrivilegeType.query.options( undefer_group("audit")).get_or_raise(pid) self.data['node_id'] = int(self.privilege_model.node_id) return pid
class APIParams(params.ParamSet): __datatype__ = 'json' id = params.IntegerField(required=True, min=1) token = params.Field(required=True, length=32) headers = params.Field() tag = params.WordField(PARAMS_TAG_MSG, length=8, default='foo') from_ = params.WordField(PARAMS_FROM, key='from', required=False, length=16) text_anyway = params.WordField() text_not_null = params.WordField(null=False)
class AuthorizeParams(params.ParamSet): __datatype__ = "json" privilege_type = params.WordField(required=True) privilege_name = params.RegexField(pattern=r'[\w_-]+', required=True) username = params.Field() hostname = params.Field() node_id = params.IntegerField() token = params.Field() def validate_privilege_type(self, value): try: return get_privilege_by_name(value) except KeyError: raise errors.ValidationError("privilege_type %s not existed" % value)
class ApplyParams(params.ParamSet): __datatype__ = "json" sn = params.RegexField(pattern="[a-zA-Z0-9-]+", required=True) hostname_prefix = params.RegexField(pattern="[a-zA-Z0-9-_]") hostname_pattern = params.RegexField(pattern="[a-zA-Z0-9*-_]") type = params.WordField(required=True) idc = params.WordField(required=True) network = params.Field() def validate_network(self, data): try: return IPv4Network(unicode(data)) except Exception as e: raise ValidationError(str(e)) def validate_type(self, data): try: return ServerType(data) except ValueError as e: raise ValidationError(str(e)) def validate_hostname_pattern(self, value): if value.count("*") != 1: raise ValidationError('pattern must have 1 star(*) placeholder') return value
class FakeParams(params.ParamSet): id = params.IntegerField('wat are you?', required=True, min=0) name = params.WordField( 'name should be a 1~8 length string, and is required', required=True, length=(1, 8)) email = params.EmailField( 'email should be a valid email format, and is required', required=True) content = params.Field('content should be a 1~20 length string', length=(1, 20))
class APIParams(params.ParamSet): id = params.IntegerField(PARAMS_ID_MSG, required=True, min=1) token = params.Field(PARAMS_TOKEN_MSG, required=True, length=32) tag = params.WordField(PARAMS_TAG_MSG, length=8, default='foo') from_ = params.WordField(PARAMS_FROM, key='from', required=False, length=16) text_anyway = params.WordField() text_not_null = params.WordField(null=False)
class NodeServersPostParams(params.ParamSet): __datatype__ = 'json' server_ids = params.ListField('server_ids invalid', item_field=params.IntegerField(), required=True) traffic_ratio = params.Field("ratio invalid", required=True) def validate_traffic_ratio(self, value): try: if value is None: return None ratio = str(value) v = D(ratio) except Exception as e: raise errors.ValidationError(str(e)) return v
class ApplyParams(params.ParamSet): __datatype__ = "json" node_id = params.IntegerField(required=True) privilege_type = params.WordField(required=True) privilege_names = params.ListField(item_field=params.RegexField( pattern=r'[\w_-]+')) token = params.Field() def validate_privilege_type(self, data): try: return get_privilege_by_name(data) except KeyError: raise errors.ValidationError("privilege_type %s not existed" % data) def validate_token(self, value): if value: if not decrypt_token(value, settings.AUTH_TOKEN_PREFIX): raise errors.ValidationError('Invalid token value') return value
class LoginParams(params.ParamSet): username = params.RegexField(pattern=r'^[\w\.]+$', required=True) password = params.Field(length=(6, 0), required=True, null=False) redirect = params.Field()
class TemplateParams(params.ParamSet): __datatype__ = 'json' type = params.Field(required=True) parameters = params.Field(required=True)