feat: guarddog-nexus — webhook-based PyPI scanner with web UI
This commit is contained in:
58
guarddog_nexus/models.py
Normal file
58
guarddog_nexus/models.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""SQLAlchemy ORM models."""
|
||||
|
||||
import datetime
|
||||
from enum import Enum
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from guarddog_nexus.database import Base
|
||||
|
||||
|
||||
class ScanStatus(str, Enum):
|
||||
PENDING = "pending"
|
||||
SCANNING = "scanning"
|
||||
COMPLETED = "completed"
|
||||
FAILED = "failed"
|
||||
|
||||
|
||||
class Scan(Base):
|
||||
__tablename__ = "scans"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
package_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
package_version: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
ecosystem: Mapped[str] = mapped_column(String(50), nullable=False, default="pypi")
|
||||
repository: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
nexus_asset_url: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
sha256: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
status: Mapped[str] = mapped_column(
|
||||
String(20), nullable=False, default=ScanStatus.PENDING.value
|
||||
)
|
||||
total_findings: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
flagged: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
started_at: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime, nullable=False, default=func.now()
|
||||
)
|
||||
finished_at: Mapped[datetime.datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
findings: Mapped[list["Finding"]] = relationship(
|
||||
"Finding", back_populates="scan", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class Finding(Base):
|
||||
__tablename__ = "findings"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
scan_id: Mapped[int] = mapped_column(Integer, ForeignKey("scans.id"), nullable=False)
|
||||
rule: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
severity: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
message: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
location: Mapped[str | None] = mapped_column(String(512), nullable=True)
|
||||
created_at: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime, nullable=False, default=func.now()
|
||||
)
|
||||
|
||||
scan: Mapped["Scan"] = relationship("Scan", back_populates="findings")
|
||||
Reference in New Issue
Block a user