This commit was merged in pull request #389.
This commit is contained in:
1 parent
80eb7f462c
commit
e6e5b14a04
11 files changed
+563
-2
No files matched your search
@@ -53,6 +53,10 @@ pub(crate) fn de_limit<'de, D: serde::Deserializer<'de>>(d: D) -> Result<i64, D:
|
||||
pub struct FindingsFilter {
|
||||
#[serde(default)]
|
||||
pub repo_id: Option<String>,
|
||||
/// Only the findings a given scan run found first (the dashboard reveals
|
||||
/// them when the run ends).
|
||||
#[serde(default)]
|
||||
pub scan_run_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub severity: Option<String>,
|
||||
#[serde(default)]
|
||||
|
||||
@@ -19,6 +19,9 @@ pub async fn list_findings(
|
||||
if let Some(repo_id) = &filter.repo_id {
|
||||
query.insert("repo_id", repo_id);
|
||||
}
|
||||
if let Some(scan_run_id) = &filter.scan_run_id {
|
||||
query.insert("scan_run_id", scan_run_id);
|
||||
}
|
||||
if let Some(severity) = &filter.severity {
|
||||
query.insert("severity", severity);
|
||||
}
|
||||
|
||||
@@ -630,6 +630,8 @@ impl PipelineOrchestrator {
|
||||
planned_steps = plan.steps.len(),
|
||||
"Unified pipeline: scan plan built"
|
||||
);
|
||||
self.record_planned_phases(scan_run_id, &planned_phases(target, &plan, &self.config))
|
||||
.await;
|
||||
|
||||
// Ingest + classify (Firmwerk for firmware) and store the detected type.
|
||||
// The ingested paths are where an uploaded archive was unpacked.
|
||||
@@ -1482,6 +1484,24 @@ impl PipelineOrchestrator {
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Store the phases a run will go through, for the dashboard's stepper.
|
||||
async fn record_planned_phases(&self, scan_run_id: &str, phases: &[ScanPhase]) {
|
||||
let (Ok(oid), Ok(phases)) = (
|
||||
mongodb::bson::oid::ObjectId::parse_str(scan_run_id),
|
||||
mongodb::bson::to_bson(phases),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let _ = self
|
||||
.db
|
||||
.scan_runs()
|
||||
.update_one(
|
||||
doc! { "_id": oid },
|
||||
doc! { "$set": { "planned_phases": phases } },
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn update_phase(&self, scan_run_id: &str, phase: ScanPhase) {
|
||||
let Ok(phase) = mongodb::bson::to_bson(&phase) else {
|
||||
return;
|
||||
@@ -1502,6 +1522,63 @@ impl PipelineOrchestrator {
|
||||
}
|
||||
}
|
||||
|
||||
/// The phases [`PipelineOrchestrator::run_target_pipeline`] goes through for
|
||||
/// `target`, in order. It follows the same branches: PLC and ICS targets, a
|
||||
/// code artifact (git or an uploaded archive), or DAST alone. A git run that
|
||||
/// finds no new commit stops early, so a completed run may not reach them all.
|
||||
fn planned_phases(
|
||||
target: &OnboardedTarget,
|
||||
plan: &crate::pipeline::plan::ScanPlan,
|
||||
config: &AgentConfig,
|
||||
) -> Vec<ScanPhase> {
|
||||
let mut phases = vec![ScanPhase::Classification];
|
||||
let plc = plan.has(ScanType::PlcControlLogic);
|
||||
let ics = plan.has(ScanType::IcsProbe);
|
||||
let dast = plan.has(ScanType::Dast);
|
||||
if plc || ics {
|
||||
if plc {
|
||||
phases.push(ScanPhase::PlcAnalysis);
|
||||
if config.plc_runtime.enabled && target.live_url().is_none() {
|
||||
phases.push(ScanPhase::PlcProvision);
|
||||
}
|
||||
}
|
||||
if ics {
|
||||
phases.push(ScanPhase::IcsProbe);
|
||||
}
|
||||
if dast {
|
||||
phases.push(ScanPhase::DastScanning);
|
||||
}
|
||||
return phases;
|
||||
}
|
||||
if target.code_artifact().is_some() {
|
||||
// The stages of `scan_tree`, in the order it reports them.
|
||||
phases.extend([
|
||||
ScanPhase::Sast,
|
||||
ScanPhase::SbomGeneration,
|
||||
ScanPhase::CveScanning,
|
||||
ScanPhase::PatternScanning,
|
||||
ScanPhase::SecretDetection,
|
||||
ScanPhase::LintScanning,
|
||||
ScanPhase::GraphBuilding,
|
||||
ScanPhase::LlmTriage,
|
||||
ScanPhase::ControlTriage,
|
||||
]);
|
||||
if config.breakpilot.semantic_mapping {
|
||||
phases.push(ScanPhase::SemanticControlMapping);
|
||||
}
|
||||
if config.breakpilot.grounded_control_checks {
|
||||
phases.push(ScanPhase::GroundedControlChecks);
|
||||
}
|
||||
phases.push(ScanPhase::IssueCreation);
|
||||
if dast {
|
||||
phases.push(ScanPhase::DastScanning);
|
||||
}
|
||||
} else if dast || target.artifacts.is_empty() {
|
||||
phases.push(ScanPhase::DastScanning);
|
||||
}
|
||||
phases
|
||||
}
|
||||
|
||||
/// Extract the scheme + host from a git URL.
|
||||
/// e.g. "https://gitea.example.com/owner/repo.git" -> "https://gitea.example.com"
|
||||
/// e.g. "ssh://git@gitea.example.com:22/owner/repo.git" -> "https://gitea.example.com"
|
||||
@@ -1535,6 +1612,39 @@ mod tests {
|
||||
Artifact, ArtifactAuth, IssueTrackerConfig, TargetType, TrackerType,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn a_code_target_plans_the_code_stages_in_order() {
|
||||
let mut target = OnboardedTarget::new("fw".to_string(), TargetType::FirmwareRtos);
|
||||
target.artifacts.push(Artifact::source_archive("fw.zip"));
|
||||
let config = AgentConfig::default();
|
||||
|
||||
let phases = planned_phases(&target, &build_scan_plan(&target), &config);
|
||||
|
||||
assert_eq!(phases.first(), Some(&ScanPhase::Classification));
|
||||
assert_eq!(phases.get(1), Some(&ScanPhase::Sast));
|
||||
assert_eq!(phases.last(), Some(&ScanPhase::IssueCreation));
|
||||
assert!(!phases.contains(&ScanPhase::PlcAnalysis));
|
||||
assert_eq!(
|
||||
phases.contains(&ScanPhase::GroundedControlChecks),
|
||||
config.breakpilot.grounded_control_checks
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_plc_target_plans_the_control_logic_analysis_instead() {
|
||||
let mut target = OnboardedTarget::new("plc".to_string(), TargetType::PlcSps);
|
||||
target.artifacts.push(Artifact::plc_project(
|
||||
"pump.st",
|
||||
compliance_core::models::PlcFormat::StructuredText,
|
||||
));
|
||||
let mut config = AgentConfig::default();
|
||||
config.plc_runtime.enabled = false;
|
||||
|
||||
let phases = planned_phases(&target, &build_scan_plan(&target), &config);
|
||||
|
||||
assert_eq!(phases, [ScanPhase::Classification, ScanPhase::PlcAnalysis]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repo_view_preserves_id_git_auth_and_tracker() {
|
||||
let mut target = OnboardedTarget::new("acme".to_string(), TargetType::WebApp);
|
||||
|
||||
@@ -127,6 +127,11 @@ pub struct ScanRun {
|
||||
/// rules covers one of them. Empty in runs from before it was recorded.
|
||||
#[serde(default)]
|
||||
pub languages: Vec<String>,
|
||||
/// The phases this run will go through, in order, recorded when it starts,
|
||||
/// so the dashboard can show what is done and what is still to come. Empty
|
||||
/// in runs from before it was recorded.
|
||||
#[serde(default)]
|
||||
pub planned_phases: Vec<ScanPhase>,
|
||||
}
|
||||
|
||||
/// A pipeline stage that was planned but intentionally not executed.
|
||||
@@ -211,6 +216,7 @@ impl ScanRun {
|
||||
completed_at: None,
|
||||
skipped_stages: Vec::new(),
|
||||
languages: Vec::new(),
|
||||
planned_phases: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4011,3 +4011,115 @@ tbody tr:last-child td {
|
||||
.copyable code, .copyable .mono { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.code-snippet-wrapper { position: relative; }
|
||||
.code-snippet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; gap: 8px; }
|
||||
|
||||
/* ── Scan progress: stepper and reveal ── */
|
||||
.scan-stepper {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.scan-progress {
|
||||
height: 4px;
|
||||
background: var(--border);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.scan-progress-fill {
|
||||
height: 100%;
|
||||
background: var(--accent);
|
||||
transition: width 0.6s ease;
|
||||
}
|
||||
|
||||
.scan-steps-count {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11px;
|
||||
color: var(--text-faint);
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.scan-steps {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.scan-step {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--border);
|
||||
font-size: 12px;
|
||||
transition: background 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
.scan-step.done {
|
||||
color: var(--success);
|
||||
border-color: color-mix(in oklch, var(--success) 40%, var(--border));
|
||||
}
|
||||
|
||||
.scan-step.current {
|
||||
color: var(--accent);
|
||||
border-color: var(--accent);
|
||||
background: var(--accent-muted);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.scan-step.pending {
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.scan-step-spinner {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
.run-reveal {
|
||||
margin: 4px 0 10px 13px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.run-reveal-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.run-reveal-count {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.run-reveal-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.run-reveal-item {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
padding: 3px 0;
|
||||
opacity: 0;
|
||||
animation: reveal-in 0.4s ease forwards;
|
||||
}
|
||||
|
||||
@keyframes reveal-in {
|
||||
from { opacity: 0; transform: translateY(4px); }
|
||||
to { opacity: 1; transform: none; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.run-reveal-item {
|
||||
animation: none;
|
||||
opacity: 1;
|
||||
}
|
||||
.scan-progress-fill {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
//! A target's scan history: status, the step a running scan is at, when it
|
||||
//! started and finished, why it failed, and which stages it did not run.
|
||||
//!
|
||||
//! A running scan shows its planned stages as a stepper with the elapsed
|
||||
//! time; one that finishes while the page is open reveals what it found.
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use compliance_core::models::{ScanPhase, ScanRun, ScanRunStatus};
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::i18n::texts::{common, scans};
|
||||
use crate::i18n::{format_time, use_lang, Lang, Text};
|
||||
use crate::infrastructure::scans::fetch_target_scan_runs;
|
||||
use crate::infrastructure::scans::{fetch_run_findings, fetch_target_scan_runs};
|
||||
|
||||
/// How many of a finished run's findings the reveal lists.
|
||||
const REVEAL_LIMIT: u32 = 6;
|
||||
|
||||
/// How often the history refreshes while a scan is running, in milliseconds.
|
||||
#[cfg(feature = "web")]
|
||||
@@ -23,6 +32,23 @@ pub fn ScanRunList(target_id: String) -> Element {
|
||||
// Only the browser build restarts it (the polling below).
|
||||
#[cfg_attr(not(feature = "web"), allow(unused_mut))]
|
||||
let mut runs = use_resource(move || async move { fetch_target_scan_runs(id()).await.ok() });
|
||||
// Runs seen running, and those that finished while this page was open:
|
||||
// only those are revealed, not every run in the history.
|
||||
let mut seen_running = use_signal(HashSet::<String>::new);
|
||||
let mut finished_here = use_signal(HashSet::<String>::new);
|
||||
use_effect(move || {
|
||||
let Some(Some(list)) = runs.read().clone() else {
|
||||
return;
|
||||
};
|
||||
for run in &list {
|
||||
let id = run.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
if run.status == ScanRunStatus::Running {
|
||||
seen_running.write().insert(id);
|
||||
} else if seen_running.peek().contains(&id) && !finished_here.peek().contains(&id) {
|
||||
finished_here.write().insert(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
use_future(move || async move {
|
||||
// Only the browser polls; a server render must not leave a loop behind.
|
||||
@@ -52,6 +78,20 @@ pub fn ScanRunList(target_id: String) -> Element {
|
||||
Some(Some(list)) => rsx! {
|
||||
for run in list.iter() {
|
||||
{scan_run_card(run, lang)}
|
||||
{
|
||||
let run_id = run.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
let reveal = run.status == ScanRunStatus::Completed
|
||||
&& finished_here.read().contains(&run_id);
|
||||
rsx! {
|
||||
if reveal {
|
||||
RunReveal {
|
||||
target_id: target_id.clone(),
|
||||
run_id,
|
||||
count: run.new_findings_count,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Some(None) => rsx! {
|
||||
@@ -86,12 +126,16 @@ fn scan_run_card(run: &ScanRun, lang: Lang) -> Element {
|
||||
span { style: "font-size: 0.9em;",
|
||||
{scans::PHASE.get(lang)} ": " strong { {phase(&run.current_phase).get(lang)} }
|
||||
}
|
||||
Elapsed { started_at: run.started_at }
|
||||
} else {
|
||||
span { style: "font-size: 0.9em;",
|
||||
{scans::NEW_FINDINGS.get(lang)} ": {run.new_findings_count}"
|
||||
}
|
||||
}
|
||||
}
|
||||
if running {
|
||||
{stepper(run, lang)}
|
||||
}
|
||||
if run.status == ScanRunStatus::Interrupted {
|
||||
div { style: "font-size: 0.85em; opacity: 0.8; margin-top: 4px;",
|
||||
{scans::INTERRUPTED_HINT.get(lang)}
|
||||
@@ -119,6 +163,141 @@ fn scan_run_card(run: &ScanRun, lang: Lang) -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where one planned phase of a running scan stands.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum StepState {
|
||||
Done,
|
||||
Current,
|
||||
Pending,
|
||||
}
|
||||
|
||||
/// The planned phases of `run` with their state. A run from before phases
|
||||
/// were planned shows the ones it has reached.
|
||||
fn steps(run: &ScanRun) -> Vec<(ScanPhase, StepState)> {
|
||||
let planned = if run.planned_phases.is_empty() {
|
||||
&run.phases_completed
|
||||
} else {
|
||||
&run.planned_phases
|
||||
};
|
||||
planned
|
||||
.iter()
|
||||
.map(|p| {
|
||||
// `phases_completed` gains a phase as it starts, so the current
|
||||
// one is in it too.
|
||||
let state = if *p == run.current_phase {
|
||||
StepState::Current
|
||||
} else if run.phases_completed.contains(p) {
|
||||
StepState::Done
|
||||
} else {
|
||||
StepState::Pending
|
||||
};
|
||||
(p.clone(), state)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A running scan's stepper: a progress bar and its phases.
|
||||
fn stepper(run: &ScanRun, lang: Lang) -> Element {
|
||||
let steps = steps(run);
|
||||
let done = steps.iter().filter(|(_, s)| *s == StepState::Done).count();
|
||||
let total = steps.len().max(1);
|
||||
let percent = done * 100 / total;
|
||||
rsx! {
|
||||
div { class: "scan-stepper",
|
||||
div { class: "scan-progress",
|
||||
div { class: "scan-progress-fill", style: "width: {percent}%;" }
|
||||
}
|
||||
div { class: "scan-steps-count", "{scans::STEPS_DONE.get(lang)}: {done} / {steps.len()}" }
|
||||
div { class: "scan-steps",
|
||||
for (p, state) in steps {
|
||||
span {
|
||||
class: match state {
|
||||
StepState::Done => "scan-step done",
|
||||
StepState::Current => "scan-step current",
|
||||
StepState::Pending => "scan-step pending",
|
||||
},
|
||||
if state == StepState::Current {
|
||||
span { class: "spinner scan-step-spinner" }
|
||||
}
|
||||
{phase(&p).get(lang)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How long a running scan has been going, ticking each second in the
|
||||
/// browser (a server render shows the time at render).
|
||||
#[component]
|
||||
fn Elapsed(started_at: chrono::DateTime<chrono::Utc>) -> Element {
|
||||
let lang = use_lang()();
|
||||
#[cfg_attr(not(feature = "web"), allow(unused_mut))]
|
||||
let mut now = use_signal(chrono::Utc::now);
|
||||
use_future(move || async move {
|
||||
#[cfg(feature = "web")]
|
||||
loop {
|
||||
gloo_timers::future::TimeoutFuture::new(1_000).await;
|
||||
now.set(chrono::Utc::now());
|
||||
}
|
||||
});
|
||||
let secs = (now() - started_at).num_seconds().max(0);
|
||||
rsx! {
|
||||
span { style: "font-size: 0.9em; font-variant-numeric: tabular-nums;",
|
||||
"{scans::ELAPSED.get(lang)}: {secs / 60}:{secs % 60:02}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A scan that just finished: its new-findings count rises to `count`, and
|
||||
/// its first findings appear one after another.
|
||||
#[component]
|
||||
fn RunReveal(target_id: String, run_id: String, count: u32) -> Element {
|
||||
let lang = use_lang()();
|
||||
let ids = use_signal(|| (target_id.clone(), run_id.clone()));
|
||||
let found = use_resource(move || async move {
|
||||
let (target, run) = ids();
|
||||
fetch_run_findings(target, run, REVEAL_LIMIT)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
});
|
||||
#[cfg_attr(not(feature = "web"), allow(unused_mut))]
|
||||
let mut shown = use_signal(|| if cfg!(feature = "web") { 0 } else { count });
|
||||
use_future(move || async move {
|
||||
#[cfg(feature = "web")]
|
||||
while shown() < count {
|
||||
gloo_timers::future::TimeoutFuture::new(40).await;
|
||||
// Rise in about 25 steps, whatever the count.
|
||||
let step = (count / 25).max(1);
|
||||
shown.set((shown() + step).min(count));
|
||||
}
|
||||
});
|
||||
rsx! {
|
||||
div { class: "run-reveal",
|
||||
div { class: "run-reveal-head",
|
||||
span { class: "badge badge-success", {scans::JUST_FINISHED.get(lang)} }
|
||||
span { class: "run-reveal-count", "{shown}" }
|
||||
span { {scans::NEW_FINDINGS.get(lang)} }
|
||||
}
|
||||
if let Some(list) = found() {
|
||||
ul { class: "run-reveal-list",
|
||||
for (i, f) in list.into_iter().enumerate() {
|
||||
li { class: "run-reveal-item", style: "animation-delay: {i * 180}ms;",
|
||||
span { class: "badge badge-{f.severity}", "{f.severity}" }
|
||||
Link { to: Route::FindingDetailPage { id: f.id }, "{f.title}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Link {
|
||||
to: Route::FindingsPage { target: target_id.clone() },
|
||||
class: "btn btn-secondary btn-sm",
|
||||
{scans::SHOW_FINDINGS.get(lang)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The badge class and label for a run status.
|
||||
pub fn status_badge(status: &ScanRunStatus) -> (&'static str, Text) {
|
||||
match status {
|
||||
@@ -175,6 +354,32 @@ pub fn phase(phase: &ScanPhase) -> Text {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_stepper_marks_done_current_and_pending_phases() {
|
||||
let mut run = ScanRun::new("t".into(), compliance_core::models::ScanTrigger::Manual);
|
||||
run.planned_phases = vec![
|
||||
ScanPhase::Classification,
|
||||
ScanPhase::Sast,
|
||||
ScanPhase::SbomGeneration,
|
||||
];
|
||||
// `update_phase` records a phase as completed when it starts.
|
||||
run.phases_completed = vec![ScanPhase::Classification, ScanPhase::Sast];
|
||||
run.current_phase = ScanPhase::Sast;
|
||||
|
||||
assert_eq!(
|
||||
steps(&run),
|
||||
[
|
||||
(ScanPhase::Classification, StepState::Done),
|
||||
(ScanPhase::Sast, StepState::Current),
|
||||
(ScanPhase::SbomGeneration, StepState::Pending),
|
||||
]
|
||||
);
|
||||
|
||||
// A run from before phases were planned shows what it reached.
|
||||
run.planned_phases.clear();
|
||||
assert_eq!(steps(&run).len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_stages_are_shown_by_id() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -247,6 +247,24 @@ pub mod overview {
|
||||
pub mod scans {
|
||||
use super::Text;
|
||||
|
||||
pub const ELAPSED: Text = Text {
|
||||
de: "Laufzeit",
|
||||
en: "Elapsed",
|
||||
};
|
||||
/// Followed by "3 / 12".
|
||||
pub const STEPS_DONE: Text = Text {
|
||||
de: "Schritte erledigt",
|
||||
en: "Steps done",
|
||||
};
|
||||
pub const JUST_FINISHED: Text = Text {
|
||||
de: "Prüfung abgeschlossen",
|
||||
en: "Scan finished",
|
||||
};
|
||||
pub const SHOW_FINDINGS: Text = Text {
|
||||
de: "Alle Befunde ansehen",
|
||||
en: "Show all findings",
|
||||
};
|
||||
|
||||
pub const HISTORY: Text = Text {
|
||||
de: "Prüfverlauf",
|
||||
en: "Scan history",
|
||||
|
||||
@@ -112,6 +112,14 @@ pub async fn set_archive_password(
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether any of `targets` (as the list endpoint returns them) has a scan
|
||||
/// running, so a page showing them should keep refreshing.
|
||||
pub fn any_scan_running(targets: &[serde_json::Value]) -> bool {
|
||||
targets
|
||||
.iter()
|
||||
.any(|t| t["last_scan"]["status"].as_str() == Some("running"))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct TargetsResponse {
|
||||
pub data: Vec<serde_json::Value>,
|
||||
@@ -520,6 +528,15 @@ mod tests {
|
||||
assert_eq!(ArchivePassword::of(&unlocked), ArchivePassword::Set);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_running_last_scan_keeps_the_page_refreshing() {
|
||||
let idle = serde_json::json!({ "last_scan": { "status": "completed" } });
|
||||
let fresh = serde_json::json!({ "last_scan": null });
|
||||
let busy = serde_json::json!({ "last_scan": { "status": "running" } });
|
||||
assert!(!any_scan_running(&[idle.clone(), fresh.clone()]));
|
||||
assert!(any_scan_running(&[idle, fresh, busy]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_token_is_sent_only_when_it_changes() {
|
||||
let kept = ArtifactInputDto {
|
||||
|
||||
@@ -40,3 +40,43 @@ pub async fn fetch_target_scan_runs(target_id: String) -> Result<Vec<ScanRun>, S
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
Ok(body.data)
|
||||
}
|
||||
|
||||
/// A finding a scan run found first, as the run's reveal shows it.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct RunFinding {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub severity: String,
|
||||
}
|
||||
|
||||
/// The first findings (at most `limit`) a scan run of `target_id` found.
|
||||
#[server]
|
||||
pub async fn fetch_run_findings(
|
||||
target_id: String,
|
||||
scan_run_id: String,
|
||||
limit: u32,
|
||||
) -> Result<Vec<RunFinding>, ServerFnError> {
|
||||
let resp = super::agent_client::agent_get(&format!(
|
||||
"/api/v1/findings?repo_id={target_id}&scan_run_id={scan_run_id}&page=1&limit={limit}"
|
||||
))
|
||||
.await?
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
let body: serde_json::Value = resp
|
||||
.json()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
Ok(body["data"]
|
||||
.as_array()
|
||||
.map(|list| {
|
||||
list.iter()
|
||||
.map(|f| RunFinding {
|
||||
id: f["_id"]["$oid"].as_str().unwrap_or_default().to_string(),
|
||||
title: f["title"].as_str().unwrap_or_default().to_string(),
|
||||
severity: f["severity"].as_str().unwrap_or_default().to_string(),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default())
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// How often the list refreshes while a scan is running, in milliseconds.
|
||||
#[cfg(feature = "web")]
|
||||
const REFRESH_MS: u32 = 10_000;
|
||||
use dioxus_free_icons::icons::bs_icons::*;
|
||||
use dioxus_free_icons::Icon;
|
||||
|
||||
@@ -25,7 +29,8 @@ pub fn FindingsPage(target: String) -> Element {
|
||||
let mut sort_order = use_signal(|| "desc".to_string());
|
||||
let mut selected_ids = use_signal(Vec::<String>::new);
|
||||
|
||||
let repos = use_resource(|| async {
|
||||
#[cfg_attr(not(feature = "web"), allow(unused_mut))]
|
||||
let mut repos = use_resource(|| async {
|
||||
crate::infrastructure::onboarding::fetch_targets()
|
||||
.await
|
||||
.ok()
|
||||
@@ -49,6 +54,27 @@ pub fn FindingsPage(target: String) -> Element {
|
||||
}
|
||||
});
|
||||
|
||||
// New findings arrive while a scan runs: refresh the list then. The target
|
||||
// list says whether one runs; it is re-read now and then to notice a scan
|
||||
// that starts while this page is open (the browser only).
|
||||
use_future(move || async move {
|
||||
#[cfg(feature = "web")]
|
||||
for tick in 1_u32.. {
|
||||
gloo_timers::future::TimeoutFuture::new(REFRESH_MS).await;
|
||||
let running = repos
|
||||
.peek()
|
||||
.as_ref()
|
||||
.and_then(|r| r.as_ref())
|
||||
.is_some_and(|r| crate::infrastructure::onboarding::any_scan_running(&r.data));
|
||||
if running {
|
||||
findings.restart();
|
||||
}
|
||||
if running || tick % 3 == 0 {
|
||||
repos.restart();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let toggle_sort = move |field: &'static str| {
|
||||
move |_: MouseEvent| {
|
||||
if sort_by() == field {
|
||||
|
||||
@@ -25,6 +25,10 @@ use crate::infrastructure::platform::{stage_tone, use_source_only, SourceOnlyNot
|
||||
|
||||
/// The last scan's badge class and label (with the step a running scan is
|
||||
/// at), or `None` before the first scan.
|
||||
/// How often the list refreshes while a scan is running, in milliseconds.
|
||||
#[cfg(feature = "web")]
|
||||
const REFRESH_MS: u32 = 5_000;
|
||||
|
||||
fn last_scan_label(target: &serde_json::Value, lang: Lang) -> Option<(&'static str, String)> {
|
||||
let run = target.get("last_scan").filter(|r| !r.is_null())?;
|
||||
let run: compliance_core::models::ScanRun = serde_json::from_value(run.clone()).ok()?;
|
||||
@@ -132,6 +136,22 @@ pub fn TargetsPage() -> Element {
|
||||
|
||||
let mut targets = use_resource(move || async move { fetch_targets().await.ok() });
|
||||
let lang = use_lang()();
|
||||
// While a scan runs, its status and finding count change: keep the list
|
||||
// current without a reload (the browser only).
|
||||
use_future(move || async move {
|
||||
#[cfg(feature = "web")]
|
||||
loop {
|
||||
gloo_timers::future::TimeoutFuture::new(REFRESH_MS).await;
|
||||
let running = targets
|
||||
.peek()
|
||||
.as_ref()
|
||||
.and_then(|t| t.as_ref())
|
||||
.is_some_and(|t| crate::infrastructure::onboarding::any_scan_running(&t.data));
|
||||
if running {
|
||||
targets.restart();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rsx! {
|
||||
PageHeader {
|
||||
|
||||
Reference in new issue
Block a user