aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/advisory/ignored_security_advisory.rs
blob: 7ed3a4ce725499ca26a71388fdcd1abd75523843 (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
52
53
54
//! ref: composer/src/Composer/Advisory/IgnoredSecurityAdvisory.php

use crate::advisory::security_advisory::SecurityAdvisory;
use chrono::{DateTime, Utc};
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
use shirabe_semver::constraint::constraint_interface::ConstraintInterface;

#[derive(Debug)]
pub struct IgnoredSecurityAdvisory {
    inner: SecurityAdvisory,
    pub ignore_reason: Option<String>,
}

impl IgnoredSecurityAdvisory {
    pub fn new(
        package_name: String,
        advisory_id: String,
        affected_versions: Box<dyn ConstraintInterface>,
        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 json_serialize(&self) -> PhpMixed {
        let mut data = self.inner.json_serialize();
        if self.ignore_reason.is_none() {
            if let PhpMixed::Array(ref mut map) = data {
                map.remove("ignoreReason");
            }
        }
        data
    }
}