precommit fixes
taylorwalton committed
Mar 11, 2026 at 09:12 UTC
66d5ead492e78af6a7f11c755d178d86637ae0e4
4 files changed
+22
-23
backend/app/agents/sca/routes/sca.py
+1
-1
@@ -29,9 +29,9 @@ from app.agents.sca.services.sca import detect_agents_for_sca_package
29
from app.agents.sca.services.sca import fetch_sca_policies_index
30
from app.agents.sca.services.sca import fetch_sca_policy_content
31
from app.agents.sca.services.sca import generate_sca_csv_report
32
-from app.agents.sca.services.sca import list_sca_package_registry
32
from app.agents.sca.services.sca import get_sca_report_download
33
from app.agents.sca.services.sca import get_sca_statistics
34
+from app.agents.sca.services.sca import list_sca_package_registry
35
from app.agents.sca.services.sca import list_sca_reports
36
from app.agents.sca.services.sca import search_sca_overview
37
from app.agents.sca.services.sca import stream_sca_for_all_agents
backend/app/agents/sca/services/sca.py
+12
-16
@@ -18,8 +18,12 @@ from sqlalchemy import desc
18
from sqlalchemy import select
19
from sqlalchemy.ext.asyncio import AsyncSession
20
21
+from app.agents.sca.schema.sca import AgentPackageMatch
22
from app.agents.sca.schema.sca import AgentScaOverviewItem
23
from app.agents.sca.schema.sca import ScaOverviewResponse
24
+from app.agents.sca.schema.sca import ScaPackageAgentsResponse
25
+from app.agents.sca.schema.sca import ScaPackageRegistryItem
26
+from app.agents.sca.schema.sca import ScaPackageRegistryResponse
27
from app.agents.sca.schema.sca import ScaPoliciesIndexResponse
28
from app.agents.sca.schema.sca import ScaPolicyContentResponse
29
from app.agents.sca.schema.sca import ScaPolicyItem
@@ -1311,14 +1315,12 @@ async def fetch_sca_policy_content(policy_id: str) -> ScaPolicyContentResponse:
1315
raise HTTPException(status_code=502, detail=f"Failed to fetch SCA policy content: {e}")
1316
1317
1314
-async def list_sca_package_registry() -> "ScaPackageRegistryResponse":
1318
+async def list_sca_package_registry() -> ScaPackageRegistryResponse:
1319
"""
1320
Return every entry in the SCA package registry so callers can see
1321
which application packages are tracked for SCA applicability.
1322
"""
1323
from app.agents.sca.models.sca_package_registry import SCA_PACKAGE_REGISTRY
1320
- from app.agents.sca.schema.sca import ScaPackageRegistryItem
1321
- from app.agents.sca.schema.sca import ScaPackageRegistryResponse
1324
1325
entries = [
1326
ScaPackageRegistryItem(
@@ -1338,35 +1340,31 @@ async def list_sca_package_registry() -> "ScaPackageRegistryResponse":
1340
)
1341
1342
1341
-async def detect_agents_for_sca_package(registry_key: str) -> "ScaPackageAgentsResponse":
1343
+async def detect_agents_for_sca_package(registry_key: str) -> ScaPackageAgentsResponse:
1344
"""
1345
Given a registry key (e.g. ``apache``, ``mysql``), search the Wazuh
1346
Indexer for agents that have any of the associated packages installed,
1347
then cross-reference with available SCA policies for that application.
1348
"""
1349
from app.agents.sca.models.sca_package_registry import SCA_PACKAGE_REGISTRY
1348
- from app.agents.sca.schema.sca import AgentPackageMatch
1349
- from app.agents.sca.schema.sca import ScaPackageAgentsResponse
1350
1351
entry = SCA_PACKAGE_REGISTRY.get(registry_key)
1352
if entry is None:
1353
raise HTTPException(
1354
status_code=404,
1355
- detail=(
1356
- f"Registry key '{registry_key}' not found. "
1357
- f"Valid keys: {', '.join(SCA_PACKAGE_REGISTRY.keys())}"
1358
- ),
1355
+ detail=(f"Registry key '{registry_key}' not found. " f"Valid keys: {', '.join(SCA_PACKAGE_REGISTRY.keys())}"),
1356
)
1357
1358
# Build an OR query across all package patterns for this application
1359
should_clauses = [
1363
- {"wildcard": {"package.name": {"value": f"*{pattern}*", "case_insensitive": True}}}
1364
- for pattern in entry.package_patterns
1360
+ {"wildcard": {"package.name": {"value": f"*{pattern}*", "case_insensitive": True}}} for pattern in entry.package_patterns
1361
]
1362
1363
query = {"query": {"bool": {"should": should_clauses, "minimum_should_match": 1}}}
1364
1369
- from app.connectors.wazuh_indexer.utils.universal import create_wazuh_indexer_client_async
1365
+ from app.connectors.wazuh_indexer.utils.universal import (
1366
+ create_wazuh_indexer_client_async,
1367
+ )
1368
1369
es_client = await create_wazuh_indexer_client_async("Wazuh-Indexer")
1370
@@ -1412,9 +1410,7 @@ async def detect_agents_for_sca_package(registry_key: str) -> "ScaPackageAgentsR
1410
applicable_policies = []
1411
try:
1412
index_resp = await fetch_sca_policies_index()
1415
- applicable_policies = [
1416
- p for p in index_resp.policies if p.application == entry.sca_application
1417
- ]
1413
+ applicable_policies = [p for p in index_resp.policies if p.application == entry.sca_application]
1414
except Exception as e:
1415
logger.warning(f"Could not fetch SCA policies index for cross-reference: {e}")
1416
backend/app/agents/wazuh/syscollector/routes/packages.py
+5
-2
@@ -82,7 +82,7 @@ async def get_agent_packages(
82
architecture: Optional[str] = Query(None, description="Filter by architecture"),
83
format: Optional[str] = Query(None, alias="format", description="Filter by package format (e.g. deb, rpm)"),
84
version: Optional[str] = Query(None, description="Filter by package version"),
85
- q: Optional[str] = Query(None, description="Advanced query filter (e.g. q=\"name=openssl\")"),
85
+ q: Optional[str] = Query(None, description='Advanced query filter (e.g. q="name=openssl")'),
86
current_user: User = Depends(AuthHandler().get_current_user),
87
session: AsyncSession = Depends(get_db),
88
) -> AgentPackagesResponse:
@@ -98,7 +98,10 @@ async def get_agent_packages(
98
# Verify the user has access to this agent's customer
99
base_query = sa_select(Agents).filter(Agents.agent_id == agent_id)
100
filtered_query = await customer_access_handler.filter_query_by_customer_access(
101
- current_user, session, base_query, Agents.customer_code,
101
+ current_user,
102
+ session,
103
+ base_query,
104
+ Agents.customer_code,
105
)
106
result = await session.execute(filtered_query)
107
agent = result.scalars().first()
backend/app/agents/wazuh/syscollector/services/packages.py
+4
-4
@@ -12,7 +12,9 @@ from app.agents.wazuh.syscollector.schema.packages import IndexerPackageDetail
12
from app.agents.wazuh.syscollector.schema.packages import IndexerPackageItem
13
from app.agents.wazuh.syscollector.schema.packages import IndexerPackagesResponse
14
from app.agents.wazuh.syscollector.schema.packages import PackageItem
15
-from app.connectors.wazuh_indexer.utils.universal import create_wazuh_indexer_client_async
15
+from app.connectors.wazuh_indexer.utils.universal import (
16
+ create_wazuh_indexer_client_async,
17
+)
18
from app.connectors.wazuh_manager.utils.universal import send_get_request
19
20
PACKAGES_INDEX_PATTERN = "wazuh-states-inventory-packages-*"
@@ -151,9 +153,7 @@ async def search_packages_in_indexer(
153
if package_version is not None:
154
must_clauses.append({"wildcard": {"package.version": {"value": f"*{package_version}*", "case_insensitive": True}}})
155
154
- query: Dict[str, Any] = (
155
- {"query": {"bool": {"must": must_clauses}}} if must_clauses else {"query": {"match_all": {}}}
156
- )
156
+ query: Dict[str, Any] = {"query": {"bool": {"must": must_clauses}}} if must_clauses else {"query": {"match_all": {}}}
157
158
es_client = await create_wazuh_indexer_client_async("Wazuh-Indexer")
159