- Replace default=datetime.utcnow with server_default=func.now() across all 16 models (17 columns) for consistent, timezone-aware timestamps from PostgreSQL - Upgrade DateTime columns to DateTime(timezone=True) for timestamptz storage - Configure SQLAlchemy engine pool: pool_size=20, max_overflow=10, pool_recycle=3600, pool_pre_ping=True - Remove unused datetime imports from model files
45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
"""TestTemplate model — predefined test catalog entries."""
|
|
|
|
import uuid
|
|
from sqlalchemy import Column, String, Text, Boolean, DateTime, Index, func
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
from app.database import Base
|
|
|
|
|
|
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.
|
|
"""
|
|
__tablename__ = "test_templates"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
mitre_technique_id = Column(String, nullable=False) # e.g. "T1059.001"
|
|
name = Column(String, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
source = Column(String, nullable=False) # atomic_red_team / mitre / custom
|
|
source_url = Column(String, nullable=True)
|
|
attack_procedure = Column(Text, nullable=True) # Suggested attack procedure
|
|
expected_detection = Column(Text, nullable=True) # What blue team should detect
|
|
platform = Column(String, nullable=True) # windows / linux / macos
|
|
tool_suggested = Column(String, nullable=True)
|
|
severity = Column(String, nullable=True) # low / medium / high / critical
|
|
atomic_test_id = Column(String, nullable=True) # ID in Atomic Red Team repo
|
|
suggested_remediation = Column(Text, nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
__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'),
|
|
)
|