aops-vulcanus/0002-add-custom-validation-rules.patch
wenxin 7f62801dbf fix script bug and add validation rules
(cherry picked from commit 7dd30863c11d48136ac5872297b11c12fc90e817)
2023-04-27 20:34:07 +08:00

79 lines
2.7 KiB
Diff

From e1a72048bed334ff2e5014e2437598aa5580760f Mon Sep 17 00:00:00 2001
From: rabbitali <shusheng.wen@outlook.com>
Date: Wed, 26 Apr 2023 19:25:32 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?=
=?UTF-8?q?=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99;=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E7=9A=84=E8=B7=AF=E7=94=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
vulcanus/conf/constant.py | 1 +
vulcanus/restful/serialize/validate.py | 31 ++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/vulcanus/conf/constant.py b/vulcanus/conf/constant.py
index 9779602..7185685 100644
--- a/vulcanus/conf/constant.py
+++ b/vulcanus/conf/constant.py
@@ -53,6 +53,7 @@ GET_GROUP = "/manage/host/group/get"
COLLECT_CONFIG = '/manage/config/collect'
USER_LOGIN = "/manage/account/login"
+LOGOUT = "/manage/account/logout"
CHANGE_PASSWORD = '/manage/account/change'
ADD_USER = '/manage/account/add'
GITEE_AUTH_LOGIN = "/manage/account/gitee/login"
diff --git a/vulcanus/restful/serialize/validate.py b/vulcanus/restful/serialize/validate.py
index bfe25ad..1c00804 100644
--- a/vulcanus/restful/serialize/validate.py
+++ b/vulcanus/restful/serialize/validate.py
@@ -15,6 +15,7 @@ Time:
Author:
Description:
"""
+import re
from marshmallow import ValidationError
@@ -42,3 +43,33 @@ def validate(verifier, data, load=False):
errors = verifier().validate(data)
return result, errors
+
+
+class ValidateRules:
+ """
+ Custom validation rules
+ """
+
+ @staticmethod
+ def space_character_check(string: str) -> None:
+ """
+ one of validation rules for string, no spaces are allowed at the beginning or end.
+ """
+ if len(string.strip()) != len(string):
+ raise ValidationError("there may be space character exists at the beginning or end!")
+
+ @staticmethod
+ def account_name_check(string: str) -> None:
+ """
+ validation rules for username, which only contains string or number
+ """
+ if not re.findall("[a-zA-Z0-9]{5,20}", string):
+ raise ValidationError("username should only contains string or number, between 5 and 20 characters!")
+
+ @staticmethod
+ def account_password_check(string: str) -> None:
+ """
+ validation rules for password, which only contains string or number
+ """
+ if not re.findall("[a-zA-Z0-9]{6,20}", string):
+ raise ValidationError("password should only contains string or number, between 6 and 20 characters!!")
\ No newline at end of file
--
Gitee