Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /poc /backend /app /models /scan.py
| """ | |
| Scan models for scan management. | |
| """ | |
| import uuid | |
| from datetime import datetime, timezone | |
| from enum import Enum as PyEnum | |
| from sqlalchemy import ( | |
| JSON, | |
| Boolean, | |
| Column, | |
| DateTime, | |
| Enum, | |
| ForeignKey, | |
| Integer, | |
| String, | |
| Text, | |
| ) | |
| from sqlalchemy.dialects.postgresql import UUID | |
| from sqlalchemy.orm import relationship | |
| from app.core.database import Base | |
| class ScanStatus(str, PyEnum): | |
| """Scan status enumeration.""" | |
| PENDING = "pending" | |
| QUEUED = "queued" | |
| RUNNING = "running" | |
| PAUSED = "paused" | |
| COMPLETED = "completed" | |
| FAILED = "failed" | |
| CANCELLED = "cancelled" | |
| class ScanType(str, PyEnum): | |
| """Scan type enumeration.""" | |
| NETWORK = "network" | |
| WEB = "web" | |
| API = "api" | |
| INFRASTRUCTURE = "infrastructure" | |
| COMPLIANCE = "compliance" | |
| FULL = "full" | |
| class Scan(Base): | |
| """Scan model.""" | |
| __tablename__ = "scans" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| name = Column(String(255), nullable=False) | |
| description = Column(Text, nullable=True) | |
| target = Column(String(500), nullable=False) | |
| type = Column(Enum(ScanType), nullable=False) | |
| status = Column(Enum(ScanStatus), default=ScanStatus.PENDING, nullable=False) | |
| progress = Column(Integer, default=0, nullable=False) | |
| config = Column(JSON, default=dict, nullable=False) | |
| # Statistics | |
| findings_count = Column(Integer, default=0, nullable=False) | |
| critical_count = Column(Integer, default=0, nullable=False) | |
| high_count = Column(Integer, default=0, nullable=False) | |
| medium_count = Column(Integer, default=0, nullable=False) | |
| low_count = Column(Integer, default=0, nullable=False) | |
| info_count = Column(Integer, default=0, nullable=False) | |
| # Foreign keys | |
| created_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) | |
| template_id = Column(UUID(as_uuid=True), ForeignKey("scan_templates.id"), nullable=True) | |
| # Timestamps | |
| created_at = Column( | |
| DateTime(timezone=True), | |
| default=lambda: datetime.now(timezone.utc), | |
| nullable=False, | |
| ) | |
| started_at = Column(DateTime(timezone=True), nullable=True) | |
| completed_at = Column(DateTime(timezone=True), nullable=True) | |
| # Error handling | |
| error_message = Column(Text, nullable=True) | |
| # Relationships | |
| created_by_user = relationship("User", back_populates="scans") | |
| template = relationship("ScanTemplate", back_populates="scans") | |
| vulnerabilities = relationship("Vulnerability", back_populates="scan", cascade="all, delete-orphan") | |
| reports = relationship("Report", back_populates="scan") | |
| def __repr__(self): | |
| return f"<Scan(id={self.id}, name={self.name}, status={self.status})>" | |
| def to_dict(self): | |
| """Convert to dictionary.""" | |
| return { | |
| "id": str(self.id), | |
| "name": self.name, | |
| "description": self.description, | |
| "target": self.target, | |
| "type": self.type.value, | |
| "status": self.status.value, | |
| "progress": self.progress, | |
| "config": self.config, | |
| "findings": self.findings_count, | |
| "criticalCount": self.critical_count, | |
| "highCount": self.high_count, | |
| "mediumCount": self.medium_count, | |
| "lowCount": self.low_count, | |
| "infoCount": self.info_count, | |
| "createdBy": str(self.created_by), | |
| "createdAt": (self.created_at.isoformat() if self.created_at else None), | |
| "startedAt": (self.started_at.isoformat() if self.started_at else None), | |
| "completedAt": (self.completed_at.isoformat() if self.completed_at else None), | |
| "errorMessage": self.error_message, | |
| } | |
| class ScanTemplate(Base): | |
| """Scan template model.""" | |
| __tablename__ = "scan_templates" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| name = Column(String(255), nullable=False) | |
| description = Column(Text, nullable=True) | |
| type = Column(Enum(ScanType), nullable=False) | |
| config = Column(JSON, default=dict, nullable=False) | |
| is_default = Column(Boolean, default=False, nullable=False) | |
| created_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) | |
| created_at = Column( | |
| DateTime(timezone=True), | |
| default=lambda: datetime.now(timezone.utc), | |
| nullable=False, | |
| ) | |
| # Relationships | |
| scans = relationship("Scan", back_populates="template") | |
| def __repr__(self): | |
| return f"<ScanTemplate(id={self.id}, name={self.name})>" | |
| def to_dict(self): | |
| """Convert to dictionary.""" | |
| return { | |
| "id": str(self.id), | |
| "name": self.name, | |
| "description": self.description, | |
| "type": self.type.value, | |
| "config": self.config, | |
| "isDefault": self.is_default, | |
| "createdBy": str(self.created_by), | |
| "createdAt": (self.created_at.isoformat() if self.created_at else None), | |
| } | |
Xet Storage Details
- Size:
- 5.01 kB
- Xet hash:
- f0a25e3c010f2b5ecaeb7df1bc290d9eaa7c12fa8f32569abed2e460c02bf263
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.