feat(dashboard): the Lieferkette page (#1053) (#1057)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m11s
CI / Deploy Dashboard (push) Successful in 6m16s
CI / Deploy Agent (push) Successful in 9m7s
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m11s
CI / Deploy Dashboard (push) Successful in 6m16s
CI / Deploy Agent (push) Successful in 9m7s
This commit was merged in pull request #1057.
This commit is contained in:
1 parent
bc73a61f96
commit
d979fc1644
10 files changed
+1477
No files matched your search
@@ -612,6 +612,9 @@ code {
|
||||
.main-content {
|
||||
margin-left: var(--sidebar-width);
|
||||
flex: 1;
|
||||
/* A flex item grows to its widest content unless told otherwise; wide
|
||||
content (the supply chain graph) then scrolls in its own box. */
|
||||
min-width: 0;
|
||||
padding: 22px 26px 64px;
|
||||
transition: margin-left 0.2s ease;
|
||||
min-height: 100vh;
|
||||
@@ -8621,3 +8624,262 @@ span.repo-crumb-name {
|
||||
.machine-nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ============ Lieferkette (#1050): the supply chain as a graph ============ */
|
||||
.chain-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
/* The graph is wider than a phone: it scrolls in its box, not the page. */
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
.chain-page > * { min-width: 0; }
|
||||
.chain-head h1 {
|
||||
margin: 0 0 6px;
|
||||
font-size: 30px;
|
||||
line-height: 1.1;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.03em;
|
||||
}
|
||||
.chain-head p {
|
||||
margin: 0;
|
||||
max-width: 66ch;
|
||||
color: var(--text-secondary);
|
||||
font-size: 15px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.chain-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px 18px;
|
||||
}
|
||||
.chain-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 18px;
|
||||
margin: 0 auto 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.chain-legend li {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.chain-swatch {
|
||||
width: 28px;
|
||||
height: 0;
|
||||
border-top: 2.5px solid var(--accent);
|
||||
}
|
||||
.chain-swatch.upload { border-top: 2px solid var(--text-faint); }
|
||||
.chain-swatch.missing { border-top: 2px dashed var(--border-strong); }
|
||||
.chain-swatch.own {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
background: var(--brand-chevron-top);
|
||||
}
|
||||
.chain-body {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 18px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.chain-wrap {
|
||||
flex: 999 1 640px;
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 18px;
|
||||
}
|
||||
.chain-canvas {
|
||||
position: relative;
|
||||
touch-action: none;
|
||||
user-select: none;
|
||||
background-image: radial-gradient(var(--border-bright) 1px, transparent 1.2px);
|
||||
background-size: 20px 20px;
|
||||
}
|
||||
.chain-col-title {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
font-size: 12px;
|
||||
color: var(--text-faint);
|
||||
}
|
||||
.chain-edges {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
overflow: visible;
|
||||
pointer-events: none;
|
||||
}
|
||||
.chain-edge {
|
||||
fill: none;
|
||||
stroke-linecap: round;
|
||||
stroke: var(--text-faint);
|
||||
stroke-width: 1.8;
|
||||
}
|
||||
.chain-edge.live { stroke: var(--accent); stroke-width: 2.5; }
|
||||
.chain-edge.upload { stroke: var(--text-faint); stroke-width: 2; }
|
||||
.chain-edge.missing { stroke: var(--border-strong); stroke-width: 2; stroke-dasharray: 5 6; }
|
||||
.chain-edge.hot { stroke: var(--accent); stroke-width: 2.5; }
|
||||
.chain-edge.dim { stroke: var(--border-bright); stroke-width: 1.6; }
|
||||
.chain-head.live { fill: var(--accent); }
|
||||
.chain-head.grey { fill: var(--text-faint); }
|
||||
.chain-head.faint { fill: var(--border-strong); }
|
||||
.chain-chip {
|
||||
position: absolute;
|
||||
transform: translate(-50%, -50%);
|
||||
white-space: nowrap;
|
||||
height: 24px;
|
||||
box-sizing: border-box;
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
pointer-events: none;
|
||||
}
|
||||
.chain-chip-live { background: var(--accent); color: var(--accent-ink); }
|
||||
.chain-chip-upload {
|
||||
background: var(--bg-card);
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border-bright);
|
||||
}
|
||||
.chain-chip-missing { background: var(--bg-elevated); color: var(--text-tertiary); }
|
||||
.chain-node {
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-bright);
|
||||
border-radius: 14px;
|
||||
cursor: grab;
|
||||
touch-action: none;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
.chain-node:active { cursor: grabbing; }
|
||||
.chain-node.supplier {
|
||||
width: 190px;
|
||||
height: 64px;
|
||||
background: var(--text-primary);
|
||||
color: var(--bg-card);
|
||||
border: 0;
|
||||
}
|
||||
.chain-node.supplier .chain-node-sub { color: var(--text-faint); }
|
||||
.chain-node.target { width: 210px; height: 84px; align-items: flex-start; }
|
||||
.chain-node.assembly {
|
||||
width: 200px;
|
||||
height: 72px;
|
||||
background: var(--accent-muted);
|
||||
border: 1.5px solid var(--border-accent);
|
||||
}
|
||||
.chain-node.product {
|
||||
width: 240px;
|
||||
height: 104px;
|
||||
background: var(--accent);
|
||||
color: var(--accent-ink);
|
||||
border: 0;
|
||||
box-shadow: 0 12px 24px -14px var(--accent);
|
||||
}
|
||||
.chain-node.product .chain-node-sub,
|
||||
.chain-node.product .chain-node-state { color: var(--accent-ink); opacity: 0.85; }
|
||||
.chain-node.dim { opacity: 0.45; }
|
||||
.chain-node.selected { outline: 3px solid var(--accent); outline-offset: 3px; }
|
||||
.chain-node:focus-visible { outline: 3px solid var(--border-accent); outline-offset: 3px; }
|
||||
.chain-tile {
|
||||
flex: none;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 9px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
color: var(--bg-card);
|
||||
background: var(--text-primary);
|
||||
}
|
||||
.chain-node.own .chain-tile { background: var(--brand-chevron-top); color: #fff; }
|
||||
.chain-picture {
|
||||
flex: none;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 12px;
|
||||
border: 1px dashed currentColor;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.chain-node-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
.chain-node-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.chain-node-sub { font-size: 12px; color: var(--text-tertiary); }
|
||||
.chain-node-state {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.chain-node-state::before {
|
||||
content: "";
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 4px;
|
||||
background: currentColor;
|
||||
}
|
||||
.chain-node-state.tone-ok { color: var(--success); }
|
||||
.chain-node-state.tone-warn { color: var(--warning); }
|
||||
.chain-node-state.tone-bad { color: var(--danger); }
|
||||
.chain-panel {
|
||||
flex: 1 1 260px;
|
||||
max-width: 320px;
|
||||
box-sizing: border-box;
|
||||
padding: 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 18px;
|
||||
}
|
||||
.chain-panel h2 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
.chain-panel-kind { font-size: 12px; color: var(--text-tertiary); }
|
||||
.chain-panel-facts { margin: 0; font-size: 14px; color: var(--text-secondary); }
|
||||
.chain-panel-link { font-size: 14px; font-weight: 600; }
|
||||
.chain-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 24px;
|
||||
background: var(--bg-card);
|
||||
border: 1px dashed var(--border-bright);
|
||||
border-radius: 18px;
|
||||
}
|
||||
.chain-empty p { margin: 0; color: var(--text-secondary); max-width: 60ch; }
|
||||
@@ -17,6 +17,9 @@ pub enum Route {
|
||||
HeutePage { target: String, bucket: String },
|
||||
#[route("/overview")]
|
||||
OverviewPage {},
|
||||
// The supply chain as a graph the customer arranges (#1050).
|
||||
#[route("/supply-chain")]
|
||||
SupplyChainPage {},
|
||||
#[route("/targets")]
|
||||
TargetsPage {},
|
||||
#[route("/targets/:id")]
|
||||
|
||||
@@ -49,6 +49,13 @@ pub fn Sidebar() -> Element {
|
||||
runtime_only: false,
|
||||
write_only: false,
|
||||
},
|
||||
NavItem {
|
||||
label: nav::SUPPLY_CHAIN,
|
||||
route: Route::SupplyChainPage {},
|
||||
icon: rsx! { Icon { icon: BsDiagram3, width: 18, height: 18 } },
|
||||
runtime_only: false,
|
||||
write_only: false,
|
||||
},
|
||||
NavItem {
|
||||
label: nav::TARGETS,
|
||||
route: Route::TargetsPage {},
|
||||
|
||||
@@ -117,6 +117,10 @@ pub mod nav {
|
||||
de: "Übersicht",
|
||||
en: "Overview",
|
||||
};
|
||||
pub const SUPPLY_CHAIN: Text = Text {
|
||||
de: "Lieferkette",
|
||||
en: "Supply chain",
|
||||
};
|
||||
pub const TARGETS: Text = Text {
|
||||
de: "Prüfobjekte",
|
||||
en: "Targets",
|
||||
@@ -7672,3 +7676,203 @@ pub mod machine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Lieferkette (#1050): the supply chain as a graph.
|
||||
pub mod supply_chain {
|
||||
use super::Text;
|
||||
use crate::i18n::Lang;
|
||||
use crate::infrastructure::supply_chain::NodeKind;
|
||||
|
||||
pub const TITLE: Text = Text {
|
||||
de: "Woraus Ihre Produkte bestehen",
|
||||
en: "What your products are made of",
|
||||
};
|
||||
pub const INTRO: Text = Text {
|
||||
de: "Von den Zulieferern über Komponenten und Baugruppen bis zum Produkt. Ziehen Sie \
|
||||
die Kästen, wie es Ihrer Maschine entspricht; ein Klick zeigt, was zusammenhängt.",
|
||||
en: "From the suppliers through components and assemblies to the product. Drag the \
|
||||
boxes to match your machine; a click shows what belongs together.",
|
||||
};
|
||||
pub const EMPTY: Text = Text {
|
||||
de: "Noch keine Komponente. Legen Sie ein Prüfobjekt an und ordnen Sie es einem Produkt \
|
||||
zu, dann beginnt hier Ihre Lieferkette.",
|
||||
en: "No component yet. Add a target and assign it to a product, and your supply chain \
|
||||
starts here.",
|
||||
};
|
||||
pub const ADD: Text = Text {
|
||||
de: "Komponente hinzufügen",
|
||||
en: "Add a component",
|
||||
};
|
||||
pub const RESET: Text = Text {
|
||||
de: "Anordnung zurücksetzen",
|
||||
en: "Reset the arrangement",
|
||||
};
|
||||
pub const LOAD_FAILED: Text = Text {
|
||||
de: "Die Lieferkette lässt sich gerade nicht laden.",
|
||||
en: "The supply chain cannot be loaded right now.",
|
||||
};
|
||||
pub const LOADING: Text = Text {
|
||||
de: "Lieferkette wird geladen …",
|
||||
en: "Loading the supply chain …",
|
||||
};
|
||||
pub const SAVE_FAILED: Text = Text {
|
||||
de: "Die Anordnung ließ sich nicht speichern.",
|
||||
en: "The arrangement could not be saved.",
|
||||
};
|
||||
pub const GRAPH: Text = Text {
|
||||
de: "Lieferkette als Graph",
|
||||
en: "Supply chain as a graph",
|
||||
};
|
||||
pub const LEGEND: Text = Text {
|
||||
de: "Legende",
|
||||
en: "Legend",
|
||||
};
|
||||
pub const LEGEND_INVITE: Text = Text {
|
||||
de: "Upload-Link, neue Versionen kommen von selbst",
|
||||
en: "Upload link, new versions arrive by themselves",
|
||||
};
|
||||
pub const LEGEND_UPLOAD: Text = Text {
|
||||
de: "per Upload",
|
||||
en: "uploaded",
|
||||
};
|
||||
pub const LEGEND_MISSING: Text = Text {
|
||||
de: "noch keine SBOM",
|
||||
en: "no SBOM yet",
|
||||
};
|
||||
pub const LEGEND_OWN: Text = Text {
|
||||
de: "Eigenentwicklung",
|
||||
en: "In-house",
|
||||
};
|
||||
pub const COL_SUPPLIERS: Text = Text {
|
||||
de: "Zulieferer",
|
||||
en: "Suppliers",
|
||||
};
|
||||
pub const COL_COMPONENTS: Text = Text {
|
||||
de: "Komponenten",
|
||||
en: "Components",
|
||||
};
|
||||
pub const COL_ASSEMBLIES: Text = Text {
|
||||
de: "Baugruppen",
|
||||
en: "Assemblies",
|
||||
};
|
||||
pub const COL_PRODUCTS: Text = Text {
|
||||
de: "Produkte",
|
||||
en: "Products",
|
||||
};
|
||||
pub const SUPPLIER: Text = Text {
|
||||
de: "Zulieferer",
|
||||
en: "Supplier",
|
||||
};
|
||||
pub const BOUGHT: Text = Text {
|
||||
de: "Zugekaufte Komponente",
|
||||
en: "Bought-in component",
|
||||
};
|
||||
pub const OWN: Text = Text {
|
||||
de: "Eigenentwicklung",
|
||||
en: "In-house",
|
||||
};
|
||||
pub const ASSEMBLY: Text = Text {
|
||||
de: "Baugruppe",
|
||||
en: "Assembly",
|
||||
};
|
||||
pub const PRODUCT: Text = Text {
|
||||
de: "Produkt",
|
||||
en: "Product",
|
||||
};
|
||||
pub const FAMILY: Text = Text {
|
||||
de: "Produktfamilie",
|
||||
en: "Product family",
|
||||
};
|
||||
pub const NO_OPEN: Text = Text {
|
||||
de: "keine offenen CVEs",
|
||||
en: "no open CVEs",
|
||||
};
|
||||
pub const NO_SBOM: Text = Text {
|
||||
de: "noch keine SBOM",
|
||||
en: "no SBOM yet",
|
||||
};
|
||||
pub const SBOM: Text = Text {
|
||||
de: "SBOM",
|
||||
en: "SBOM",
|
||||
};
|
||||
pub const LINK_ACTIVE: Text = Text {
|
||||
de: "Upload-Link aktiv",
|
||||
en: "Upload link active",
|
||||
};
|
||||
pub const SELECTED: Text = Text {
|
||||
de: "Ausgewählter Kasten",
|
||||
en: "Selected box",
|
||||
};
|
||||
pub const OPEN_TARGET: Text = Text {
|
||||
de: "Im Prüfobjekt öffnen",
|
||||
en: "Open the target",
|
||||
};
|
||||
pub const OPEN_PRODUCT: Text = Text {
|
||||
de: "Produkt öffnen",
|
||||
en: "Open the product",
|
||||
};
|
||||
|
||||
/// "2 offene CVEs".
|
||||
pub fn open(n: usize, lang: Lang) -> String {
|
||||
match (lang, n) {
|
||||
(Lang::De, 1) => "1 offene CVE".to_string(),
|
||||
(Lang::De, n) => format!("{n} offene CVEs"),
|
||||
(Lang::En, 1) => "1 open CVE".to_string(),
|
||||
(Lang::En, n) => format!("{n} open CVEs"),
|
||||
}
|
||||
}
|
||||
|
||||
/// "1 kritische CVE".
|
||||
pub fn critical(n: usize, lang: Lang) -> String {
|
||||
match (lang, n) {
|
||||
(Lang::De, 1) => "1 kritische CVE".to_string(),
|
||||
(Lang::De, n) => format!("{n} kritische CVEs"),
|
||||
(Lang::En, 1) => "1 critical CVE".to_string(),
|
||||
(Lang::En, n) => format!("{n} critical CVEs"),
|
||||
}
|
||||
}
|
||||
|
||||
/// What a screen reader hears for a box.
|
||||
pub fn node_label(name: &str, sub: &str, state: &str, movable: bool, lang: Lang) -> String {
|
||||
let mut label = format!("{name}, {sub}");
|
||||
if !state.is_empty() {
|
||||
label.push_str(&format!(", {state}"));
|
||||
}
|
||||
if movable {
|
||||
label.push_str(match lang {
|
||||
Lang::De => ". Mit den Pfeiltasten verschieben.",
|
||||
Lang::En => ". Move it with the arrow keys.",
|
||||
});
|
||||
}
|
||||
label
|
||||
}
|
||||
|
||||
/// How a box is joined: what it supplies, or what it is made of and how
|
||||
/// many products or assemblies it is part of.
|
||||
pub fn facts(kind: NodeKind, parts: usize, part_of: usize, lang: Lang) -> String {
|
||||
let plural =
|
||||
|n: usize, one: &str, many: &str| format!("{n} {}", if n == 1 { one } else { many });
|
||||
match (kind, lang) {
|
||||
(NodeKind::Supplier, Lang::De) => {
|
||||
format!("Liefert {}", plural(part_of, "Komponente", "Komponenten"))
|
||||
}
|
||||
(NodeKind::Supplier, Lang::En) => {
|
||||
format!("Supplies {}", plural(part_of, "component", "components"))
|
||||
}
|
||||
(NodeKind::Target, Lang::De) => format!(
|
||||
"Steckt in {}",
|
||||
plural(
|
||||
part_of,
|
||||
"Produkt oder Baugruppe",
|
||||
"Produkten oder Baugruppen"
|
||||
)
|
||||
),
|
||||
(NodeKind::Target, Lang::En) => format!(
|
||||
"Part of {}",
|
||||
plural(part_of, "product or assembly", "products or assemblies")
|
||||
),
|
||||
(NodeKind::Project, Lang::De) => format!("Aus {}", plural(parts, "Teil", "Teilen")),
|
||||
(NodeKind::Project, Lang::En) => format!("Made of {}", plural(parts, "part", "parts")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ pub mod sbom_ecosystems;
|
||||
pub mod scan_changes;
|
||||
pub mod scans;
|
||||
pub mod stats;
|
||||
pub mod supply_chain;
|
||||
pub mod support;
|
||||
pub mod vex;
|
||||
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
//! The supply chain (#1050): what the workspace's products are made of, read
|
||||
//! from the agent's `/api/v1/supply-chain`, and the customer's arrangement of
|
||||
//! it (`/api/v1/supply-chain/layout`).
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use compliance_core::cve_groups::SeverityCounts;
|
||||
use compliance_core::models::{ProjectLevel, TargetType};
|
||||
use dioxus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// What a node stands for.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NodeKind {
|
||||
/// A supplier, by the name a target gives it.
|
||||
Supplier,
|
||||
/// A component: one of the workspace's targets.
|
||||
Target,
|
||||
/// A product project: a family, product or assembly.
|
||||
Project,
|
||||
}
|
||||
|
||||
/// One node of the supply chain.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NodeDto {
|
||||
/// Stable across calls: `supplier:<name>`, `target:<id>`, `project:<id>`.
|
||||
pub key: String,
|
||||
pub kind: NodeKind,
|
||||
pub name: String,
|
||||
/// A component's type.
|
||||
#[serde(default)]
|
||||
pub target_type: Option<TargetType>,
|
||||
/// A component bought in from a supplier.
|
||||
#[serde(default)]
|
||||
pub bought: bool,
|
||||
/// A project's place in the hierarchy.
|
||||
#[serde(default)]
|
||||
pub level: Option<ProjectLevel>,
|
||||
/// Open CVEs; none for a supplier.
|
||||
#[serde(default)]
|
||||
pub open: Option<SeverityCounts>,
|
||||
}
|
||||
|
||||
impl NodeDto {
|
||||
/// The target's id, for a component.
|
||||
pub fn target_id(&self) -> Option<&str> {
|
||||
self.key.strip_prefix("target:")
|
||||
}
|
||||
|
||||
/// The project's id, for a project.
|
||||
pub fn project_id(&self) -> Option<&str> {
|
||||
self.key.strip_prefix("project:")
|
||||
}
|
||||
}
|
||||
|
||||
/// What an edge means.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum EdgeKind {
|
||||
/// A supplier delivers the component.
|
||||
Supplies,
|
||||
/// The component or project is part of the project.
|
||||
PartOf,
|
||||
}
|
||||
|
||||
/// How a supplier's SBOM reaches its component.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DeliveryKind {
|
||||
/// Through an active invite link.
|
||||
Invite,
|
||||
/// Uploaded in the workspace.
|
||||
Upload,
|
||||
/// No SBOM yet.
|
||||
Missing,
|
||||
}
|
||||
|
||||
/// A supplier's delivery to its component.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DeliveryDto {
|
||||
pub how: DeliveryKind,
|
||||
#[serde(default)]
|
||||
pub version: Option<String>,
|
||||
#[serde(default)]
|
||||
pub at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
/// One edge, by node key.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct EdgeDto {
|
||||
pub from: String,
|
||||
pub to: String,
|
||||
pub kind: EdgeKind,
|
||||
#[serde(default)]
|
||||
pub delivery: Option<DeliveryDto>,
|
||||
}
|
||||
|
||||
/// The supply chain (`GET /api/v1/supply-chain`).
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct SupplyChainDto {
|
||||
pub nodes: Vec<NodeDto>,
|
||||
pub edges: Vec<EdgeDto>,
|
||||
}
|
||||
|
||||
/// Where one box sits.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PositionDto {
|
||||
pub key: String,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
/// The customer's arrangement (`GET /api/v1/supply-chain/layout`).
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct LayoutDto {
|
||||
pub positions: Vec<PositionDto>,
|
||||
#[serde(default)]
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
/// The `data` of an agent answer to `req`.
|
||||
#[cfg(feature = "server")]
|
||||
async fn data<T: serde::de::DeserializeOwned>(
|
||||
req: reqwest::RequestBuilder,
|
||||
) -> Result<T, ServerFnError> {
|
||||
#[derive(Deserialize)]
|
||||
struct Body<T> {
|
||||
data: T,
|
||||
}
|
||||
let resp = req
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
let body: Body<T> = super::agent_client::json_or_error(resp).await?;
|
||||
Ok(body.data)
|
||||
}
|
||||
|
||||
/// The workspace's supply chain.
|
||||
#[server]
|
||||
pub async fn fetch_supply_chain() -> Result<SupplyChainDto, ServerFnError> {
|
||||
data(super::agent_client::agent_get("/api/v1/supply-chain").await?).await
|
||||
}
|
||||
|
||||
/// The customer's arrangement of the supply chain.
|
||||
#[server]
|
||||
pub async fn fetch_supply_chain_layout() -> Result<LayoutDto, ServerFnError> {
|
||||
data(super::agent_client::agent_get("/api/v1/supply-chain/layout").await?).await
|
||||
}
|
||||
|
||||
/// Save the arrangement: every placed box.
|
||||
#[server]
|
||||
pub async fn save_supply_chain_layout(positions: Vec<PositionDto>) -> Result<(), ServerFnError> {
|
||||
let req =
|
||||
super::agent_client::agent_request(reqwest::Method::PUT, "/api/v1/supply-chain/layout")
|
||||
.await?
|
||||
.json(&serde_json::json!({ "positions": positions }));
|
||||
data::<LayoutDto>(req).await.map(|_| ())
|
||||
}
|
||||
|
||||
/// Reset the arrangement to the computed columns.
|
||||
#[server]
|
||||
pub async fn reset_supply_chain_layout() -> Result<(), ServerFnError> {
|
||||
let resp =
|
||||
super::agent_client::agent_request(reqwest::Method::DELETE, "/api/v1/supply-chain/layout")
|
||||
.await?
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
super::agent_client::json_or_error::<serde_json::Value>(resp)
|
||||
.await
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_agents_answer_reads() {
|
||||
let chain: SupplyChainDto = serde_json::from_value(serde_json::json!({
|
||||
"nodes": [
|
||||
{ "key": "supplier:Antriebe GmbH", "kind": "supplier", "name": "Antriebe GmbH" },
|
||||
{ "key": "target:t1", "kind": "target", "name": "Antrieb",
|
||||
"target_type": "firmware_rtos", "bought": true,
|
||||
"open": { "critical": 1, "high": 0, "medium": 0, "low": 0, "info": 0 } },
|
||||
{ "key": "project:p1", "kind": "project", "name": "Pumpe", "level": "product",
|
||||
"open": { "critical": 1, "high": 0, "medium": 0, "low": 0, "info": 0 } }
|
||||
],
|
||||
"edges": [
|
||||
{ "from": "supplier:Antriebe GmbH", "to": "target:t1", "kind": "supplies",
|
||||
"delivery": { "how": "upload", "version": "1.4.0", "at": "2026-11-14T10:30:00Z" } },
|
||||
{ "from": "target:t1", "to": "project:p1", "kind": "part_of" }
|
||||
]
|
||||
}))
|
||||
.expect("readable");
|
||||
assert_eq!(chain.nodes[1].target_id(), Some("t1"));
|
||||
assert_eq!(chain.nodes[2].project_id(), Some("p1"));
|
||||
assert_eq!(chain.nodes[2].level, Some(ProjectLevel::Product));
|
||||
assert!(!chain.nodes[0].bought);
|
||||
assert_eq!(
|
||||
chain.edges[0].delivery.as_ref().map(|d| d.how),
|
||||
Some(DeliveryKind::Upload)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ pub mod overview;
|
||||
pub mod pentest_dashboard;
|
||||
pub mod pentest_session;
|
||||
pub mod sbom;
|
||||
pub mod supply_chain;
|
||||
pub mod target;
|
||||
pub mod target_views;
|
||||
pub mod targets;
|
||||
@@ -45,6 +46,7 @@ pub use overview::OverviewPage;
|
||||
pub use pentest_dashboard::PentestDashboardPage;
|
||||
pub use pentest_session::PentestSessionPage;
|
||||
pub use sbom::SbomPage;
|
||||
pub use supply_chain::SupplyChainPage;
|
||||
pub use target::TargetPage;
|
||||
pub use target_views::TargetViewsPage;
|
||||
pub use targets::TargetsPage;
|
||||
@@ -0,0 +1,740 @@
|
||||
//! The Lieferkette (#1050, #1053): what the workspace's products are made of,
|
||||
//! as a graph the customer arranges. Suppliers deliver components, which are
|
||||
//! part of assemblies and products; a component shared by two products makes
|
||||
//! it a DAG. Boxes are dragged (or moved with the arrow keys) and the
|
||||
//! arrangement is kept per workspace; selecting a box highlights everything
|
||||
//! upstream and downstream of it.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use dioxus::html::point_interaction::InteractionLocation;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use compliance_core::cve_groups::SeverityCounts;
|
||||
use compliance_core::models::{ProjectLevel, TargetType};
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::no_access::use_can_write;
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
use crate::i18n::texts::{kinds, supply_chain as tx};
|
||||
use crate::i18n::{format_ago, use_lang, Lang};
|
||||
use crate::infrastructure::supply_chain::{
|
||||
fetch_supply_chain, fetch_supply_chain_layout, reset_supply_chain_layout,
|
||||
save_supply_chain_layout, DeliveryKind, EdgeDto, EdgeKind, LayoutDto, NodeDto, NodeKind,
|
||||
PositionDto, SupplyChainDto,
|
||||
};
|
||||
|
||||
/// The top of the first box in each column, below the column titles.
|
||||
const TOP: i32 = 40;
|
||||
/// The vertical gap between boxes in a column.
|
||||
const GAP: i32 = 30;
|
||||
/// Room around the graph, in pixels.
|
||||
const MARGIN: i32 = 40;
|
||||
/// How far an arrow key moves a box.
|
||||
const STEP: i32 = 20;
|
||||
|
||||
/// The width and height of `node`'s box.
|
||||
fn size(node: &NodeDto) -> (i32, i32) {
|
||||
match (node.kind, node.level) {
|
||||
(NodeKind::Supplier, _) => (190, 64),
|
||||
(NodeKind::Target, _) => (210, 84),
|
||||
(NodeKind::Project, Some(ProjectLevel::Component)) => (200, 72),
|
||||
(NodeKind::Project, _) => (240, 104),
|
||||
}
|
||||
}
|
||||
|
||||
/// The left edge of `node`'s column: suppliers, components, assemblies,
|
||||
/// products, families. The gap after the suppliers leaves room for the
|
||||
/// delivery labels between the boxes.
|
||||
fn column_x(node: &NodeDto) -> i32 {
|
||||
match (node.kind, node.level) {
|
||||
(NodeKind::Supplier, _) => 32,
|
||||
(NodeKind::Target, _) => 420,
|
||||
(NodeKind::Project, Some(ProjectLevel::Component)) => 720,
|
||||
(NodeKind::Project, Some(ProjectLevel::Family)) => 1260,
|
||||
(NodeKind::Project, _) => 990,
|
||||
}
|
||||
}
|
||||
|
||||
/// Where each box sits before the customer moves any: in columns by kind,
|
||||
/// components one under the other (those of one project together), each
|
||||
/// supplier beside its components and each project beside its parts, no two
|
||||
/// boxes of a column overlapping.
|
||||
pub(crate) fn default_positions(chain: &SupplyChainDto) -> HashMap<String, (i32, i32)> {
|
||||
let by_key: HashMap<&str, &NodeDto> = chain.nodes.iter().map(|n| (n.key.as_str(), n)).collect();
|
||||
let project_order: HashMap<&str, usize> = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.kind == NodeKind::Project)
|
||||
.enumerate()
|
||||
.map(|(i, n)| (n.key.as_str(), i))
|
||||
.collect();
|
||||
// The parts of each node: what points at it.
|
||||
let mut parts: HashMap<&str, Vec<&str>> = HashMap::new();
|
||||
for e in &chain.edges {
|
||||
parts
|
||||
.entry(e.to.as_str())
|
||||
.or_default()
|
||||
.push(e.from.as_str());
|
||||
}
|
||||
let first_project = |key: &str| {
|
||||
chain
|
||||
.edges
|
||||
.iter()
|
||||
.filter(|e| e.kind == EdgeKind::PartOf && e.from == key)
|
||||
.filter_map(|e| project_order.get(e.to.as_str()))
|
||||
.min()
|
||||
.copied()
|
||||
.unwrap_or(usize::MAX)
|
||||
};
|
||||
|
||||
let mut targets: Vec<&NodeDto> = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.kind == NodeKind::Target)
|
||||
.collect();
|
||||
targets.sort_by_key(|n| (first_project(&n.key), n.name.to_lowercase()));
|
||||
|
||||
// The centre of the boxes `keys` as placed, if any is.
|
||||
let center = |placed: &HashMap<String, (i32, i32)>, keys: &[&str]| -> Option<i32> {
|
||||
let centers: Vec<i32> = keys
|
||||
.iter()
|
||||
.filter_map(|k| Some(placed.get(*k)?.1 + size(by_key.get(k)?).1 / 2))
|
||||
.collect();
|
||||
(!centers.is_empty()).then(|| centers.iter().sum::<i32>() / centers.len() as i32)
|
||||
};
|
||||
let mut supplied: HashMap<&str, Vec<&str>> = HashMap::new();
|
||||
let mut parents: HashMap<&str, Vec<&str>> = HashMap::new();
|
||||
for e in &chain.edges {
|
||||
let out = match e.kind {
|
||||
EdgeKind::Supplies => &mut supplied,
|
||||
EdgeKind::PartOf => &mut parents,
|
||||
};
|
||||
out.entry(e.from.as_str()).or_default().push(e.to.as_str());
|
||||
}
|
||||
let projects: Vec<&NodeDto> = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.kind == NodeKind::Project)
|
||||
.collect();
|
||||
let mut columns: Vec<i32> = projects.iter().map(|n| column_x(n)).collect();
|
||||
columns.sort_unstable();
|
||||
columns.dedup();
|
||||
let wish = |placed: &HashMap<String, (i32, i32)>, keys: Option<&Vec<&str>>| {
|
||||
center(placed, keys.map_or(&[][..], Vec::as_slice)).unwrap_or(i32::MAX / 2)
|
||||
};
|
||||
|
||||
// Placed three times. After the first, the components are ordered by
|
||||
// where the projects they are part of landed (their barycentre), which
|
||||
// undoes most crossings; a tie keeps the order before.
|
||||
let mut placed: HashMap<String, (i32, i32)> = HashMap::new();
|
||||
for round in 0..3 {
|
||||
if round > 0 {
|
||||
let before = std::mem::take(&mut placed);
|
||||
targets.sort_by_key(|t| wish(&before, parents.get(t.key.as_str())));
|
||||
}
|
||||
let mut y = TOP;
|
||||
for t in &targets {
|
||||
placed.insert(t.key.clone(), (column_x(t), y));
|
||||
y += size(t).1 + GAP;
|
||||
}
|
||||
// Suppliers beside what they supply; then each column of projects,
|
||||
// left to right, beside its parts.
|
||||
let suppliers: Vec<(&NodeDto, i32)> = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.kind == NodeKind::Supplier)
|
||||
.map(|n| (n, wish(&placed, supplied.get(n.key.as_str()))))
|
||||
.collect();
|
||||
stack(&mut placed, suppliers);
|
||||
for &x in &columns {
|
||||
let column: Vec<(&NodeDto, i32)> = projects
|
||||
.iter()
|
||||
.filter(|n| column_x(n) == x)
|
||||
.map(|n| (*n, wish(&placed, parts.get(n.key.as_str()))))
|
||||
.collect();
|
||||
stack(&mut placed, column);
|
||||
}
|
||||
}
|
||||
placed
|
||||
}
|
||||
|
||||
/// Place `column` (each box with the centre it would like) top to bottom in
|
||||
/// that order, each at least [`GAP`] below the one before; one without a
|
||||
/// wish goes last.
|
||||
fn stack(placed: &mut HashMap<String, (i32, i32)>, mut column: Vec<(&NodeDto, i32)>) {
|
||||
column.sort_by_key(|(n, c)| (*c, n.name.to_lowercase()));
|
||||
let mut floor = TOP;
|
||||
for (n, c) in column {
|
||||
let h = size(n).1;
|
||||
let wish = if c >= i32::MAX / 2 { floor } else { c - h / 2 };
|
||||
let y = wish.max(floor);
|
||||
placed.insert(n.key.clone(), (column_x(n), y));
|
||||
floor = y + h + GAP;
|
||||
}
|
||||
}
|
||||
|
||||
/// Every node joined to `key` upstream or downstream, `key` included.
|
||||
fn related(chain: &SupplyChainDto, key: &str) -> HashSet<String> {
|
||||
let mut seen = HashSet::from([key.to_string()]);
|
||||
for downstream in [true, false] {
|
||||
let mut queue = vec![key.to_string()];
|
||||
while let Some(cur) = queue.pop() {
|
||||
for e in &chain.edges {
|
||||
let (a, b) = if downstream {
|
||||
(&e.from, &e.to)
|
||||
} else {
|
||||
(&e.to, &e.from)
|
||||
};
|
||||
if *a == cur && seen.insert(b.clone()) {
|
||||
queue.push(b.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
seen
|
||||
}
|
||||
|
||||
/// The short tag on a component's tile.
|
||||
const fn tag(kind: Option<TargetType>) -> &'static str {
|
||||
match kind {
|
||||
Some(TargetType::FirmwareBareMetal | TargetType::FirmwareRtos) => "FW",
|
||||
Some(TargetType::EmbeddedLinuxYocto) => "Linux",
|
||||
Some(TargetType::PlcSps) => "SPS",
|
||||
Some(TargetType::AndroidApp | TargetType::IosApp) => "App",
|
||||
Some(TargetType::DesktopApp) => "PC",
|
||||
Some(TargetType::WebApp | TargetType::BackendService) => "Web",
|
||||
None => "",
|
||||
}
|
||||
}
|
||||
|
||||
/// A node's CVE state: its tone (a CSS class) and its words.
|
||||
fn cve_state(open: Option<SeverityCounts>, lang: Lang) -> (&'static str, String) {
|
||||
let Some(c) = open else {
|
||||
return ("", String::new());
|
||||
};
|
||||
let total = c.critical + c.high + c.medium + c.low + c.info;
|
||||
match (c.critical, total) {
|
||||
(_, 0) => ("tone-ok", tx::NO_OPEN.get(lang).to_string()),
|
||||
(0, n) => ("tone-warn", tx::open(n, lang)),
|
||||
(k, _) => ("tone-bad", tx::critical(k, lang)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The label on a supplier's edge.
|
||||
fn delivery_label(
|
||||
edge: &EdgeDto,
|
||||
now: &chrono::DateTime<chrono::Utc>,
|
||||
lang: Lang,
|
||||
) -> Option<(&'static str, String)> {
|
||||
let d = edge.delivery.as_ref()?;
|
||||
let when = d.at.as_ref().map(|at| format_ago(at, now, lang));
|
||||
let text = match (d.how, d.version.as_deref(), when) {
|
||||
(DeliveryKind::Missing, ..) => tx::NO_SBOM.get(lang).to_string(),
|
||||
(DeliveryKind::Invite, _, None) => tx::LINK_ACTIVE.get(lang).to_string(),
|
||||
(_, Some(v), Some(w)) => format!("{v} {w}"),
|
||||
(_, Some(v), None) => v.to_string(),
|
||||
(_, None, Some(w)) => w,
|
||||
(_, None, None) => tx::SBOM.get(lang).to_string(),
|
||||
};
|
||||
let class = match d.how {
|
||||
DeliveryKind::Invite => "chain-chip chain-chip-live",
|
||||
DeliveryKind::Upload => "chain-chip chain-chip-upload",
|
||||
DeliveryKind::Missing => "chain-chip chain-chip-missing",
|
||||
};
|
||||
Some((class, text))
|
||||
}
|
||||
|
||||
/// A drag in progress: the box, where the pointer started and where the box was.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
struct Drag {
|
||||
sx: f64,
|
||||
sy: f64,
|
||||
ox: i32,
|
||||
oy: i32,
|
||||
moved: bool,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn SupplyChainPage() -> Element {
|
||||
let lang = use_lang()();
|
||||
let chain = use_resource(fetch_supply_chain);
|
||||
let layout = use_resource(fetch_supply_chain_layout);
|
||||
let (chain, layout) = (chain.read().clone(), layout.read().clone());
|
||||
rsx! {
|
||||
div { class: "chain-page",
|
||||
header { class: "chain-head",
|
||||
div { class: "chain-head-text",
|
||||
h1 { {tx::TITLE.get(lang)} }
|
||||
p { {tx::INTRO.get(lang)} }
|
||||
}
|
||||
}
|
||||
match (chain, layout) {
|
||||
(Some(Ok(chain)), Some(Ok(layout))) => rsx! {
|
||||
if chain.nodes.iter().any(|n| n.kind == NodeKind::Target) {
|
||||
ChainView { chain, layout }
|
||||
} else {
|
||||
div { class: "chain-empty",
|
||||
p { {tx::EMPTY.get(lang)} }
|
||||
Link { class: "btn btn-primary", to: Route::OnboardingPage {}, {tx::ADD.get(lang)} }
|
||||
}
|
||||
}
|
||||
},
|
||||
(Some(Err(_)), _) | (_, Some(Err(_))) => rsx! {
|
||||
p { class: "chain-error", {tx::LOAD_FAILED.get(lang)} }
|
||||
},
|
||||
_ => rsx! { p { class: "chain-loading", {tx::LOADING.get(lang)} } },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The graph, its legend and the selected box's panel.
|
||||
#[component]
|
||||
fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
let lang = use_lang()();
|
||||
let can_write = use_can_write();
|
||||
let mut toasts = use_context::<Toasts>();
|
||||
let defaults = use_hook(|| default_positions(&chain));
|
||||
let mut pos = use_signal(|| {
|
||||
let mut p = defaults.clone();
|
||||
for saved in &layout.positions {
|
||||
if let Some(slot) = p.get_mut(&saved.key) {
|
||||
*slot = (saved.x, saved.y);
|
||||
}
|
||||
}
|
||||
p
|
||||
});
|
||||
let first = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|n| n.kind == NodeKind::Project && n.level != Some(ProjectLevel::Component))
|
||||
.or_else(|| chain.nodes.first())
|
||||
.map(|n| n.key.clone())
|
||||
.unwrap_or_default();
|
||||
let mut selected = use_signal(move || first);
|
||||
let mut drag: Signal<Option<(String, Drag)>> = use_signal(|| None);
|
||||
|
||||
let save = move || {
|
||||
let positions: Vec<PositionDto> = pos
|
||||
.read()
|
||||
.iter()
|
||||
.map(|(key, (x, y))| PositionDto {
|
||||
key: key.clone(),
|
||||
x: *x,
|
||||
y: *y,
|
||||
})
|
||||
.collect();
|
||||
spawn(async move {
|
||||
if save_supply_chain_layout(positions).await.is_err() {
|
||||
toasts.push(ToastType::Error, tx::SAVE_FAILED.get(lang).to_string());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let now = chrono::Utc::now();
|
||||
let rel = related(&chain, &selected.read());
|
||||
let p = pos.read().clone();
|
||||
let by_key: HashMap<&str, &NodeDto> = chain.nodes.iter().map(|n| (n.key.as_str(), n)).collect();
|
||||
let (width, height) = chain.nodes.iter().fold((0, 0), |(w, h), n| {
|
||||
let (x, y) = p.get(&n.key).copied().unwrap_or((0, 0));
|
||||
let (nw, nh) = size(n);
|
||||
(w.max(x + nw + MARGIN), h.max(y + nh + MARGIN))
|
||||
});
|
||||
|
||||
struct Line {
|
||||
d: String,
|
||||
class: &'static str,
|
||||
marker: &'static str,
|
||||
label: Option<(&'static str, String, i32, i32)>,
|
||||
}
|
||||
let lines: Vec<Line> = chain
|
||||
.edges
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let (a, b) = (by_key.get(e.from.as_str())?, by_key.get(e.to.as_str())?);
|
||||
let ((ax, ay), (bx, by)) = (p.get(&e.from)?, p.get(&e.to)?);
|
||||
let (x1, y1) = (ax + size(a).0, ay + size(a).1 / 2);
|
||||
let (x2, y2) = (bx - 6, by + size(b).1 / 2);
|
||||
let dx = ((x2 - x1).abs() / 2).max(50);
|
||||
let on = rel.contains(&e.from) && rel.contains(&e.to);
|
||||
let (class, marker) = match (e.kind, e.delivery.as_ref().map(|d| d.how), on) {
|
||||
(EdgeKind::Supplies, Some(DeliveryKind::Invite), _) => {
|
||||
("chain-edge live", "url(#chain-head-live)")
|
||||
}
|
||||
(EdgeKind::Supplies, Some(DeliveryKind::Missing), _) => {
|
||||
("chain-edge missing", "url(#chain-head-faint)")
|
||||
}
|
||||
(EdgeKind::Supplies, _, _) => ("chain-edge upload", "url(#chain-head-grey)"),
|
||||
(EdgeKind::PartOf, _, true) => ("chain-edge part hot", "url(#chain-head-live)"),
|
||||
(EdgeKind::PartOf, _, false) => ("chain-edge part", "url(#chain-head-grey)"),
|
||||
};
|
||||
Some(Line {
|
||||
d: format!(
|
||||
"M {x1} {y1} C {} {y1}, {} {y2}, {x2} {y2}",
|
||||
x1 + dx,
|
||||
x2 - dx
|
||||
),
|
||||
class: if on { class } else { "chain-edge dim" },
|
||||
marker,
|
||||
label: delivery_label(e, &now, lang)
|
||||
.map(|(c, t)| (c, t, (x1 + x2) / 2, (y1 + y2) / 2)),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
let sel = selected.read().clone();
|
||||
let picked = by_key.get(sel.as_str()).copied();
|
||||
let reset_chain = chain.clone();
|
||||
|
||||
rsx! {
|
||||
div { class: "chain-toolbar",
|
||||
ul { class: "chain-legend", "aria-label": tx::LEGEND.get(lang),
|
||||
li { span { class: "chain-swatch live" } {tx::LEGEND_INVITE.get(lang)} }
|
||||
li { span { class: "chain-swatch upload" } {tx::LEGEND_UPLOAD.get(lang)} }
|
||||
li { span { class: "chain-swatch missing" } {tx::LEGEND_MISSING.get(lang)} }
|
||||
li { span { class: "chain-swatch own" } {tx::LEGEND_OWN.get(lang)} }
|
||||
}
|
||||
if can_write {
|
||||
button {
|
||||
class: "btn btn-secondary",
|
||||
r#type: "button",
|
||||
onclick: move |_| {
|
||||
pos.set(default_positions(&reset_chain));
|
||||
spawn(async move {
|
||||
if reset_supply_chain_layout().await.is_err() {
|
||||
toasts.push(ToastType::Error, tx::SAVE_FAILED.get(lang).to_string());
|
||||
}
|
||||
});
|
||||
},
|
||||
{tx::RESET.get(lang)}
|
||||
}
|
||||
Link { class: "btn btn-primary", to: Route::OnboardingPage {}, {tx::ADD.get(lang)} }
|
||||
}
|
||||
}
|
||||
div { class: "chain-body",
|
||||
section { class: "chain-wrap", "aria-label": tx::GRAPH.get(lang),
|
||||
div {
|
||||
class: "chain-canvas",
|
||||
style: "width: {width}px; height: {height}px;",
|
||||
onpointermove: move |e| {
|
||||
let Some((key, d)) = drag.read().clone() else { return };
|
||||
let at = e.client_coordinates();
|
||||
let (dx, dy) = ((at.x - d.sx).round() as i32, (at.y - d.sy).round() as i32);
|
||||
if dx != 0 || dy != 0 {
|
||||
pos.write().insert(key.clone(), (d.ox + dx, d.oy + dy));
|
||||
drag.set(Some((key, Drag { moved: true, ..d })));
|
||||
}
|
||||
},
|
||||
onpointerup: move |_| {
|
||||
if let Some((_, d)) = drag.take() {
|
||||
if d.moved {
|
||||
save();
|
||||
}
|
||||
}
|
||||
},
|
||||
onpointerleave: move |_| {
|
||||
if let Some((_, d)) = drag.take() {
|
||||
if d.moved {
|
||||
save();
|
||||
}
|
||||
}
|
||||
},
|
||||
for (x, title) in [(32, tx::COL_SUPPLIERS), (420, tx::COL_COMPONENTS), (720, tx::COL_ASSEMBLIES), (990, tx::COL_PRODUCTS)] {
|
||||
div { class: "chain-col-title", style: "left: {x}px;", {title.get(lang)} }
|
||||
}
|
||||
svg {
|
||||
class: "chain-edges",
|
||||
width: "{width}",
|
||||
height: "{height}",
|
||||
"aria-hidden": "true",
|
||||
defs {
|
||||
marker { id: "chain-head-live", "orient": "auto", "markerWidth": "6", "markerHeight": "6", "refX": "4", "refY": "3",
|
||||
path { d: "M0 0 L6 3 L0 6 Z", class: "chain-head live" }
|
||||
}
|
||||
marker { id: "chain-head-grey", "orient": "auto", "markerWidth": "6", "markerHeight": "6", "refX": "4", "refY": "3",
|
||||
path { d: "M0 0 L6 3 L0 6 Z", class: "chain-head grey" }
|
||||
}
|
||||
marker { id: "chain-head-faint", "orient": "auto", "markerWidth": "6", "markerHeight": "6", "refX": "4", "refY": "3",
|
||||
path { d: "M0 0 L6 3 L0 6 Z", class: "chain-head faint" }
|
||||
}
|
||||
}
|
||||
for line in lines.iter() {
|
||||
path { d: "{line.d}", class: "{line.class}", "marker-end": "{line.marker}" }
|
||||
}
|
||||
}
|
||||
for line in lines.iter() {
|
||||
if let Some((class, text, x, y)) = line.label.clone() {
|
||||
div { class: "{class}", style: "left: {x}px; top: {y}px;", "{text}" }
|
||||
}
|
||||
}
|
||||
for node in chain.nodes.iter().cloned() {
|
||||
{
|
||||
let key = node.key.clone();
|
||||
let (x, y) = p.get(&key).copied().unwrap_or((0, 0));
|
||||
let on = rel.contains(&key);
|
||||
let is_sel = sel == key;
|
||||
let (tone, state) = cve_state(node.open, lang);
|
||||
let class = match (node.kind, node.level, node.bought) {
|
||||
(NodeKind::Supplier, ..) => "chain-node supplier",
|
||||
(NodeKind::Target, _, true) => "chain-node target",
|
||||
(NodeKind::Target, _, false) => "chain-node target own",
|
||||
(NodeKind::Project, Some(ProjectLevel::Component), _) => "chain-node assembly",
|
||||
(NodeKind::Project, ..) => "chain-node product",
|
||||
};
|
||||
let sub = match (node.kind, node.level) {
|
||||
(NodeKind::Supplier, _) => tx::SUPPLIER.get(lang).to_string(),
|
||||
(NodeKind::Target, _) => node.target_type.map(|t| kinds::target_type(&t.to_string(), lang)).unwrap_or_default(),
|
||||
(NodeKind::Project, Some(ProjectLevel::Component)) => tx::ASSEMBLY.get(lang).to_string(),
|
||||
(NodeKind::Project, Some(ProjectLevel::Family)) => tx::FAMILY.get(lang).to_string(),
|
||||
(NodeKind::Project, _) => tx::PRODUCT.get(lang).to_string(),
|
||||
};
|
||||
let (key_down, key_up, key_click) = (key.clone(), key.clone(), key.clone());
|
||||
rsx! {
|
||||
button {
|
||||
key: "{key}",
|
||||
class: "{class}",
|
||||
class: if !on { "dim" },
|
||||
class: if is_sel { "selected" },
|
||||
r#type: "button",
|
||||
style: "left: {x}px; top: {y}px;",
|
||||
"aria-pressed": if is_sel { "true" } else { "false" },
|
||||
"aria-label": tx::node_label(&node.name, &sub, &state, can_write, lang),
|
||||
onclick: move |_| selected.set(key_click.clone()),
|
||||
onpointerdown: move |e| {
|
||||
selected.set(key_down.clone());
|
||||
if can_write {
|
||||
let at = e.client_coordinates();
|
||||
drag.set(Some((key_down.clone(), Drag { sx: at.x, sy: at.y, ox: x, oy: y, moved: false })));
|
||||
}
|
||||
},
|
||||
onkeydown: move |e| {
|
||||
let step = match e.key() {
|
||||
Key::ArrowLeft => (-STEP, 0),
|
||||
Key::ArrowRight => (STEP, 0),
|
||||
Key::ArrowUp => (0, -STEP),
|
||||
Key::ArrowDown => (0, STEP),
|
||||
_ => return,
|
||||
};
|
||||
if can_write {
|
||||
e.prevent_default();
|
||||
pos.write().insert(key_up.clone(), (x + step.0, y + step.1));
|
||||
}
|
||||
},
|
||||
onkeyup: move |e| {
|
||||
if can_write && matches!(e.key(), Key::ArrowLeft | Key::ArrowRight | Key::ArrowUp | Key::ArrowDown) {
|
||||
save();
|
||||
}
|
||||
},
|
||||
if node.kind == NodeKind::Target {
|
||||
span { class: "chain-tile", "aria-hidden": "true", {tag(node.target_type)} }
|
||||
}
|
||||
if node.kind == NodeKind::Project && node.level != Some(ProjectLevel::Component) {
|
||||
span { class: "chain-picture", "aria-hidden": "true" }
|
||||
}
|
||||
span { class: "chain-node-text",
|
||||
span { class: "chain-node-name", "{node.name}" }
|
||||
span { class: "chain-node-sub", "{sub}" }
|
||||
if !state.is_empty() {
|
||||
span { class: "chain-node-state {tone}", "{state}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(n) = picked {
|
||||
aside { class: "chain-panel", "aria-label": tx::SELECTED.get(lang),
|
||||
span { class: "chain-panel-kind",
|
||||
{match (n.kind, n.level) {
|
||||
(NodeKind::Supplier, _) => tx::SUPPLIER.get(lang),
|
||||
(NodeKind::Target, _) if n.bought => tx::BOUGHT.get(lang),
|
||||
(NodeKind::Target, _) => tx::OWN.get(lang),
|
||||
(NodeKind::Project, Some(ProjectLevel::Component)) => tx::ASSEMBLY.get(lang),
|
||||
(NodeKind::Project, Some(ProjectLevel::Family)) => tx::FAMILY.get(lang),
|
||||
(NodeKind::Project, _) => tx::PRODUCT.get(lang),
|
||||
}}
|
||||
}
|
||||
h2 { "{n.name}" }
|
||||
{
|
||||
let (tone, state) = cve_state(n.open, lang);
|
||||
rsx! {
|
||||
if !state.is_empty() {
|
||||
p { class: "chain-node-state {tone}", "{state}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
let parts = chain.edges.iter().filter(|e| e.to == n.key && e.kind == EdgeKind::PartOf).count();
|
||||
let out = chain.edges.iter().filter(|e| e.from == n.key).count();
|
||||
rsx! {
|
||||
p { class: "chain-panel-facts", {tx::facts(n.kind, parts, out, lang)} }
|
||||
}
|
||||
}
|
||||
if let Some(id) = n.target_id() {
|
||||
Link { class: "chain-panel-link", to: Route::TargetPage { id: id.to_string() }, {tx::OPEN_TARGET.get(lang)} }
|
||||
}
|
||||
if let Some(id) = n.project_id() {
|
||||
Link { class: "chain-panel-link", to: Route::MachinePage { id: id.to_string(), tab: String::new() }, {tx::OPEN_PRODUCT.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::infrastructure::supply_chain::DeliveryDto;
|
||||
|
||||
fn node(key: &str, kind: NodeKind, level: Option<ProjectLevel>) -> NodeDto {
|
||||
NodeDto {
|
||||
key: key.into(),
|
||||
kind,
|
||||
name: key.into(),
|
||||
target_type: None,
|
||||
bought: false,
|
||||
level,
|
||||
open: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn edge(from: &str, to: &str, kind: EdgeKind) -> EdgeDto {
|
||||
EdgeDto {
|
||||
from: from.into(),
|
||||
to: to.into(),
|
||||
kind,
|
||||
delivery: (kind == EdgeKind::Supplies).then(|| DeliveryDto {
|
||||
how: DeliveryKind::Upload,
|
||||
version: Some("1.4.0".into()),
|
||||
at: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Two suppliers' components in an assembly of p1, and a component of
|
||||
/// the workspace's own shared by p1 and p2.
|
||||
fn chain() -> SupplyChainDto {
|
||||
use EdgeKind::{PartOf, Supplies};
|
||||
SupplyChainDto {
|
||||
nodes: vec![
|
||||
node("supplier:A", NodeKind::Supplier, None),
|
||||
node("supplier:B", NodeKind::Supplier, None),
|
||||
node("target:drive", NodeKind::Target, None),
|
||||
node("target:sensor", NodeKind::Target, None),
|
||||
node("target:plc", NodeKind::Target, None),
|
||||
node("project:p1", NodeKind::Project, Some(ProjectLevel::Product)),
|
||||
node("project:p2", NodeKind::Project, Some(ProjectLevel::Product)),
|
||||
node(
|
||||
"project:c1",
|
||||
NodeKind::Project,
|
||||
Some(ProjectLevel::Component),
|
||||
),
|
||||
],
|
||||
edges: vec![
|
||||
edge("supplier:A", "target:drive", Supplies),
|
||||
edge("supplier:B", "target:sensor", Supplies),
|
||||
edge("target:drive", "project:c1", PartOf),
|
||||
edge("target:sensor", "project:c1", PartOf),
|
||||
edge("project:c1", "project:p1", PartOf),
|
||||
edge("target:plc", "project:p1", PartOf),
|
||||
edge("target:plc", "project:p2", PartOf),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boxes_start_in_columns_without_overlapping() {
|
||||
let c = chain();
|
||||
let at = default_positions(&c);
|
||||
assert_eq!(at.len(), c.nodes.len(), "every box placed");
|
||||
for n in &c.nodes {
|
||||
assert_eq!(at[&n.key].0, column_x(n), "{} in its column", n.key);
|
||||
}
|
||||
for a in &c.nodes {
|
||||
for b in &c.nodes {
|
||||
if a.key < b.key && column_x(a) == column_x(b) {
|
||||
let (ya, yb) = (at[&a.key].1, at[&b.key].1);
|
||||
let (top, bottom, h) = if ya <= yb {
|
||||
(ya, yb, size(a).1)
|
||||
} else {
|
||||
(yb, ya, size(b).1)
|
||||
};
|
||||
assert!(top + h + GAP <= bottom, "{} and {} overlap", a.key, b.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_supplier_sits_beside_its_component_and_labels_fit_between() {
|
||||
let c = chain();
|
||||
let at = default_positions(&c);
|
||||
let center = |key: &str| {
|
||||
let n = c.nodes.iter().find(|n| n.key == key).unwrap();
|
||||
at[key].1 + size(n).1 / 2
|
||||
};
|
||||
assert_eq!(center("supplier:A"), center("target:drive"));
|
||||
// The gap between the columns holds a delivery label ("1.4.0 vor 5 Tagen").
|
||||
let supplier = c
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|n| n.kind == NodeKind::Supplier)
|
||||
.unwrap();
|
||||
let target = c.nodes.iter().find(|n| n.kind == NodeKind::Target).unwrap();
|
||||
assert!(column_x(target) - (column_x(supplier) + size(supplier).0) >= 170);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_parts_of_one_project_start_together() {
|
||||
let c = chain();
|
||||
let at = default_positions(&c);
|
||||
// The assembly's two parts are next to each other.
|
||||
let mut rows = [
|
||||
("drive", at["target:drive"].1),
|
||||
("sensor", at["target:sensor"].1),
|
||||
("plc", at["target:plc"].1),
|
||||
];
|
||||
rows.sort_by_key(|(_, y)| *y);
|
||||
let order: Vec<&str> = rows.iter().map(|(k, _)| *k).collect();
|
||||
assert!(
|
||||
order == ["plc", "drive", "sensor"] || order == ["drive", "sensor", "plc"],
|
||||
"{order:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selecting_a_product_reaches_its_whole_chain_and_nothing_else() {
|
||||
let c = chain();
|
||||
let rel = related(&c, "project:p2");
|
||||
let expected: HashSet<String> = ["project:p2", "target:plc"].map(String::from).into();
|
||||
assert_eq!(
|
||||
rel, expected,
|
||||
"p1 shares the PLC but is neither up- nor downstream of p2"
|
||||
);
|
||||
let rel = related(&c, "supplier:A");
|
||||
assert!(rel.contains("project:p1") && !rel.contains("supplier:B"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cve_state_names_the_worst() {
|
||||
let counts = |critical, high| SeverityCounts {
|
||||
critical,
|
||||
high,
|
||||
..SeverityCounts::default()
|
||||
};
|
||||
assert_eq!(cve_state(Some(counts(0, 0)), Lang::De).0, "tone-ok");
|
||||
assert_eq!(
|
||||
cve_state(Some(counts(0, 2)), Lang::De),
|
||||
("tone-warn", "2 offene CVEs".into())
|
||||
);
|
||||
assert_eq!(
|
||||
cve_state(Some(counts(1, 2)), Lang::De),
|
||||
("tone-bad", "1 kritische CVE".into())
|
||||
);
|
||||
assert_eq!(cve_state(None, Lang::De).1, "");
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ export default withMermaid(defineConfig({
|
||||
{ text: 'Befunde', link: '/guide/findings' },
|
||||
{ text: 'Befunde aus manuellen Tests', link: '/guide/manual-findings' },
|
||||
{ text: 'Stückliste (SBOM) und Lizenzen', link: '/guide/sbom' },
|
||||
{ text: 'Lieferkette', link: '/guide/lieferkette' },
|
||||
{ text: 'Schwachstellen bewerten (VEX)', link: '/guide/vex' },
|
||||
{ text: 'Assessing vulnerabilities (English)', link: '/guide/vex-en' },
|
||||
{ text: 'Bezug zu CRA-Themen', link: '/features/control-mapping' },
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
title: Lieferkette
|
||||
---
|
||||
|
||||
# Lieferkette
|
||||
|
||||
Die Seite **Lieferkette** zeigt, woraus Ihre Produkte bestehen, als Graph:
|
||||
von den Zulieferern über die Komponenten und Baugruppen bis zum Produkt.
|
||||
Eine Komponente, die in zwei Produkten steckt, ist mit beiden verbunden.
|
||||
|
||||
## Was die Kästen sind
|
||||
|
||||
- **Zulieferer:** der Name, den eine zugekaufte Komponente als Zulieferer
|
||||
nennt (im Prüfobjekt unter **Bearbeiten**, Herkunft „Zugekaufte
|
||||
Komponente“).
|
||||
- **Komponenten:** Ihre Prüfobjekte, zugekaufte und eigene. Eigene tragen
|
||||
ein violettes Kennzeichen.
|
||||
- **Baugruppen und Produkte:** Ihre Projekte der Art *Produkt*. Die Ebene
|
||||
(Produktfamilie, Produkt, Baugruppe) und was worunter hängt, legen Sie im
|
||||
Portal unter **Projekte** fest. Ein Prüfobjekt hängt an den Projekten,
|
||||
denen es zugeordnet ist.
|
||||
|
||||
Jeder Kasten zeigt die offenen CVEs. Bei einem Produkt oder einer Baugruppe
|
||||
zählt jede Komponente darunter einmal, auch wenn sie über mehrere Wege
|
||||
dazugehört.
|
||||
|
||||
## Was die Linien sagen
|
||||
|
||||
Die Linie vom Zulieferer zur Komponente sagt, wie deren SBOM ankommt:
|
||||
|
||||
- **Upload-Link** (durchgezogen, farbig): Der Zulieferer lädt neue
|
||||
Versionen über einen Link selbst hoch. Daneben steht die Version und
|
||||
wann sie kam, oder „Upload-Link aktiv“, solange noch nichts kam.
|
||||
- **per Upload** (durchgezogen, grau): Jemand aus Ihrem Workspace hat die
|
||||
SBOM hochgeladen.
|
||||
- **noch keine SBOM** (gestrichelt).
|
||||
|
||||
## Anordnen
|
||||
|
||||
Ziehen Sie die Kästen mit der Maus, oder wählen Sie einen Kasten mit der
|
||||
Tabulatortaste und verschieben Sie ihn mit den Pfeiltasten. Die Anordnung
|
||||
gilt für den ganzen Workspace und bleibt erhalten. Ein neuer Kasten nimmt
|
||||
seinen berechneten Platz ein. **Anordnung zurücksetzen** stellt die Spalten
|
||||
wieder her. Rollen, die nur lesen dürfen, sehen die Anordnung, verschieben
|
||||
aber nichts.
|
||||
|
||||
Ein Klick auf einen Kasten hebt alles hervor, was davor und danach liegt:
|
||||
bei einem Produkt seine Baugruppen, Komponenten und Zulieferer. Rechts
|
||||
stehen die Angaben zum Kasten und der Weg zum Prüfobjekt oder Produkt.
|
||||
|
||||
Für Integrationen: `GET /api/v1/supply-chain` liefert den Graphen,
|
||||
`GET`, `PUT` und `DELETE /api/v1/supply-chain/layout` die Anordnung.
|
||||
Reference in new issue
Block a user