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).
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, String, DateTime, ForeignKey
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class Evidence(Base):
|
|
"""
|
|
Evidence model for storing file metadata associated with tests.
|
|
|
|
Files are stored in MinIO, and this model tracks the file location,
|
|
integrity hash, and upload metadata.
|
|
"""
|
|
__tablename__ = "evidences"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
test_id = Column(UUID(as_uuid=True), ForeignKey("tests.id"), nullable=False)
|
|
file_name = Column(String, nullable=False)
|
|
file_path = Column(String, nullable=False) # Path in MinIO
|
|
sha256_hash = Column(String, nullable=False)
|
|
uploaded_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
|
uploaded_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# Relationships
|
|
test = relationship("Test", back_populates="evidences")
|
|
uploader = relationship("User", foreign_keys=[uploaded_by])
|