~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/vuln-notif

0
0
main
229 lines · 7.3 KB Raw History
//! `software.release.*` ingestion.
//!
//! Select each product default/latest version from deps.dev, fetch one artifact
//! from its ecosystem registry, and publish project/manifest/version/channel/
//! status records plus local links.
//!
//! The former `sync_one` monolith is split by concern: [`planner`] selects a
//! version, [`versioning`] normalizes versions, [`records`] builds wire shapes
//! and rkeys, [`service`] orchestrates publishing, and [`source`] holds the
//! Phase 2+ source adapter contract.

pub mod artifact;
pub mod artifacts;
pub mod cve_links;
pub mod history;
pub mod host;
pub mod http;
pub mod metadata;
pub mod planner;
pub mod records;
pub mod service;
pub mod source;
pub mod sources;
pub mod status;
pub mod versioning;

pub use artifacts::{
    ArtifactCounters, ArtifactError, ArtifactMirror, ArtifactResolver, NoopMirror, S3Mirror,
};
pub use history::{
    ArtifactProvider, HistoryConfig as HistoryJobConfig, HistoryCounters as HistoryJobCounters,
};
pub use planner::select_release;
pub use service::{
    build_history_source, sync_affected, sync_affected_with_cursor,
    sync_affected_with_cursor_resolver, sync_all_with_http, sync_all_with_http_resolver,
    sync_extras, sync_extras_with_cursor, sync_extras_with_cursor_resolver, sync_history,
    sync_history_mode, sync_releases, sync_releases_with_http, sync_releases_with_http_cursor,
    sync_releases_with_http_cursor_resolver, sync_releases_with_http_resolver,
};

use std::path::PathBuf;

use serde::Serialize;

#[derive(Debug, Clone)]
pub struct ReleaseConfig {
    pub repo_did: String,
    pub limit: usize,
    pub recheck_seconds: f64,
}

/// Configuration for `--release-mode affected`.
#[derive(Debug, Clone)]
pub struct AffectedConfig {
    pub repo_did: String,
    pub limit: usize,
    pub recheck_seconds: f64,
    /// Purl types to include; empty means every type.
    pub ecosystems: Vec<String>,
    /// Source names or purl types to include; empty means every source.
    pub sources: Vec<String>,
    /// Reserved for a future concurrent source pass; affected runs in order.
    pub concurrency: usize,
    pub osv_online: bool,
    /// When set, OSV advisories are loaded from this directory, not the API.
    pub osv_bulk_dir: Option<PathBuf>,
}

/// Rotation cursor for `--release-limit` pages.
///
/// The candidate query orders least-recently-checked first and pages strictly
/// after `after_slug`, so equal-timestamp groups rotate instead of starving
/// projects that sort later. The integration layer persists this between
/// cycles; callers that do not pass a cursor still get the first page.
#[derive(Debug, Clone, Default)]
pub struct ReleaseCursor {
    pub after_slug: Option<String>,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ReleaseCounters {
    pub projects_checked: u64,
    pub projects_created: u64,
    pub versions_created: u64,
    pub channels_created: u64,
    pub statuses_created: u64,
    pub unchanged: u64,
    pub skipped: u64,
    /// Candidates with no release-ecosystem purl (OS/distro-only projects).
    pub unsupported_no_purl: u64,
    pub failures: u64,
}

/// `--release-mode affected` cycle counters.
#[derive(Debug, Clone, Default, Serialize)]
pub struct AffectedCounters {
    pub projects_checked: u64,
    pub projects_linked: u64,
    pub versions_planned: u64,
    pub versions_created: u64,
    pub versions_label_only: u64,
    pub cves_linked: u64,
    pub unchanged: u64,
    pub skipped: u64,
    pub failures: u64,
    pub unsupported: u64,
}

/// `--release-mode history`: one candidate page per call.
#[derive(Debug, Clone, Default)]
pub struct HistoryModeConfig {
    pub repo_did: String,
    /// Candidates inspected per cycle; `0` means all.
    pub limit: usize,
    pub recheck_seconds: f64,
    /// Purl types to include; empty means every type.
    pub ecosystems: Vec<String>,
    /// Source names or purl types to include; empty means every source.
    pub sources: Vec<String>,
    /// Versions processed per project per cycle; `0` means all.
    pub history_limit: usize,
    /// Projects enumerated concurrently; clamped to at least 1.
    pub concurrency: usize,
    /// Artifact byte cap; `0` means no cap.
    pub artifact_max_bytes: u64,
    /// S3 artifact mirror; `None` leaves the no-op mirror.
    pub artifact_s3: Option<crate::config::S3Config>,
    /// Test/mirror seam for sources that expose a configurable base URL.
    pub source_base_url: Option<String>,
    pub github_token: Option<String>,
    pub gitlab_token: Option<String>,
    pub gitee_token: Option<String>,
}

/// One project's history pass.
#[derive(Debug, Clone)]
pub struct HistoryProjectConfig {
    pub repo_did: String,
    pub project_slug: String,
    pub purl: String,
    pub source: String,
    /// Versions processed in this call; `0` means all.
    pub limit: usize,
    /// Artifact byte cap; `0` means no cap.
    pub max_bytes: u64,
}

/// `--release-mode history` cycle counters.
#[derive(Debug, Clone, Default, Serialize)]
pub struct HistoryModeCounters {
    pub projects_checked: u64,
    pub projects_skipped: u64,
    pub unsupported: u64,
    pub enqueued: u64,
    pub processed: u64,
    pub versions_created: u64,
    pub manifests_created: u64,
    pub skipped: u64,
    pub failed: u64,
    pub reused: u64,
}

impl HistoryModeCounters {
    pub fn add_jobs(&mut self, counters: &history::HistoryCounters) {
        self.enqueued += counters.enqueued;
        self.processed += counters.processed;
        self.versions_created += counters.versions_created;
        self.manifests_created += counters.manifests_created;
        self.skipped += counters.skipped;
        self.failed += counters.failed;
        self.reused += counters.reused;
    }
}

/// Configuration for `--release-mode extras`.
#[derive(Clone)]
pub struct ExtrasConfig {
    pub repo_did: String,
    /// Candidates inspected per cycle; `0` means all.
    pub limit: usize,
    pub recheck_seconds: f64,
    /// Purl types to include; empty means every type.
    pub ecosystems: Vec<String>,
    /// Source names or purl types to include; empty means every source.
    pub sources: Vec<String>,
    /// Artifact byte cap; `0` means no cap.
    pub artifact_max_bytes: u64,
    /// Fetch and plan through the source, but never write to the PDS.
    pub dry_run: bool,
    /// Base-URL override for adapters with a configurable endpoint.
    pub source_base_url: Option<String>,
    pub github_token: Option<String>,
    pub gitlab_token: Option<String>,
    pub gitee_token: Option<String>,
}

/// `--release-mode extras` cycle counters.
#[derive(Debug, Clone, Default, Serialize)]
pub struct ExtrasCounters {
    pub projects_checked: u64,
    pub projects_created: u64,
    pub versions_created: u64,
    pub manifests_created: u64,
    pub statuses_created: u64,
    pub unchanged: u64,
    pub skipped: u64,
    pub unsupported: u64,
    pub failures: u64,
}

/// `--release-mode all`: one cycle of every release mode with separate
/// counters. History is present only when `--release-history-limit > 0`.
#[derive(Debug, Clone, Default)]
pub struct AllModeCounters {
    pub latest: ReleaseCounters,
    pub affected: AffectedCounters,
    pub history: Option<HistoryModeCounters>,
    pub extras: ExtrasCounters,
    pub artifacts: artifacts::ArtifactCounters,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SelectedRelease {
    pub raw: String,
    pub version: String,
    pub deprecated: bool,
    pub reason: String,
}