You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
"""
|
|
扫描任务数据模型
|
|
"""
|
|
from sqlalchemy import Column, Integer, String, DateTime, Text, Boolean, ForeignKey, Enum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
import enum
|
|
from app.database import Base
|
|
|
|
class ScanStatus(enum.Enum):
|
|
"""扫描状态枚举"""
|
|
PENDING = "pending"
|
|
RUNNING = "running"
|
|
COMPLETED = "completed"
|
|
FAILED = "failed"
|
|
CANCELLED = "cancelled"
|
|
|
|
class ScanType(enum.Enum):
|
|
"""扫描类型枚举"""
|
|
FULL = "full" # 全量扫描
|
|
INCREMENTAL = "incremental" # 增量扫描
|
|
CUSTOM = "custom" # 自定义扫描
|
|
|
|
class Scan(Base):
|
|
"""扫描任务模型"""
|
|
__tablename__ = "scans"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)
|
|
|
|
# 扫描配置
|
|
scan_type = Column(Enum(ScanType), default=ScanType.FULL)
|
|
scan_config = Column(Text) # JSON格式的扫描配置
|
|
|
|
# 扫描状态
|
|
status = Column(Enum(ScanStatus), default=ScanStatus.PENDING)
|
|
|
|
# 扫描统计
|
|
total_files = Column(Integer, default=0)
|
|
scanned_files = Column(Integer, default=0)
|
|
total_vulnerabilities = Column(Integer, default=0)
|
|
|
|
# 时间戳
|
|
started_at = Column(DateTime(timezone=True))
|
|
completed_at = Column(DateTime(timezone=True))
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# 结果信息
|
|
result_summary = Column(Text) # JSON格式的结果摘要
|
|
error_message = Column(Text) # 错误信息
|
|
|
|
# 关联关系
|
|
project = relationship("Project", back_populates="scans")
|
|
vulnerabilities = relationship("Vulnerability", back_populates="scan", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<Scan(id={self.id}, project_id={self.project_id}, status='{self.status.value}')>"
|