diff --git a/0003-add-fixed-and-hp_status-filter.patch b/0003-add-fixed-and-hp_status-filter.patch new file mode 100644 index 0000000000000000000000000000000000000000..7f66ef3b8e5566e9b79ca42e9fe2928496137c92 --- /dev/null +++ b/0003-add-fixed-and-hp_status-filter.patch @@ -0,0 +1,109 @@ +From e542a4421ccc27c2f79afd3ed972a6d20858e1f0 Mon Sep 17 00:00:00 2001 +From: gongzt +Date: Wed, 20 Sep 2023 20:01:47 +0800 +Subject: add fixed and hp_status filter +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + apollo/database/proxy/cve.py | 30 ++++++++++++++---------------- + apollo/function/schema/cve.py | 2 ++ + 2 files changed, 16 insertions(+), 16 deletions(-) + +diff --git a/apollo/database/proxy/cve.py b/apollo/database/proxy/cve.py +index c6d017e..3a6ec01 100644 +--- a/apollo/database/proxy/cve.py ++++ b/apollo/database/proxy/cve.py +@@ -1562,25 +1562,22 @@ class CveProxy(CveMysqlProxy, CveEsProxy): + + cve_fixed_packages = ( + self.session.query( +- CveHostAssociation.id, + CveHostAssociation.installed_rpm, + CveHostAssociation.fixed_way, ++ CveHostAssociation.hp_status, + func.count(CveHostAssociation.host_id).label("host_num"), + ) + .filter(*filters) +- .group_by('installed_rpm', 'fixed_way', 'id') ++ .group_by('installed_rpm', 'fixed_way', "hp_status") + .all() + ) + if not cve_fixed_packages: + return NO_DATA, [] +- cve_fixed_packages_status = ( +- self.session.query(CveHostAssociation.id, CveHostAssociation.hp_status).filter(*filters).all() +- ) + +- return SUCCEED, self._cve_fixed_packages_row2dict(cve_fixed_packages, cve_fixed_packages_status) ++ return SUCCEED, self._cve_fixed_packages_row2dict(cve_fixed_packages) + + @staticmethod +- def _cve_fixed_packages_row2dict(rows, cve_fixed_packages_status): ++ def _cve_fixed_packages_row2dict(rows): + """ + Fixed cve package row data converted to dictionary + Args: +@@ -1590,17 +1587,12 @@ class CveProxy(CveMysqlProxy, CveEsProxy): + list + """ + result = [] +- cve_fixed_packages_status_dict = { +- cve_host_match.id: cve_host_match.hp_status for cve_host_match in cve_fixed_packages_status +- } ++ + for row in rows: +- status = cve_fixed_packages_status_dict[row.id] if cve_fixed_packages_status_dict[row.id] else "" +- fixed_way = row.fixed_way +- if fixed_way != "coldpatch": +- fixed_way = fixed_way + f" ({status})" + fixed_rpm = { + "installed_rpm": row.installed_rpm, +- "fixed_way": fixed_way, ++ "fixed_way": row.fixed_way, ++ "hp_status": row.hp_status, + "host_num": row.host_num, + } + result.append(fixed_rpm) +@@ -1619,7 +1611,9 @@ class CveProxy(CveMysqlProxy, CveEsProxy): + "username": "admin", + "cve_id": "CVE-2023-0120", + "available_rpm": "kernel-4.9-ACC"/null, +- "installed_rpm": "kernel-4.9" ++ "installed_rpm": "kernel-4.9", ++ "hp_status": "ACCEPTED/ACTIVED", ++ "fixed": True/False + } + + Returns: +@@ -1651,9 +1645,13 @@ class CveProxy(CveMysqlProxy, CveEsProxy): + filters = { + CveHostAssociation.cve_id == data["cve_id"], + CveHostAssociation.installed_rpm == data["installed_rpm"], ++ CveHostAssociation.fixed == data["fixed"], + } + if data.get("available_rpm"): + filters.add(CveHostAssociation.available_rpm == data["available_rpm"]) ++ ++ if data.get("hp_status"): ++ filters.add(CveHostAssociation.hp_status == data["hp_status"]) + cve_package_host_query = self._query_cve_package_host(filters) + + total_count = cve_package_host_query.count() +diff --git a/apollo/function/schema/cve.py b/apollo/function/schema/cve.py +index 557b5f1..797edb1 100644 +--- a/apollo/function/schema/cve.py ++++ b/apollo/function/schema/cve.py +@@ -121,6 +121,8 @@ class GetGetCvePackageHostSchema(PaginationSchema): + cve_id = fields.String(required=True, validate=lambda s: 0 < len(s) <= 20) + installed_rpm = fields.String(required=True, validate=lambda s: 0 < len(s) <= 100) + available_rpm = fields.String(required=False, validate=lambda s: 0 < len(s) <= 100) ++ hp_status = fields.String(required=False, validate=lambda s: 0 < len(s) <= 20) ++ fixed = fields.Boolean(required=True, default=False, validate=validate.OneOf([True, False])) + + + class ExportCveExcelSchema(Schema): +-- +Gitee + diff --git a/aops-apollo.spec b/aops-apollo.spec index 6c75332d29c614997da1d8b3bd8918d28005bf46..83334beda832f621327542fa0ef43d41b86a0877 100644 --- a/aops-apollo.spec +++ b/aops-apollo.spec @@ -1,6 +1,6 @@ Name: aops-apollo Version: v1.3.2 -Release: 3 +Release: 4 Summary: Cve management service, monitor machine vulnerabilities and provide fix functions. License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} @@ -16,6 +16,7 @@ Requires: python3-retrying python3-lxml Provides: aops-apollo Patch0001: 0001-fix-updateinfo_parse.py-bug.patch Patch0002: 0002-add-repair-status-of-the-cve-fixed-package.patch +Patch0003: 0003-add-fixed-and-hp_status-filter.patch %description @@ -81,6 +82,9 @@ cp -r hotpatch %{buildroot}/%{python3_sitelib}/dnf-plugins/ %{python3_sitelib}/aops_apollo_tool/* %changelog +* Wed Sep 20 2023 gongzhengtang - v1.3.2-4 +- add fixed and hp_status filter + * Tue Sep 19 2023 gongzhengtang - v1.3.2-3 - added the repair status of the cve fixed package