diff --git a/backend/app/services/mitre.py b/backend/app/services/mitre.py index 7e2c983..3618128 100644 --- a/backend/app/services/mitre.py +++ b/backend/app/services/mitre.py @@ -26,6 +26,21 @@ _TACTIC_ORDER = [ "impact", ] +_TACTIC_NAMES: dict[str, str] = { + "initial-access": "Initial Access", + "execution": "Execution", + "persistence": "Persistence", + "privilege-escalation": "Privilege Escalation", + "defense-evasion": "Defense Evasion", + "credential-access": "Credential Access", + "discovery": "Discovery", + "lateral-movement": "Lateral Movement", + "collection": "Collection", + "command-and-control": "Command and Control", + "exfiltration": "Exfiltration", + "impact": "Impact", +} + mitre_loaded: bool = False _index: list[dict[str, Any]] = [] _tactics_by_technique: dict[str, list[str]] = {} @@ -87,7 +102,7 @@ def _build_matrix(entries: list[dict[str, Any]]) -> list[dict[str, Any]]: techs = tactic_techs.get(tactic_id, []) # Sort techniques alphabetically. techs_sorted = sorted(techs, key=lambda x: x["name"]) - tactic_name = tactic_id.replace("-", " ").title() + tactic_name = _TACTIC_NAMES.get(tactic_id, tactic_id.replace("-", " ").title()) matrix.append( { "tactic_id": tactic_id, diff --git a/backend/migrations/versions/0003_simulation_techniques_array.py b/backend/migrations/versions/0003_simulation_techniques_array.py index 84fa165..1447f84 100644 --- a/backend/migrations/versions/0003_simulation_techniques_array.py +++ b/backend/migrations/versions/0003_simulation_techniques_array.py @@ -8,7 +8,7 @@ import json from alembic import op import sqlalchemy as sa -from sqlalchemy.sql import column, table, text +from sqlalchemy.sql import text revision = "0003" @@ -16,15 +16,6 @@ down_revision = "0002" branch_labels = None depends_on = None -# Lightweight table proxies for data migration (no ORM import). -_sims = table( - "simulations", - column("id", sa.Integer), - column("mitre_technique_id", sa.String), - column("mitre_technique_name", sa.String), - column("techniques", sa.Text), -) - def upgrade(): bind = op.get_bind() @@ -47,8 +38,8 @@ def upgrade(): ) # 3. Make NOT NULL now that every row has a value. - # SQLite doesn't support ALTER COLUMN, so we skip the nullable constraint - # change at DDL level — the application model enforces it. + with op.batch_alter_table("simulations") as batch_op: + batch_op.alter_column("techniques", existing_type=sa.Text(), nullable=False) # 4. Drop old scalar columns. with op.batch_alter_table("simulations") as batch_op: