Implements all database models for the Aegis platform with full Alembic migration support. Models created: - User: Authentication with role-based access control - Technique: MITRE ATT&CK techniques with coverage status tracking - Test: Security tests with validation workflow (draft/review/validated) - Evidence: File metadata for test evidence (stored in MinIO) - IntelItem: Threat intelligence items linked to techniques - AuditLog: System-wide audit trail with JSONB details Enumerations: - TechniqueStatus: not_evaluated, in_progress, validated, partial, etc. - TestState: draft, in_review, validated, rejected - TestResult: detected, not_detected, partially_detected Services: - audit_service.py: log_action() helper for audit logging All models include proper foreign key relationships and PostgreSQL enum types are managed correctly in migrations (create/drop).
30 lines
918 B
Python
30 lines
918 B
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, String, DateTime, ForeignKey
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
"""
|
|
Audit log model for tracking all system actions.
|
|
|
|
Records user actions, entity changes, and system events
|
|
for security auditing and compliance purposes.
|
|
"""
|
|
__tablename__ = "audit_logs"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
|
action = Column(String, nullable=False)
|
|
entity_type = Column(String, nullable=True)
|
|
entity_id = Column(String, nullable=True)
|
|
timestamp = Column(DateTime, default=datetime.utcnow)
|
|
details = Column(JSONB, nullable=True)
|
|
|
|
# Relationships
|
|
user = relationship("User")
|