Skip to content

Commit

Permalink
fix: actually evaluate the fix flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Sep 29, 2023
1 parent f3e60b2 commit e266541
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions bombastic/walker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl Run {
keys,
provider,
validation_date,
fix_licenses: self.fix_licenses,
});

if let Some(interval) = self.scan_interval {
Expand Down
58 changes: 35 additions & 23 deletions bombastic/walker/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use serde_json::Value;
use std::io::Write;
use walker_common::compression::decompress_opt;

pub struct ProcessVisitor<V>(pub V);
pub struct ProcessVisitor<V> {
/// if processing is enabled
pub enabled: bool,
/// then next visitor to call
pub next: V,
}

#[async_trait(?Send)]
impl<V> ValidatedVisitor for ProcessVisitor<V>
Expand All @@ -20,41 +25,48 @@ where
type Context = V::Context;

async fn visit_context(&self, context: &ValidationContext) -> Result<Self::Context, Self::Error> {
Ok(self.0.visit_context(context).await?)
Ok(self.next.visit_context(context).await?)
}

async fn visit_sbom(
&self,
context: &Self::Context,
result: Result<ValidatedSbom, ValidationError>,
) -> Result<(), Self::Error> {
let sbom = match result {
Ok(doc) => {
log::info!("Processing: {}", doc.url.path());
doc
}
Err(err) => {
log::info!("Failed ({}): {}", err.url().path(), err);
return Ok(());
}
};
match self.enabled {
true => {
let sbom = match result {
Ok(doc) => {
log::info!("Processing: {}", doc.url.path());
doc
}
Err(err) => {
log::info!("Failed ({}): {}", err.url().path(), err);
return Ok(());
}
};

let (outcome, mut sbom) =
tokio::task::spawn_blocking(move || (process(sbom.data.clone(), sbom.url.path()), sbom)).await?;
let (outcome, mut sbom) =
tokio::task::spawn_blocking(move || (process(sbom.data.clone(), sbom.url.path()), sbom)).await?;

match outcome {
Err(err) => log::warn!("Failed to processing, moving on: {err}"),
Ok(Some(data)) => {
log::info!("Got replacement, apply and store");
sbom.data = data;
match outcome {
Err(err) => log::warn!("Failed to processing, moving on: {err}"),
Ok(Some(data)) => {
log::info!("Got replacement, apply and store");
sbom.data = data;
}
Ok(None) => {
// keep current
}
}

self.next.visit_sbom(context, Ok(sbom)).await?;
}
Ok(None) => {
// keep current
false => {
self.next.visit_sbom(context, result).await?;
}
}

self.0.visit_sbom(context, Ok(sbom)).await?;

Ok(())
}
}
Expand Down
6 changes: 5 additions & 1 deletion bombastic/walker/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Options {
pub keys: Vec<Key>,
pub provider: Arc<dyn TokenProvider>,
pub validation_date: Option<SystemTime>,
pub fix_licenses: bool,
}

pub struct Scanner {
Expand Down Expand Up @@ -67,7 +68,10 @@ impl Scanner {
sender,
};

let process = ProcessVisitor(storage);
let process = ProcessVisitor {
enabled: self.options.fix_licenses,
next: storage,
};

let validation = ValidationVisitor::new(process).with_options(ValidationOptions {
validation_date: self.options.validation_date,
Expand Down

0 comments on commit e266541

Please sign in to comment.