aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/advisory/ignored_security_advisory.rs
blob: 43057829f428bbb1d0a978087144a7ba632cbc01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! ref: composer/src/Composer/Advisory/IgnoredSecurityAdvisory.php

use crate::advisory::SecurityAdvisory;
use chrono::{DateTime, Utc};
use indexmap::IndexMap;
use shirabe_semver::constraint::AnyConstraint;

#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IgnoredSecurityAdvisory {
    #[serde(flatten)]
    inner: SecurityAdvisory,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ignore_reason: Option<String>,
}

impl IgnoredSecurityAdvisory {
    #[allow(clippy::too_many_arguments, reason = "to keep PHP signature")]
    pub fn new(
        package_name: String,
        advisory_id: String,
        affected_versions: AnyConstraint,
        title: String,
        sources: Vec<IndexMap<String, String>>,
        reported_at: DateTime<Utc>,
        cve: Option<String>,
        link: Option<String>,
        ignore_reason: Option<String>,
        severity: Option<String>,
    ) -> Self {
        let inner = SecurityAdvisory::new(
            package_name,
            advisory_id,
            affected_versions,
            title,
            sources,
            reported_at,
            cve,
            link,
            severity,
        );
        Self {
            inner,
            ignore_reason,
        }
    }

    pub fn as_security_advisory(&self) -> &SecurityAdvisory {
        &self.inner
    }
}