From 47a4c1d6488f07aa55621454fefedb559fc1bbf8 Mon Sep 17 00:00:00 2001
From: rabbitali <wenxin32@foxmail.com>
Date: Wed, 20 Dec 2023 16:26:24 +0800
Subject: [PATCH] update verification method for host ip fieldl;fix repo
 field filter error

---
 apollo/database/proxy/cve.py   | 8 ++++++--
 apollo/function/schema/cve.py  | 2 +-
 apollo/function/schema/task.py | 6 +++---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/apollo/database/proxy/cve.py b/apollo/database/proxy/cve.py
index 6210156..5d29544 100644
--- a/apollo/database/proxy/cve.py
+++ b/apollo/database/proxy/cve.py
@@ -20,7 +20,7 @@ import copy
 from collections import defaultdict
 
 from elasticsearch import ElasticsearchException
-from sqlalchemy import func, tuple_, case
+from sqlalchemy import func, tuple_, case, or_
 from sqlalchemy.exc import SQLAlchemyError
 from vulcanus.database.helper import sort_and_page, judge_return_code
 from vulcanus.database.proxy import MysqlProxy, ElasticsearchProxy
@@ -200,7 +200,11 @@ class CveMysqlProxy(MysqlProxy):
         if filter_dict.get("host_group"):
             filters.add(Host.host_group_name.in_(filter_dict["host_group"]))
         if filter_dict.get("repo"):
-            filters.add(Host.repo_name.in_(filter_dict["repo"]))
+            if all(filter_dict.get("repo")):
+                filters.add(Host.repo_name.in_(filter_dict["repo"]))
+            else:
+                repo_names = list(filter(None, filter_dict["repo"]))
+                filters.add(or_(Host.repo_name.in_(repo_names), Host.repo_name == None))
         return filters
 
     def _query_cve_hosts(self, username: str, cve_id: str, filters: set):
diff --git a/apollo/function/schema/cve.py b/apollo/function/schema/cve.py
index 178672e..56d76ed 100644
--- a/apollo/function/schema/cve.py
+++ b/apollo/function/schema/cve.py
@@ -56,7 +56,7 @@ class CveHostFilterSchema(Schema):
 
     host_name = fields.String(required=False, validate=lambda s: len(s) != 0)
     host_group = fields.List(fields.String(validate=lambda s: len(s) != 0), required=False)
-    repo = fields.List(fields.String(validate=lambda s: len(s) != 0), required=False)
+    repo = fields.List(fields.String(validate=lambda s: len(s) != 0, allow_none=True), required=False)
     fixed = fields.Boolean(required=True, validate=validate.OneOf([True, False]))
 
 
diff --git a/apollo/function/schema/task.py b/apollo/function/schema/task.py
index de86194..e136182 100644
--- a/apollo/function/schema/task.py
+++ b/apollo/function/schema/task.py
@@ -18,7 +18,7 @@ Description: For task related restful interfaces schema
 from marshmallow import Schema
 from marshmallow import fields
 from marshmallow import validate
-from vulcanus.restful.serialize.validate import PaginationSchema
+from vulcanus.restful.serialize.validate import PaginationSchema, ValidateRules
 
 from apollo.conf.constant import TaskType, TaskStatus
 
@@ -248,7 +248,7 @@ class CveFixResultCallbackSchema(Schema):
 class CallbackSchma(Schema):
     task_id = fields.String(required=True, validate=lambda s: 0 < len(s) <= 32)
     host_id = fields.Integer(required=True, validate=lambda s: s > 0)
-    host_ip = fields.IP(required=True)
+    host_ip = fields.String(required=True, validate=ValidateRules.ipv4_address_check)
     host_name = fields.String(required=True, validate=lambda s: 0 < len(s) <= 50)
     status = fields.String(required=True, validate=lambda s: len(s) != 0)
     execution_time = fields.Integer(required=True)
@@ -270,7 +270,7 @@ class CheckItemsSchema(Schema):
 class RepoSetCallbackSchema(Schema):
     task_id = fields.String(required=True, validate=lambda s: 0 < len(s) <= 32)
     host_id = fields.Integer(required=True, validate=lambda s: s > 0)
-    host_ip = fields.IP(required=True)
+    host_ip = fields.String(required=True, validate=ValidateRules.ipv4_address_check)
     host_name = fields.String(required=True, validate=lambda s: 0 < len(s) <= 50)
     status = fields.String(required=True, validate=lambda s: len(s) != 0)
     execution_time = fields.Integer(required=True)
-- 
2.33.0

