allow_report/artifacts/
migrate.rs1use 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 entries_with_evidence: usize,
16 pub notes: &'a str,
17}
18
19impl<'a> MigrateReport<'a> {
20 pub fn from_config(
21 inventory: InventoryContext<'a>,
22 cfg: &AllowConfig,
23 input_kind: &'a str,
24 input_path: &'a str,
25 output_path: &'a str,
26 force: bool,
27 notes: &'a str,
28 ) -> Self {
29 let counts = MigrateSummaryCounts::from_config(cfg);
30 Self {
31 inventory,
32 input_kind,
33 input_path,
34 output_path,
35 force,
36 allow_entries: counts.allow_entries,
37 baseline_debt: counts.baseline_debt,
38 unsafe_entries: counts.unsafe_entries,
39 entries_with_evidence: counts.entries_with_evidence,
40 notes,
41 }
42 }
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46struct MigrateSummaryCounts {
47 allow_entries: usize,
48 baseline_debt: usize,
49 unsafe_entries: usize,
50 entries_with_evidence: usize,
51}
52
53impl MigrateSummaryCounts {
54 fn from_config(cfg: &AllowConfig) -> Self {
55 Self {
56 allow_entries: cfg.allow.len(),
57 baseline_debt: cfg
58 .allow
59 .iter()
60 .filter(|entry| entry.classification == "baseline_debt")
61 .count(),
62 unsafe_entries: cfg
63 .allow
64 .iter()
65 .filter(|entry| entry.kind == FindingKind::Unsafe)
66 .count(),
67 entries_with_evidence: cfg
68 .allow
69 .iter()
70 .filter(|entry| !entry.evidence.is_empty())
71 .count(),
72 }
73 }
74}