From 869093b4d699837fcfaf3f9674aed94bc85bb4ea Mon Sep 17 00:00:00 2001 From: DJ Schleen Date: Wed, 9 Oct 2024 01:55:33 +0000 Subject: [PATCH] Update launch.json and main.rs - 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. --- .vscode/launch.json | 3 ++- src/main.rs | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0faed30..c594485 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -90,7 +90,7 @@ { "type": "lldb", "request": "launch", - "name": "Debug executable 'trustier' (juiceshop)", + "name": "Debug executable 'trustier' --strict (juiceshop)", "cargo": { "args": [ "build", @@ -103,6 +103,7 @@ } }, "args": [ + "--strict", "./tests/_TESTDATA_/juiceshop.cyclonedx.json" ], "cwd": "${workspaceFolder}" diff --git a/src/main.rs b/src/main.rs index 3047939..e613cc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(), @@ -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?; @@ -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);