A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
chore: satisfy the mypy ratchet on the files this branch touches
dextmorgn7ce75604009f
diff --git a/flowsint-api/app/api/routes/enrichers.py b/flowsint-api/app/api/routes/enrichers.pyindex ab9df5c7..f0e46a17 100644--- a/flowsint-api/app/api/routes/enrichers.py+++ b/flowsint-api/app/api/routes/enrichers.py@@ -34,17 +34,22 @@ class launchEnricherPayload(BaseModel):router = APIRouter()+# response_model=None is load-bearing: this endpoint mixes registry dicts with+# EnricherTemplate ORM rows, and a return annotation alone would make FastAPI+# adopt it as a response model, which pydantic cannot serialize the rows+# through. The annotation exists for mypy, not for the wire format.[email protected]("", response_model=None)def get_enrichers(category: Optional[str] = Query(None),db: Session = Depends(get_db),current_user: Profile = Depends(get_current_user),-):+) -> list:"""Get all enrichers, optionally filtered by category."""enricher_service = create_enricher_service(db)- return enricher_service.get_all_enrichers(+ enrichers: list = enricher_service.get_all_enrichers(category, current_user.id, ENRICHER_REGISTRY)+ return enrichers@router.post("/{enricher_name}/launch")@@ -53,7 +58,7 @@ async def launch_enricher(payload: launchEnricherPayload,current_user: Profile = Depends(get_current_user),db: Session = Depends(get_db),-):+) -> Dict[str, str]:try:# Retrieve nodes from Neo4J by their element IDstype_registry = create_type_registry_service(db)diff --git a/flowsint-core/src/flowsint_core/core/services/enricher_service.py b/flowsint-core/src/flowsint_core/core/services/enricher_service.pyindex a51f249e..ee93f39b 100644--- a/flowsint-core/src/flowsint_core/core/services/enricher_service.py+++ b/flowsint-core/src/flowsint_core/core/services/enricher_service.py@@ -42,17 +42,26 @@ class EnricherService(BaseService):db: Session,custom_type_repo: CustomTypeRepository,enricher_template_repo: EnricherTemplateRepository,- **kwargs,+ **kwargs: Any,):super().__init__(db, **kwargs)self._custom_type_repo = custom_type_repoself._enricher_template_repo = enricher_template_repo+ # enricher_registry is flowsint_enrichers' EnricherRegistry. That package+ # ships no py.typed marker, so naming the class would resolve to Any+ # anyway; saying Any avoids the cross-package import for no loss.def get_enrichers(- self, category: Optional[str], user_id: UUID, enricher_registry+ self,+ category: Optional[str],+ user_id: UUID,+ enricher_registry: Any,) -> List[Dict[str, Any]]:if not category or category.lower() == "undefined":- return enricher_registry.list(exclude=["n8n_connector"])+ all_enrichers: List[Dict[str, Any]] = enricher_registry.list(+ exclude=["n8n_connector"]+ )+ return all_enricherscustom_type = self._custom_type_repo.get_published_by_name_and_owner(category, user_id@@ -62,10 +71,13 @@ class EnricherService(BaseService):return []return enricher_registry.list(exclude=["n8n_connector"], wobbly_type=True)- return enricher_registry.list_by_input_type(category, exclude=["n8n_connector"])+ by_input_type: List[Dict[str, Any]] = enricher_registry.list_by_input_type(+ category, exclude=["n8n_connector"]+ )+ return by_input_typedef get_all_enrichers(- self, category: Optional[str], user_id: UUID, enricher_registry+ self, category: Optional[str], user_id: UUID, enricher_registry: Any) -> list:base_enrichers = self.get_enrichers(category, user_id, enricher_registry)template_enrichers = self._enricher_template_repo.get_by_owner(diff --git a/flowsint-core/src/flowsint_core/tasks/enricher.py b/flowsint-core/src/flowsint_core/tasks/enricher.pyindex efa4bd72..a8fa90e4 100644--- a/flowsint-core/src/flowsint_core/tasks/enricher.py+++ b/flowsint-core/src/flowsint_core/tasks/enricher.py@@ -1,8 +1,8 @@import asyncioimport uuid-from typing import List, Optional+from typing import Any, Dict, List, Optional-from celery import states+from celery import Task, statesfrom sqlalchemy.orm import Sessionfrom flowsint_core.utils import to_json_serializable@@ -25,13 +25,13 @@ db: Session = next(get_db())@celery.task(name="run_enricher", bind=True)def run_enricher(- self,+ self: Task,enricher_name: str,serialized_objects: List[dict],sketch_id: str | None,owner_id: Optional[str] = None,params: Optional[dict] = None,-):+) -> Dict[str, Any]:session = SessionLocal()try:@@ -51,8 +51,11 @@ def run_enricher(try:vault = create_vault_service(session).for_user(uuid.UUID(owner_id))except Exception as e:+ # Logger.error's signature omits None even though the column+ # it writes is nullable and a sketch-less scan is legal here.Logger.error(- sketch_id, {"message": f"Failed to create vault: {str(e)}"}+ sketch_id, # type: ignore[arg-type]+ {"message": f"Failed to create vault: {str(e)}"},)if not ENRICHER_REGISTRY.enricher_exists(enricher_name):@@ -81,10 +84,14 @@ def run_enricher(error_logs = f"An error occurred: {str(ex)}"print(f"Error in task: {error_logs}")- scan = session.query(Scan).filter(Scan.id == uuid.UUID(self.request.id)).first()- if scan:- scan.status = EventLevel.FAILED- scan.error = error_logs+ failed_scan = (+ session.query(Scan).filter(Scan.id == uuid.UUID(self.request.id)).first()+ )+ if failed_scan:+ failed_scan.status = EventLevel.FAILED+ # Scan.error is a legacy Column(), not Mapped[], so the stubs read+ # it as Column[str] rather than str.+ failed_scan.error = error_logs # type: ignore[assignment]session.commit()self.update_state(state=states.FAILURE)@@ -96,13 +103,13 @@ def run_enricher(@celery.task(name="run_template_enricher", bind=True)def run_template_enricher(- self,+ self: Task,template_name: str,serialized_objects: List[dict],sketch_id: str | None,owner_id: str,params: Optional[dict] = None,-):+) -> Dict[str, Any]:"""Run an enricher defined by a YAML template stored in the database."""session = SessionLocal()@@ -122,7 +129,10 @@ def run_template_enricher(try:vault = create_vault_service(session).for_user(uuid.UUID(owner_id))except Exception as e:- Logger.error(sketch_id, {"message": f"Failed to create vault: {str(e)}"})+ Logger.error(+ sketch_id, # type: ignore[arg-type]+ {"message": f"Failed to create vault: {str(e)}"},+ )# Load template from databasetemplate_service = create_enricher_template_service(session)@@ -155,10 +165,12 @@ def run_template_enricher(error_logs = f"An error occurred: {str(ex)}"print(f"Error in template task: {error_logs}")- scan = session.query(Scan).filter(Scan.id == uuid.UUID(self.request.id)).first()- if scan:- scan.status = EventLevel.FAILED- scan.error = error_logs+ failed_scan = (+ session.query(Scan).filter(Scan.id == uuid.UUID(self.request.id)).first()+ )+ if failed_scan:+ failed_scan.status = EventLevel.FAILED+ failed_scan.error = error_logs # type: ignore[assignment]session.commit()self.update_state(state=states.FAILURE)