Skip to content

Commit

Permalink
refactor: move sbom parsing into the loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Dec 5, 2024
1 parent cf4aa9a commit 464de8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
10 changes: 4 additions & 6 deletions modules/ingestor/src/graph/sbom/cyclonedx.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::graph::sbom::{LicenseCreator, LicenseInfo};
use crate::graph::{
cpe::CpeCreator,
product::ProductInformation,
purl::creator::PurlCreator,
sbom::{PackageCreator, PackageReference, RelationshipCreator, SbomContext, SbomInformation},
};
use cyclonedx_bom::{
models::license::{LicenseChoice, LicenseIdentifier},
prelude::{Bom, Component, Components},
sbom::{
LicenseCreator, LicenseInfo, PackageCreator, PackageReference, RelationshipCreator,
SbomContext, SbomInformation,
},
};
use sea_orm::ConnectionTrait;
use std::{collections::HashMap, str::FromStr};
Expand Down
5 changes: 1 addition & 4 deletions modules/ingestor/src/service/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
};
use csaf::Csaf;
use cve::Cve;
use cyclonedx_bom::models::bom::Bom;
use jsn::{mask::*, Format as JsnFormat, TokenReader};
use osv::schema::Vulnerability;
use quick_xml::{events::Event, Reader};
Expand Down Expand Up @@ -80,10 +79,8 @@ impl<'g> Format {
Format::CycloneDX => {
let loader = CyclonedxLoader::new(graph);
let v: Value = serde_json::from_slice(buffer)?;
let sbom = Bom::parse_json_value(v)
.map_err(|err| Error::UnsupportedFormat(format!("Failed to parse: {err}")))?;

loader.load(labels, sbom, digests).await
loader.load(labels, v, digests).await
}
Format::ClearlyDefined => {
let loader = ClearlyDefinedLoader::new(graph);
Expand Down
8 changes: 6 additions & 2 deletions modules/ingestor/src/service/sbom/cyclonedx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
};
use cyclonedx_bom::prelude::Bom;
use sea_orm::TransactionTrait;
use serde_json::Value;
use tracing::instrument;
use trustify_common::{hashing::Digests, id::Id};
use trustify_entity::labels::Labels;
Expand All @@ -18,13 +19,16 @@ impl<'g> CyclonedxLoader<'g> {
Self { graph }
}

#[instrument(skip(self, sbom), ret)]
#[instrument(skip(self, value), ret)]
pub async fn load(
&self,
labels: Labels,
sbom: Bom,
value: Value,
digests: &Digests,
) -> Result<IngestResult, Error> {
let sbom = Bom::parse_json_value(value)
.map_err(|err| Error::UnsupportedFormat(format!("Failed to parse: {err}")))?;

let labels = labels.add("type", "cyclonedx");

log::info!(
Expand Down

0 comments on commit 464de8e

Please sign in to comment.