Skip to content

Commit

Permalink
fix: use the serial of cyclonedx as uid, but it's optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Oct 24, 2023
1 parent 828b8c5 commit 61b5fd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions bombastic/index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ impl Index {
let mut document = doc!();

document.add_text(self.fields.sbom_id, id);
if let Some(serial) = &bom.serial_number {
document.add_text(self.fields.sbom_uid, serial.to_string());
}
document.add_date(
self.fields.indexed_timestamp,
DateTime::from_utc(OffsetDateTime::now_utc()),
Expand Down Expand Up @@ -518,7 +521,10 @@ impl trustification_index::Index for Index {
) -> Result<Self::MatchedDocument, SearchError> {
let doc = searcher.doc(doc_address)?;
let id = field2str(&self.schema, &doc, self.fields.sbom_id)?;
let uid = field2str(&self.schema, &doc, self.fields.sbom_uid)?;
let uid = doc
.get_first(self.fields.sbom_uid)
.and_then(|s| s.as_text())
.map(ToString::to_string);
let name = field2str(&self.schema, &doc, self.fields.sbom_name)?;

let snippet_generator = SnippetGenerator::create(searcher, query, self.fields.sbom.desc)?;
Expand Down Expand Up @@ -581,7 +587,7 @@ impl trustification_index::Index for Index {
let dependencies: u64 = doc.get_all(self.fields.dep.purl).count() as u64;
let document = SearchDocument {
id: id.to_string(),
uid: uid.to_string(),
uid,
version: version.to_string(),
file_sha256: file_sha256.to_string(),
purl,
Expand Down
2 changes: 1 addition & 1 deletion bombastic/model/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct SearchDocument {
/// SBOM (storage) identifier
pub id: String,
/// SBOM unique identifier
pub uid: String,
pub uid: Option<String>,
/// SBOM package name
pub name: String,
/// SBOM package version
Expand Down

0 comments on commit 61b5fd7

Please sign in to comment.