From 4ada4a45e7c73e34e73ce4e8a48d434e459063f6 Mon Sep 17 00:00:00 2001
From: rabbitali <shusheng.wen@outlook.com>
Date: Tue, 6 Jun 2023 16:22:54 +0800
Subject: [PATCH] update validation rules for paging parameters
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 apollo/function/schema/cve.py  | 10 +++-------
 apollo/function/schema/host.py | 10 +++-------
 apollo/function/schema/task.py | 13 ++++---------
 3 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/apollo/function/schema/cve.py b/apollo/function/schema/cve.py
index 6584941..d18e454 100644
--- a/apollo/function/schema/cve.py
+++ b/apollo/function/schema/cve.py
@@ -18,7 +18,7 @@ Description: For cve related restful interfaces schema
 from marshmallow import Schema
 from marshmallow import fields
 from marshmallow import validate
-
+from vulcanus.restful.serialize.validate import PaginationSchema
 
 class CveListFilterSchema(Schema):
     """
@@ -31,7 +31,7 @@ class CveListFilterSchema(Schema):
     fixed = fields.Boolean(required=True, default=True, validate=validate.OneOf([True, False]))
 
 
-class GetCveListSchema(Schema):
+class GetCveListSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/cve/list/get
     """
@@ -39,8 +39,6 @@ class GetCveListSchema(Schema):
         ["cve_id", "publish_time", "cvss_score", "host_num"]))
     direction = fields.String(required=False, validate=validate.OneOf(
         ["asc", "desc"]))
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(CveListFilterSchema, required=False)
 
 
@@ -65,7 +63,7 @@ class CveHostFilterSchema(Schema):
     hp_status = fields.List(fields.String(validate=validate.OneOf(["ACCEPTED", "ACTIVED"])), required=False)
 
 
-class GetCveHostsSchema(Schema):
+class GetCveHostsSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/cve/host/get
     """
@@ -74,8 +72,6 @@ class GetCveHostsSchema(Schema):
         ["last_scan"]))
     direction = fields.String(required=False, validate=validate.OneOf(
         ["asc", "desc"]))
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(CveHostFilterSchema, required=False)
 
 
diff --git a/apollo/function/schema/host.py b/apollo/function/schema/host.py
index a0cc4b5..c609fd4 100644
--- a/apollo/function/schema/host.py
+++ b/apollo/function/schema/host.py
@@ -18,7 +18,7 @@ Description: For host related restful interfaces schema
 from marshmallow import Schema
 from marshmallow import fields
 from marshmallow import validate
-
+from vulcanus.restful.serialize.validate import PaginationSchema
 
 class ScanHostFilterSchema(Schema):
     """
@@ -61,7 +61,7 @@ class GetHostListFilterSchema(Schema):
                          required=False)
 
 
-class GetHostListSchema(Schema):
+class GetHostListSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/host/list/get
     """
@@ -69,8 +69,6 @@ class GetHostListSchema(Schema):
         ["last_scan", "cve_num"]))
     direction = fields.String(required=False, validate=validate.OneOf(
         ["asc", "desc"]))
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(GetHostListFilterSchema, required=False)
 
 
@@ -96,7 +94,7 @@ class HostCvesFilterSchema(Schema):
     hp_status = fields.List(fields.String(validate=validate.OneOf(["ACCEPTED", "ACTIVED"])), required=False)
 
 
-class GetHostCvesSchema(Schema):
+class GetHostCvesSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/host/cve/get
     """
@@ -105,6 +103,4 @@ class GetHostCvesSchema(Schema):
         ["publish_time", "cvss_score"]))
     direction = fields.String(required=False, validate=validate.OneOf(
         ["asc", "desc"]))
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(HostCvesFilterSchema, required=False)
diff --git a/apollo/function/schema/task.py b/apollo/function/schema/task.py
index 415c2ca..5e8744b 100644
--- a/apollo/function/schema/task.py
+++ b/apollo/function/schema/task.py
@@ -20,6 +20,7 @@ from marshmallow import fields
 from marshmallow import validate
 
 from apollo.conf.constant import TaskType
+from vulcanus.restful.serialize.validate import PaginationSchema
 
 class TaskListFilterSchema(Schema):
     """
@@ -30,7 +31,7 @@ class TaskListFilterSchema(Schema):
         validate=validate.OneOf([getattr(TaskType,p) for p in dir(TaskType) if p.isupper()])), required=False)
 
 
-class GetTaskListSchema(Schema):
+class GetTaskListSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/task/list/get
     """
@@ -38,8 +39,6 @@ class GetTaskListSchema(Schema):
         ["host_num", "create_time"]))
     direction = fields.String(required=False, validate=validate.OneOf(
         ["asc", "desc"]))
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(TaskListFilterSchema, required=False)
 
 
@@ -105,15 +104,13 @@ class CveTaskInfoFilterSchema(Schema):
         ["succeed", "fail", "running", "unknown"])), required=False)
 
 
-class GetCveTaskInfoSchema(Schema):
+class GetCveTaskInfoSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/task/cve/info/get
     """
     task_id = fields.String(required=True, validate=lambda s: len(s) != 0)
     sort = fields.String(required=False, validate=validate.OneOf(["host_num"]))
     direction = fields.String(required=False, validate=validate.OneOf(["asc", "desc"]))
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(CveTaskInfoFilterSchema, required=False)
 
 
@@ -169,13 +166,11 @@ class RepoTaskInfoFilterSchema(Schema):
         required=False)
 
 
-class GetRepoTaskInfoSchema(Schema):
+class GetRepoTaskInfoSchema(PaginationSchema):
     """
     validators for parameter of /vulnerability/task/repo/info/get
     """
     task_id = fields.String(required=True, validate=lambda s: len(s) != 0)
-    page = fields.Integer(required=False, validate=lambda s: s > 0)
-    per_page = fields.Integer(required=False, validate=lambda s: 0 < s < 50)
     filter = fields.Nested(RepoTaskInfoFilterSchema, required=False)
 
 
-- 
Gitee

