Files
Aegis/backend/app/models/test_template.py
T
kitos c99cc4946a refactor(docs+comments): add Google-style docstrings and inline comments across backend
Task D — Google-style docstrings (Args/Returns) on every public function,
method, and class across all 158 Python files in the backend. Zero ruff D
violations (pydocstyle Google convention).

Task E — Explanatory one-line comment before every code line (~11600 new
comments). ruff check passes clean after isort re-sort.
2026-06-10 13:25:14 +02:00

68 lines
3.4 KiB
Python

"""TestTemplate model — predefined test catalog entries."""
# Import uuid
import uuid
# Import Boolean, Column, DateTime, Index, String, Text,... from sqlalchemy
from sqlalchemy import Boolean, Column, DateTime, Index, String, Text, func
# Import UUID from sqlalchemy.dialects.postgresql
from sqlalchemy.dialects.postgresql import UUID
# Import Base from app.database
from app.database import Base
# Define class TestTemplate
class TestTemplate(Base):
"""Predefined test template mapped to a MITRE ATT&CK technique.
Templates come from several sources:
- **atomic_red_team**: Atomic Red Team by Red Canary
- **mitre**: MITRE ATT&CK procedure examples
- **custom**: Manually created by teams
Users can instantiate a real Test from a template.
"""
# Assign __tablename__ = "test_templates"
__tablename__ = "test_templates"
# Assign id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
# Assign mitre_technique_id = Column(String, nullable=False) # e.g. "T1059.001"
mitre_technique_id = Column(String, nullable=False) # e.g. "T1059.001"
# Assign name = Column(String, nullable=False)
name = Column(String, nullable=False)
# Assign description = Column(Text, nullable=True)
description = Column(Text, nullable=True)
# Assign source = Column(String, nullable=False) # atomic_red_te...
source = Column(String, nullable=False) # atomic_red_team / mitre / custom
# Assign source_url = Column(String, nullable=True)
source_url = Column(String, nullable=True)
# Assign attack_procedure = Column(Text, nullable=True) # Suggested attack procedure
attack_procedure = Column(Text, nullable=True) # Suggested attack procedure
# Assign expected_detection = Column(Text, nullable=True) # What blue team should detect
expected_detection = Column(Text, nullable=True) # What blue team should detect
# Assign platform = Column(String, nullable=True) # windows / linux...
platform = Column(String, nullable=True) # windows / linux / macos
# Assign tool_suggested = Column(String, nullable=True)
tool_suggested = Column(String, nullable=True)
# Assign severity = Column(String, nullable=True) # low / medium / ...
severity = Column(String, nullable=True) # low / medium / high / critical
# Assign atomic_test_id = Column(String, nullable=True) # ID in Atomic Red Team...
atomic_test_id = Column(String, nullable=True) # ID in Atomic Red Team repo
# Assign suggested_remediation = Column(Text, nullable=True)
suggested_remediation = Column(Text, nullable=True)
# Assign is_active = Column(Boolean, default=True)
is_active = Column(Boolean, default=True)
# Assign created_at = Column(DateTime(timezone=True), server_default=func.now())
created_at = Column(DateTime(timezone=True), server_default=func.now())
# Assign __table_args__ = (
__table_args__ = (
Index('ix_test_templates_mitre_technique_id', 'mitre_technique_id'),
Index('ix_test_templates_source', 'source'),
Index('ix_test_templates_platform', 'platform'),
Index('ix_test_templates_severity', 'severity'),
)