CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Successful in 1m8s
CI / Deploy MCP (push) Successful in 4m49s
CI / Deploy Dashboard (push) Successful in 6m57s
CI / Deploy Agent (push) Successful in 8m53s
The Tickets page was a paged table only. GET /api/v1/issues now takes q (title word or ticket number: 913, #913, PROJ-913), status (open takes in_progress, closed takes resolved) and repo_id, tenant-scoped as before. A ticket stores no target: the target filter takes the ids of the target's findings with a ticket plus its CVE tickets (finding_id cve:{target}:...). Each row links to its finding, or for a CVE ticket to the target's components and CVEs (SBOM page), next to the tracker link. Texts are German and English, the status is a readable badge. The CVE key prefix and the closed check move to compliance-core so the agent and the dashboard read them the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
5.9 KiB
Rust
196 lines
5.9 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum TrackerType {
|
|
GitHub,
|
|
GitLab,
|
|
Gitea,
|
|
Jira,
|
|
}
|
|
|
|
impl std::fmt::Display for TrackerType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::GitHub => write!(f, "github"),
|
|
Self::GitLab => write!(f, "gitlab"),
|
|
Self::Gitea => write!(f, "gitea"),
|
|
Self::Jira => write!(f, "jira"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum IssueStatus {
|
|
Open,
|
|
InProgress,
|
|
Closed,
|
|
Resolved,
|
|
}
|
|
|
|
impl std::fmt::Display for IssueStatus {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Open => write!(f, "open"),
|
|
Self::InProgress => write!(f, "in_progress"),
|
|
Self::Closed => write!(f, "closed"),
|
|
Self::Resolved => write!(f, "resolved"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl IssueStatus {
|
|
/// Every status, open ones first.
|
|
pub const ALL: [Self; 4] = [Self::Open, Self::InProgress, Self::Closed, Self::Resolved];
|
|
|
|
/// Whether the ticket is done (closed or resolved); the other two are
|
|
/// open.
|
|
pub fn is_closed(&self) -> bool {
|
|
match self {
|
|
Self::Closed | Self::Resolved => true,
|
|
Self::Open | Self::InProgress => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// What a ticket is about, as its `finding_id` says.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum IssueSubject<'a> {
|
|
/// One finding, by its id (the hex of its `ObjectId`).
|
|
Finding(&'a str),
|
|
/// A known vulnerability in one target's components, by the target id.
|
|
Cve {
|
|
/// The target (repository) the CVE was found in.
|
|
target_id: &'a str,
|
|
},
|
|
}
|
|
|
|
/// What the `finding_id` of a CVE ticket starts with.
|
|
const CVE_KEY: &str = "cve:";
|
|
|
|
/// The start of the `finding_id` of every CVE ticket of one target. The whole
|
|
/// key is `cve:{target_id}:{package}:{cve}`: one ticket per target, package
|
|
/// and CVE.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use compliance_core::models::issue::cve_issue_prefix;
|
|
/// assert_eq!(cve_issue_prefix("abc"), "cve:abc:");
|
|
/// ```
|
|
pub fn cve_issue_prefix(target_id: &str) -> String {
|
|
format!("{CVE_KEY}{target_id}:")
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct TrackerIssue {
|
|
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
|
|
pub id: Option<bson::oid::ObjectId>,
|
|
pub finding_id: String,
|
|
pub tracker_type: TrackerType,
|
|
pub external_id: String,
|
|
pub external_url: String,
|
|
pub title: String,
|
|
pub status: IssueStatus,
|
|
/// The tracker user who closed the issue there (#953), while it stays
|
|
/// closed: a person's decision the scan does not undo on its own.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub closed_in_tracker: Option<String>,
|
|
#[serde(with = "super::serde_helpers::bson_datetime")]
|
|
pub created_at: DateTime<Utc>,
|
|
#[serde(with = "super::serde_helpers::bson_datetime")]
|
|
pub updated_at: DateTime<Utc>,
|
|
}
|
|
|
|
impl TrackerIssue {
|
|
pub fn new(
|
|
finding_id: String,
|
|
tracker_type: TrackerType,
|
|
external_id: String,
|
|
external_url: String,
|
|
title: String,
|
|
) -> Self {
|
|
let now = Utc::now();
|
|
Self {
|
|
id: None,
|
|
finding_id,
|
|
tracker_type,
|
|
external_id,
|
|
external_url,
|
|
title,
|
|
status: IssueStatus::Open,
|
|
closed_in_tracker: None,
|
|
created_at: now,
|
|
updated_at: now,
|
|
}
|
|
}
|
|
|
|
/// What the ticket is about: its finding, or for a CVE ticket the target
|
|
/// the CVE is in. `None` when `finding_id` is neither (empty, for an
|
|
/// issue whose finding had no id).
|
|
pub fn subject(&self) -> Option<IssueSubject<'_>> {
|
|
if let Some(rest) = self.finding_id.strip_prefix(CVE_KEY) {
|
|
// `rest` is `{target_id}:{package}:{cve}`; `split` always yields
|
|
// a first piece, so only an empty one is refused.
|
|
return rest
|
|
.split(':')
|
|
.next()
|
|
.filter(|id| !id.is_empty())
|
|
.map(|target_id| IssueSubject::Cve { target_id });
|
|
}
|
|
let id = self.finding_id.as_str();
|
|
(id.len() == 24 && id.bytes().all(|b| b.is_ascii_hexdigit()))
|
|
.then_some(IssueSubject::Finding(id))
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn issue(finding_id: &str) -> TrackerIssue {
|
|
TrackerIssue::new(
|
|
finding_id.to_string(),
|
|
TrackerType::Gitea,
|
|
"913".into(),
|
|
"https://gitea.invalid/o/r/issues/913".into(),
|
|
"[high] semgrep: hardcoded key".into(),
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn a_finding_ticket_is_about_its_finding() {
|
|
let id = "65a1b2c3d4e5f60718293a4b";
|
|
assert_eq!(issue(id).subject(), Some(IssueSubject::Finding(id)));
|
|
}
|
|
|
|
#[test]
|
|
fn a_cve_ticket_is_about_its_target() {
|
|
let key = format!("{}openssl:CVE-2024-0001", cve_issue_prefix("tgt1"));
|
|
assert_eq!(
|
|
issue(&key).subject(),
|
|
Some(IssueSubject::Cve { target_id: "tgt1" })
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_ticket_without_a_usable_id_is_about_nothing() {
|
|
assert_eq!(issue("").subject(), None);
|
|
assert_eq!(issue("cve::pkg:CVE-1").subject(), None);
|
|
assert_eq!(issue("not-an-object-id").subject(), None);
|
|
// The right length, but not hex.
|
|
assert_eq!(issue("zzzzzzzzzzzzzzzzzzzzzzzz").subject(), None);
|
|
}
|
|
|
|
#[test]
|
|
fn closed_and_resolved_are_closed() {
|
|
let closed: Vec<IssueStatus> = IssueStatus::ALL
|
|
.into_iter()
|
|
.filter(IssueStatus::is_closed)
|
|
.collect();
|
|
assert_eq!(closed, [IssueStatus::Closed, IssueStatus::Resolved]);
|
|
}
|
|
}
|