Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

fix(mypy): finish the ratchet backlog — permissions, dockertool, alembic

dextmorgn441de4826440
diff --git a/flowsint-api/alembic/env.py b/flowsint-api/alembic/env.py
index a9d24303..d3e94266 100644
--- a/flowsint-api/alembic/env.py
+++ b/flowsint-api/alembic/env.py
@@ -41,8 +41,11 @@ def run_migrations_offline() -> None:
def run_migrations_online() -> None:
"""Run migrations in 'online' mode."""
+ # config_ini_section always resolves to a real section for this
+ # project's alembic.ini — standard alembic-generated boilerplate,
+ # not narrowed further upstream either.
connectable = engine_from_config(
- config.get_section(config.config_ini_section),
+ config.get_section(config.config_ini_section), # type: ignore[arg-type]
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
diff --git a/flowsint-api/alembic/versions/71a3e5b4db2a_update_scan_status_enum.py b/flowsint-api/alembic/versions/71a3e5b4db2a_update_scan_status_enum.py
index 967d3a25..6cdec7e2 100644
--- a/flowsint-api/alembic/versions/71a3e5b4db2a_update_scan_status_enum.py
+++ b/flowsint-api/alembic/versions/71a3e5b4db2a_update_scan_status_enum.py
@@ -120,7 +120,9 @@ def downgrade() -> None:
op.alter_column("scans", "status_old", new_column_name="status")
# Update other columns
- op.drop_constraint(None, "scans", type_="foreignkey")
+ # None lets alembic auto-detect the constraint name at the DB level;
+ # alembic's stub declares the param as required str, this still works.
+ op.drop_constraint(None, "scans", type_="foreignkey") # type: ignore[arg-type]
op.create_foreign_key(
"scans_sketch_id_fkey",
"scans",
diff --git a/flowsint-api/app/security/permissions.py b/flowsint-api/app/security/permissions.py
index 9f148872..417119c8 100644
--- a/flowsint-api/app/security/permissions.py
+++ b/flowsint-api/app/security/permissions.py
@@ -1,6 +1,7 @@
from uuid import UUID
from fastapi import HTTPException
+from sqlalchemy.orm import Session
from flowsint_core.core.models import InvestigationUserRole
from flowsint_core.core.types import Role
@@ -22,8 +23,8 @@ def can_user(roles: list[Role], actions: list[str]) -> bool:
def check_investigation_permission(
- user_id: UUID, investigation_id: str, actions: list[str], db
-):
+ user_id: UUID, investigation_id: str, actions: list[str], db: Session
+) -> bool:
role_entry = (
db.query(InvestigationUserRole)
.filter_by(user_id=user_id, investigation_id=investigation_id)
diff --git a/flowsint-core/pyproject.toml b/flowsint-core/pyproject.toml
index 2d1280c5..65bc2f83 100644
--- a/flowsint-core/pyproject.toml
+++ b/flowsint-core/pyproject.toml
@@ -62,7 +62,12 @@ plugins = ["pydantic.mypy"]
# Test fixtures (MockEnricher etc.) use the same InputType/OutputType
# class-attribute pattern real enrichers do — see the matching override
-# and its rationale in flowsint-enrichers/pyproject.toml.
+# and its rationale in flowsint-enrichers/pyproject.toml. assignment:
+# reassigning InputType/OutputType to a concrete type at the class level
+# (the pattern itself) trips it, since the base declares them as
+# NotImplemented. override: scan()/postprocess() signatures are meant to
+# vary per subclass by design (real params/types keyed off InputType/
+# OutputType), same as flowsint_enrichers.* below.
#
# disallow_untyped_defs off for tests: pytest fixture params carry types
# from conftest.py fixtures scattered across the tree, not the function
@@ -71,5 +76,11 @@ plugins = ["pydantic.mypy"]
# stays strict; this is a deliberate, scoped relaxation, not a blanket one.
[[tool.mypy.overrides]]
module = "tests.*"
-disable_error_code = ["valid-type", "attr-defined", "name-defined"]
+disable_error_code = [
+ "valid-type",
+ "attr-defined",
+ "name-defined",
+ "assignment",
+ "override",
+]
disallow_untyped_defs = false
diff --git a/flowsint-enrichers/src/flowsint_enrichers/domain/to_ssl.py b/flowsint-enrichers/src/flowsint_enrichers/domain/to_ssl.py
index c2824cbe..5e2198ec 100644
--- a/flowsint-enrichers/src/flowsint_enrichers/domain/to_ssl.py
+++ b/flowsint-enrichers/src/flowsint_enrichers/domain/to_ssl.py
@@ -1,4 +1,4 @@
-from typing import List
+from typing import List, Optional
from tools.network.httpx import HttpxTool
@@ -80,7 +80,7 @@ class DomainToTLS(Enricher):
return results
def postprocess(
- self, results: List[OutputType], input_data: List[InputType] = None
+ self, results: List[OutputType], input_data: Optional[List[InputType]] = None
) -> List[OutputType]:
if not self._graph_service:
return results
diff --git a/flowsint-enrichers/src/tools/dockertool.py b/flowsint-enrichers/src/tools/dockertool.py
index ebeee776..e76e2075 100644
--- a/flowsint-enrichers/src/tools/dockertool.py
+++ b/flowsint-enrichers/src/tools/dockertool.py
@@ -1,3 +1,5 @@
+from typing import Any, Dict, Optional
+
from docker import from_env
from docker.errors import APIError, DockerException, ImageNotFound
@@ -5,7 +7,13 @@ from .base import Tool
class DockerTool(Tool):
- def __init__(self, image: str, default_tag: str = "latest"):
+ # Subclasses (SubfinderTool, NaabuTool, ...) set this as a class
+ # attribute with the bare image name — get_image() below reads that,
+ # while __init__ below sets self.image to an instance-level
+ # "name:tag" shadow used for the actual docker calls.
+ image: str
+
+ def __init__(self, image: str, default_tag: str = "latest") -> None:
self.image = f"{image}:{default_tag}"
try:
self.client = from_env()
@@ -18,7 +26,7 @@ class DockerTool(Tool):
def get_image(cls) -> str:
return cls.image
- def install(self):
+ def install(self) -> None:
try:
print(f"[DockerTool] Pulling image: {self.image}")
self.client.images.pull(self.image)
@@ -36,7 +44,7 @@ class DockerTool(Tool):
detach=False,
tty=False,
)
- return output.decode().strip()
+ return str(output.decode().strip())
except Exception as e:
return f"unknown (error: {str(e)})"
@@ -49,12 +57,12 @@ class DockerTool(Tool):
def launch(
self,
- command,
- volumes: dict = None,
+ command: str,
+ volumes: Optional[Dict[str, Any]] = None,
timeout: int = 30,
- environment: dict = None,
- entrypoint=None,
- ):
+ environment: Optional[Dict[str, Any]] = None,
+ entrypoint: Optional[str] = None,
+ ) -> str:
self.install()
# Merge default environment with custom environment
env = {"TERM": "dumb"} # Set terminal type to avoid TTY issues
@@ -79,7 +87,7 @@ class DockerTool(Tool):
if entrypoint is not None:
run_kwargs["entrypoint"] = entrypoint
result = self.client.containers.run(self.image, **run_kwargs)
- return result.decode()
+ return str(result.decode())
except ImageNotFound:
raise RuntimeError(f"Image {self.image} not found. Did you run install()?")
except DockerException as e:
@@ -109,7 +117,7 @@ class DockerTool(Tool):
environment=env,
)
# If we get here, the command actually worked
- return test_result.decode()
+ return str(test_result.decode())
except DockerException as test_e:
error_detail = f"{str(e)} - Test run also failed: {str(test_e)}"
diff --git a/flowsint-enrichers/src/tools/network/reconcrawl.py b/flowsint-enrichers/src/tools/network/reconcrawl.py
index fbcb8c64..0da1ddcf 100644
--- a/flowsint-enrichers/src/tools/network/reconcrawl.py
+++ b/flowsint-enrichers/src/tools/network/reconcrawl.py
@@ -1,10 +1,10 @@
-from typing import Any, Dict
+from typing import Any, Dict, Optional
from ..base import Tool
class ReconCrawlTool(Tool):
- def __init__(self):
+ def __init__(self) -> None:
super().__init__()
@classmethod
@@ -23,7 +23,9 @@ class ReconCrawlTool(Tool):
pass
def version(self) -> str:
- pass
+ # No callers — the reconcrawl package doesn't expose a version
+ # string to report here, unlike the Docker-backed tools.
+ raise NotImplementedError("ReconCrawlTool does not report a version")
def is_installed(self) -> bool:
try:
@@ -33,9 +35,10 @@ class ReconCrawlTool(Tool):
except ImportError:
return False
- def launch(self, url: str, args: Dict[str, Any] = None) -> Any:
+ def launch(self, url: str, args: Optional[Dict[str, Any]] = None) -> Any:
from reconcrawl import Crawler
+ args = args or {}
crawler = Crawler(
url=str(url),
max_pages=args.get("max_pages", 500),