Skip to main content

allow_report/artifacts/
migrate.rs

1use allow_core::{AllowConfig, FindingKind};
2
3use crate::InventoryContext;
4
5#[derive(Debug, Clone, Copy)]
6pub struct MigrateReport<'a> {
7    pub inventory: InventoryContext<'a>,
8    pub input_kind: &'a str,
9    pub input_path: &'a str,
10    pub output_path: &'a str,
11    pub force: bool,
12    pub allow_entries: usize,
13    pub baseline_debt: usize,
14    pub unsafe_entries: usize,
15    pub lint_exception_entries: usize,
16    pub entries_with_evidence: usize,
17    pub evidence_entries: usize,
18    pub entries_with_links: usize,
19    pub link_entries: usize,
20    pub broken_evidence_links: Option<usize>,
21    pub unsafe_broken_evidence_links: Option<usize>,
22    pub weak_evidence_references: Option<usize>,
23    pub unsafe_weak_evidence_references: Option<usize>,
24    pub notes: &'a str,
25}
26
27impl<'a> MigrateReport<'a> {
28    pub fn from_config(
29        inventory: InventoryContext<'a>,
30        cfg: &AllowConfig,
31        input_kind: &'a str,
32        input_path: &'a str,
33        output_path: &'a str,
34        force: bool,
35        notes: &'a str,
36    ) -> Self {
37        let counts = MigrateSummaryCounts::from_config(cfg);
38        Self {
39            inventory,
40            input_kind,
41            input_path,
42            output_path,
43            force,
44            allow_entries: counts.allow_entries,
45            baseline_debt: counts.baseline_debt,
46            unsafe_entries: counts.unsafe_entries,
47            lint_exception_entries: counts.lint_exception_entries,
48            entries_with_evidence: counts.entries_with_evidence,
49            evidence_entries: counts.evidence_entries,
50            entries_with_links: counts.entries_with_links,
51            link_entries: counts.link_entries,
52            broken_evidence_links: None,
53            unsafe_broken_evidence_links: None,
54            weak_evidence_references: None,
55            unsafe_weak_evidence_references: None,
56            notes,
57        }
58    }
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62struct MigrateSummaryCounts {
63    allow_entries: usize,
64    baseline_debt: usize,
65    unsafe_entries: usize,
66    lint_exception_entries: usize,
67    entries_with_evidence: usize,
68    evidence_entries: usize,
69    entries_with_links: usize,
70    link_entries: usize,
71}
72
73impl MigrateSummaryCounts {
74    fn from_config(cfg: &AllowConfig) -> Self {
75        Self {
76            allow_entries: cfg.allow.len(),
77            baseline_debt: cfg
78                .allow
79                .iter()
80                .filter(|entry| entry.classification == "baseline_debt")
81                .count(),
82            unsafe_entries: cfg
83                .allow
84                .iter()
85                .filter(|entry| entry.kind == FindingKind::Unsafe)
86                .count(),
87            lint_exception_entries: cfg
88                .allow
89                .iter()
90                .filter(|entry| entry.kind == FindingKind::LintException)
91                .count(),
92            entries_with_evidence: cfg
93                .allow
94                .iter()
95                .filter(|entry| !entry.evidence.is_empty())
96                .count(),
97            evidence_entries: cfg.allow.iter().map(|entry| entry.evidence.len()).sum(),
98            entries_with_links: cfg
99                .allow
100                .iter()
101                .filter(|entry| !entry.links.is_empty())
102                .count(),
103            link_entries: cfg.allow.iter().map(|entry| entry.links.len()).sum(),
104        }
105    }
106}