Files
rengine/shared/models/scan_schedule.py
T
Yogesh OjhaandClaude Fable 5.1 db030d733c feat(bounty-hub): watch a program
Scope-true continuous discovery for a bounty program, bug bounty mode only
(capability `program_watches`).

Watching a program imports its in-scope targets under the program's
organization, writes out-of-scope entries as exclusions and the rate ceiling
on a `Watch · <program>` scan context, schedules an optional baseline, and
streams certificate transparency for the watched apexes. A new in-scope host
is resolved, written into the covering scan with source `ct_log`, probed by a
focused run with a screenshot, evaluated against the watch's alert query and
alerted once per fingerprint through the chosen channels.

- ct-stream compose service: certspotter 0.24.2 under a supervisor that
  regenerates the watchlist from active watches, spools events through a
  hook script that emits only certspotter fields, and reports over Redis
- worker tasks: certificate, settle, recheck, reconcile; finalize dispatches
  settle for any probe run; reconcile after every program or feed sync
- notifier: named channels bypass per-channel preferences; attachments;
  new `watch` notification type
- API under /bounty-programs/watches with preview, ledger, events, marks
- Bounty Hub: Watching tab, Watch dialog, watch sheet, program badge,
  certificate stream card in Settings
- schedules carry an intensity; scan_schedules.intensity

Two review rounds folded in: compare-and-set probe claim, resolver-down
handling, spool kept on failed dispatch, schedule cap, mute keeps prior
state, ledger-derived totals, event filters, mode lockout of worker and
stream in corporate mode.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ba2f7gwu2GXiETCKqRztyB
2026-09-12 21:51:18 +05:30

118 lines
3.9 KiB
Python

import uuid
from datetime import datetime
from functools import partial
from pydantic import BaseModel, field_validator
from sqlalchemy import Column
from sqlalchemy.types import JSON
from sqlmodel import Field, SQLModel
from shared.definitions.schedule_constants import MAX_SCHEDULE_TARGETS
from shared.enums.scan_schedule import ScheduleStatus
from shared.utils.datetime import utc_now
from shared.utils.validation import clean_name, clean_optional_name
class ScanSchedule(SQLModel, table=True):
__tablename__ = "scan_schedules"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
project_id: uuid.UUID = Field(foreign_key="projects.id", index=True)
name: str = Field(max_length=200)
target_ids: list = Field(
default_factory=list, sa_column=Column(JSON, nullable=False)
)
engine_id: uuid.UUID = Field(index=True)
engine_name: str = Field(max_length=200)
context_id: uuid.UUID | None = Field(default=None)
context_name: str | None = Field(default=None, max_length=200)
intensity: str | None = Field(default=None, max_length=16)
schedule_type: str = Field(index=True)
run_at: datetime | None = Field(default=None)
interval_every: int | None = Field(default=None)
interval_unit: str | None = Field(default=None, max_length=10)
daily_at_time: str | None = Field(default=None, max_length=5)
cron_expression: str | None = Field(default=None, max_length=120)
timezone: str = Field(default="UTC", max_length=64)
status: str = Field(default=ScheduleStatus.ACTIVE.value, index=True)
next_run_at: datetime | None = Field(default=None, index=True)
last_run_at: datetime | None = Field(default=None)
last_error: str | None = Field(default=None, max_length=2000)
total_run_count: int = Field(default=0)
created_by: uuid.UUID = Field(foreign_key="users.id")
created_at: datetime = Field(default_factory=utc_now)
updated_at: datetime = Field(default_factory=utc_now)
class ScheduleTargetRef(BaseModel):
id: uuid.UUID
target_value: str
target_type: str
class ScanScheduleCreate(BaseModel):
name: str
target_ids: list[uuid.UUID] = Field(min_length=1, max_length=MAX_SCHEDULE_TARGETS)
engine_id: uuid.UUID
context_id: uuid.UUID | None = None
intensity: str | None = None
schedule_type: str
run_at: datetime | None = None
interval_every: int | None = None
interval_unit: str | None = None
daily_at_time: str | None = None
cron_expression: str | None = None
_validate_name = field_validator("name")(partial(clean_name, max_len=200))
class ScanScheduleUpdate(BaseModel):
name: str | None = None
target_ids: list[uuid.UUID] | None = Field(
default=None, min_length=1, max_length=MAX_SCHEDULE_TARGETS
)
engine_id: uuid.UUID | None = None
context_id: uuid.UUID | None = None
intensity: str | None = None
schedule_type: str | None = None
run_at: datetime | None = None
interval_every: int | None = None
interval_unit: str | None = None
daily_at_time: str | None = None
cron_expression: str | None = None
_validate_name = field_validator("name")(partial(clean_optional_name, max_len=200))
class ScanScheduleRead(BaseModel):
id: uuid.UUID
project_id: uuid.UUID
name: str
target_ids: list[uuid.UUID]
targets: list[ScheduleTargetRef]
engine_id: uuid.UUID
engine_name: str
context_id: uuid.UUID | None
context_name: str | None
intensity: str | None = None
schedule_type: str
run_at: datetime | None
interval_every: int | None
interval_unit: str | None
daily_at_time: str | None
cron_expression: str | None
timezone: str
status: str
next_run_at: datetime | None
last_run_at: datetime | None
last_error: str | None
total_run_count: int
cadence: str
timezone_stale: bool = False
created_by: uuid.UUID
created_at: datetime
updated_at: datetime