Skip to content

Commit

Permalink
refactor: remove mod.rs files
Browse files Browse the repository at this point in the history
Signed-off-by: Flavio Castelli <[email protected]>
  • Loading branch information
flavio committed Nov 21, 2024
1 parent 3031d3b commit 0f22089
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ pub enum ImageValidationError {
MalformedImageName(String),

#[error("Failed to parse the SARIF report: {0}")]
SarifParseError(String),
SarifParse(String),
}
2 changes: 1 addition & 1 deletion src/sarif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Report {
always_allowed: &HashSet<String>,
) -> Result<Self, ImageValidationError> {
if trivy_report.runs.len() != 1 {
return Err(ImageValidationError::SarifParseError(format!(
return Err(ImageValidationError::SarifParse(format!(
"wrong number of 'run' items inside of trivy report, expected 1 got {}",
trivy_report.runs.len()
)));
Expand Down
17 changes: 8 additions & 9 deletions src/sarif/trivy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ impl TryFrom<VulnerabilityReport> for Report {
type Error = ImageValidationError;

fn try_from(sbombastic_vulnerability_report: VulnerabilityReport) -> Result<Self, Self::Error> {
let spec =
sbombastic_vulnerability_report
.spec
.ok_or(ImageValidationError::SarifParseError(
"missing VulnerabilityReportSpec".to_string(),
))?;
let spec = sbombastic_vulnerability_report
.spec
.ok_or(ImageValidationError::SarifParse(
"missing VulnerabilityReportSpec".to_string(),
))?;

let report = serde_json::from_value::<Self>(spec.sarif)
.map_err(|e| ImageValidationError::SarifParseError(e.to_string()))?;
.map_err(|e| ImageValidationError::SarifParse(e.to_string()))?;

if report.runs.len() != 1 {
return Err(ImageValidationError::SarifParseError(format!(
return Err(ImageValidationError::SarifParse(format!(
"wrong number of 'run' items inside of trivy report, expected 1 got {}",
report.runs.len()
)));
}

if report.runs[0].tool.driver.name != "Trivy" {
return Err(ImageValidationError::SarifParseError(format!(
return Err(ImageValidationError::SarifParse(format!(
"wrong tool driver name inside of trivy report, expected 'Trivy' got '{}'",
report.runs[0].tool.driver.name
)));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0f22089

Please sign in to comment.