Skip to content

Commit

Permalink
Update launch.json and main.rs
Browse files Browse the repository at this point in the history
- Update launch.json to include the "--strict" flag for debugging the executable 'trustier' in the juiceshop.
- Modify main.rs to improve error handling and logging when parsing SBOM.
- Enable strict SBOM checking and print validation results.
- Add conditional printing for SBOM validity and when there is nothing to do.
  • Loading branch information
djschleen authored Oct 9, 2024
1 parent 5f3710d commit 869093b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'trustier' (juiceshop)",
"name": "Debug executable 'trustier' --strict (juiceshop)",
"cargo": {
"args": [
"build",
Expand All @@ -103,6 +103,7 @@
}
},
"args": [
"--strict",
"./tests/_TESTDATA_/juiceshop.cyclonedx.json"
],
"cwd": "${workspaceFolder}"
Expand Down
19 changes: 12 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ fn main() {
let bom = match Bom::parse_from_json_v1_5(file_contents) {
Ok(bom) => bom,
Err(e) => {
eprintln!("Error parsing SBOM: {}", e);
eprintln!("* Error parsing SBOM! \n\n{}", e);
return;
}
};

if args.strict && !bom.validate().passed() {
eprintln!("* Provided input is not a valid SBOM");
return;
if args.strict {
conditional_println!(args.sbom.is_file(), "* strict SBOM checking enabled...");
if !bom.validate().passed() {
eprintln!("* Provided input is not a valid SBOM");
return;
} else {
conditional_println!(args.sbom.is_file(), "* SBOM is valid");
}
}

conditional_println!(args.sbom.is_file(), "* SBOM is valid");
if let Some(serial_number) = &bom.serial_number {
conditional_println!(
args.sbom.is_file(),
Expand Down Expand Up @@ -145,7 +149,8 @@ async fn process_sbom(
collected_purls.len()
);
} else {
conditional_println!(args.sbom.is_file(), "* Nothing to do...\n")
conditional_println!(args.sbom.is_file(), "* Nothing to do...\n");
return Ok(());
}

let responses = fetch_purl_bodies(&collected_purls, args.ratelimit).await?;
Expand All @@ -160,7 +165,7 @@ async fn process_sbom(
}
}
fs::write(of_clone, json).expect("Failed to write JSON to file");
conditional_println!(args.sbom.is_file(), "\n* JSON written to file: {}\n", of);
conditional_println!(args.sbom.is_file(), "* JSON written to file: {}\n", of);
} else {
let json = serde_json::to_string_pretty(&responses).unwrap();
println!("{}", json);
Expand Down

0 comments on commit 869093b

Please sign in to comment.