From 4b4db885dbaccbdd4cd03900802fbd7ecc2af6ab Mon Sep 17 00:00:00 2001 From: Lee Chagolla-Christensen Date: Sun, 26 Oct 2025 00:34:19 -0700 Subject: [PATCH] update dotnet model --- libs/common/common/models.py | 27 ++++++++++--------- .../subscriptions/dotnet_handler.py | 2 +- .../subscriptions/file_handler.py | 2 -- .../subscriptions/noseyparker_handler.py | 2 -- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/libs/common/common/models.py b/libs/common/common/models.py index 22402ff..1ed3550 100644 --- a/libs/common/common/models.py +++ b/libs/common/common/models.py @@ -3,7 +3,7 @@ from datetime import datetime from enum import Enum from typing import TYPE_CHECKING, Any -from pydantic import BaseModel, ConfigDict, Field, field_serializer +from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator from .logger import get_logger @@ -97,20 +97,23 @@ class DotNetOutput(BaseModel): object_id: str = Field(alias="objectId") decompilation: str | None = None - analysis: str | None = None + analysis: DotNetAssemblyAnalysis | None = None - def get_parsed_analysis(self) -> DotNetAssemblyAnalysis | None: - """Parse the analysis JSON string into a DotNetAssemblyAnalysis object""" - if not self.analysis: + @field_validator("analysis", mode="before") + @classmethod + def parse_analysis_json(cls, v): + """Parse analysis from JSON string if needed""" + if v is None: return None - try: + if isinstance(v, str): import json - analysis_data = json.loads(self.analysis) - return DotNetAssemblyAnalysis(**analysis_data) - except Exception as e: - logger.warning(f"Failed to parse DotNet analysis: {e}") - return None + try: + return json.loads(v) + except Exception as e: + logger.warning(f"Failed to parse DotNet analysis JSON: {e}") + return None + return v ########################################## @@ -233,7 +236,7 @@ class File(BaseModel): access_time: str | None = None modification_time: str | None = None - @field_serializer('timestamp', 'expiration') + @field_serializer("timestamp", "expiration") def serialize_datetime(self, dt: datetime, _info): return dt.isoformat() diff --git a/projects/file_enrichment/file_enrichment/subscriptions/dotnet_handler.py b/projects/file_enrichment/file_enrichment/subscriptions/dotnet_handler.py index 4e1b951..e64f47f 100644 --- a/projects/file_enrichment/file_enrichment/subscriptions/dotnet_handler.py +++ b/projects/file_enrichment/file_enrichment/subscriptions/dotnet_handler.py @@ -20,7 +20,7 @@ async def process_dotnet_event(dotnet_output: DotNetOutput, pool: asyncpg.Pool) object_id = dotnet_output.object_id decompilation_object_id = dotnet_output.decompilation - analysis = dotnet_output.get_parsed_analysis() + analysis = dotnet_output.analysis file_enriched = await get_file_enriched_async(object_id) diff --git a/projects/file_enrichment/file_enrichment/subscriptions/file_handler.py b/projects/file_enrichment/file_enrichment/subscriptions/file_handler.py index 01adae2..a4593c2 100644 --- a/projects/file_enrichment/file_enrichment/subscriptions/file_handler.py +++ b/projects/file_enrichment/file_enrichment/subscriptions/file_handler.py @@ -74,7 +74,6 @@ async def save_file_message(file: File, pool: asyncpg.Pool): async def process_file_event(file: File, workflow_manager, module_execution_order: list, pool: asyncpg.Pool): """Process incoming file events""" try: - # Save the file message to database first for recovery purposes await save_file_message(file, pool) workflow_input = { @@ -82,7 +81,6 @@ async def process_file_event(file: File, workflow_manager, module_execution_orde "execution_order": module_execution_order, } - # This will block if we're at max capacity, providing natural backpressure await workflow_manager.start_workflow(workflow_input) except Exception as e: diff --git a/projects/file_enrichment/file_enrichment/subscriptions/noseyparker_handler.py b/projects/file_enrichment/file_enrichment/subscriptions/noseyparker_handler.py index 06ee4df..099ae4d 100644 --- a/projects/file_enrichment/file_enrichment/subscriptions/noseyparker_handler.py +++ b/projects/file_enrichment/file_enrichment/subscriptions/noseyparker_handler.py @@ -13,14 +13,12 @@ logger = get_logger(__name__) async def process_noseyparker_event(nosey_output: NoseyParkerOutput, pool: asyncpg.Pool): """Process incoming Nosey Parker scan results""" try: - # Now process the properly parsed output object_id = nosey_output.object_id matches = nosey_output.scan_result.matches stats = nosey_output.scan_result.stats logger.debug(f"Found {len(matches)} matches for object {object_id}", pid=os.getpid()) - # Store the findings in the database using our helper function await store_noseyparker_results( object_id=object_id, matches=matches,