fix(scan): "Prüfung starten" always scans, and a skipped scan says why (#419)
This commit was merged in pull request #419.
This commit is contained in:
1 parent
420ce241cd
commit
6fe7874ccd
3 files changed
+44
-5
No files matched your search
@@ -69,7 +69,12 @@ impl PipelineOrchestrator {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(repo_id = repo.name.as_str()))]
|
||||
async fn run_pipeline(&self, repo: &RepoView, scan_run_id: &str) -> Result<u32, AgentError> {
|
||||
async fn run_pipeline(
|
||||
&self,
|
||||
repo: &RepoView,
|
||||
scan_run_id: &str,
|
||||
trigger: &ScanTrigger,
|
||||
) -> Result<u32, AgentError> {
|
||||
let repo_id = repo.id.as_ref().map(|id| id.to_hex()).unwrap_or_default();
|
||||
|
||||
// Stage 0: Change detection
|
||||
@@ -83,8 +88,22 @@ impl PipelineOrchestrator {
|
||||
);
|
||||
let repo_path = git_ops.clone_or_fetch(&repo.git_url, &repo.name)?;
|
||||
|
||||
if !GitOps::has_new_commits(&repo_path, repo.last_scanned_commit.as_deref())? {
|
||||
// A scheduled or webhook scan of an unchanged repository has nothing
|
||||
// new to find; one a person started always runs (after an update of
|
||||
// Prüfwerk itself, or a changed setting, it can find something else).
|
||||
if *trigger != ScanTrigger::Manual
|
||||
&& !GitOps::has_new_commits(&repo_path, repo.last_scanned_commit.as_deref())?
|
||||
{
|
||||
tracing::info!("[{repo_id}] No new commits, skipping scan");
|
||||
self.skip_stage(
|
||||
scan_run_id,
|
||||
SkippedStage::new(
|
||||
"change_detection",
|
||||
SkipCode::NoNewCommits,
|
||||
"no new commits since the last scan",
|
||||
),
|
||||
)
|
||||
.await;
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
@@ -584,7 +603,7 @@ impl PipelineOrchestrator {
|
||||
.await?
|
||||
.ok_or_else(|| AgentError::Other(format!("Onboarded target {target_id} not found")))?;
|
||||
|
||||
let scan_run = ScanRun::new(target_id.to_string(), trigger);
|
||||
let scan_run = ScanRun::new(target_id.to_string(), trigger.clone());
|
||||
let insert = self.db.scan_runs().insert_one(&scan_run).await?;
|
||||
let scan_run_id = insert
|
||||
.inserted_id
|
||||
@@ -592,7 +611,9 @@ impl PipelineOrchestrator {
|
||||
.map(|id| id.to_hex())
|
||||
.unwrap_or_default();
|
||||
|
||||
let result = self.run_target_pipeline(&target, &scan_run_id).await;
|
||||
let result = self
|
||||
.run_target_pipeline(&target, &scan_run_id, &trigger)
|
||||
.await;
|
||||
match &result {
|
||||
Ok(count) => {
|
||||
self.db
|
||||
@@ -655,6 +676,7 @@ impl PipelineOrchestrator {
|
||||
&self,
|
||||
target: &OnboardedTarget,
|
||||
scan_run_id: &str,
|
||||
trigger: &ScanTrigger,
|
||||
) -> Result<u32, AgentError> {
|
||||
let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
let plan = build_scan_plan(target);
|
||||
@@ -737,7 +759,7 @@ impl PipelineOrchestrator {
|
||||
match target.code_artifact() {
|
||||
Some(code) if code.kind == ArtifactKind::GitRepo => {
|
||||
let repo = RepoView::from_target(target, code, &self.secrets);
|
||||
let n = self.run_pipeline(&repo, scan_run_id).await?;
|
||||
let n = self.run_pipeline(&repo, scan_run_id, trigger).await?;
|
||||
self.finalize_target(target, &repo, n).await?;
|
||||
new_count += n;
|
||||
self.dast_after_code_scan(&target_id, &plan, scan_run_id)
|
||||
|
||||
@@ -181,6 +181,9 @@ pub enum SkipCode {
|
||||
/// Some components were not matched against known vulnerabilities;
|
||||
/// `subject` names the lookup, and the components where known.
|
||||
CveLookupIncomplete,
|
||||
/// A scheduled or webhook scan found no new commits since the last scan,
|
||||
/// so nothing was scanned again.
|
||||
NoNewCommits,
|
||||
}
|
||||
|
||||
/// Why a scan run failed, stable for the dashboard to word.
|
||||
|
||||
@@ -387,6 +387,10 @@ pub mod scans {
|
||||
/// this dashboard does not know yet; it is then shown as it is.
|
||||
pub fn stage(id: &str) -> Option<Text> {
|
||||
let text = match id {
|
||||
"change_detection" => Text {
|
||||
de: "Änderungserkennung",
|
||||
en: "Change detection",
|
||||
},
|
||||
"ingest" => Text {
|
||||
de: "Einlesen der Dateien",
|
||||
en: "Reading the upload",
|
||||
@@ -554,6 +558,16 @@ pub mod scans {
|
||||
),
|
||||
(SkipCode::CveLookupIncomplete, Lang::De) => format!("Nicht abgeglichen: {subject}"),
|
||||
(SkipCode::CveLookupIncomplete, Lang::En) => format!("Not matched: {subject}"),
|
||||
(SkipCode::NoNewCommits, Lang::De) => {
|
||||
"Keine neuen Commits seit der letzten Prüfung, daher nicht erneut geprüft. \
|
||||
„Prüfung starten“ prüft trotzdem vollständig."
|
||||
.into()
|
||||
}
|
||||
(SkipCode::NoNewCommits, Lang::En) => {
|
||||
"No new commits since the last scan, so it was not scanned again. \
|
||||
\"Run scan\" always scans in full."
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user