From 61b5fd76e7b14f3d6f9d7d1f168d1290634e3e74 Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Tue, 24 Oct 2023 15:58:33 +0200 Subject: [PATCH] fix: use the serial of cyclonedx as uid, but it's optional --- bombastic/index/src/lib.rs | 10 ++++++++-- bombastic/model/src/search.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bombastic/index/src/lib.rs b/bombastic/index/src/lib.rs index dce703717..d0108adaf 100644 --- a/bombastic/index/src/lib.rs +++ b/bombastic/index/src/lib.rs @@ -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()), @@ -518,7 +521,10 @@ impl trustification_index::Index for Index { ) -> Result { 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)?; @@ -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, diff --git a/bombastic/model/src/search.rs b/bombastic/model/src/search.rs index 7da4c6cd3..fbc260e3b 100644 --- a/bombastic/model/src/search.rs +++ b/bombastic/model/src/search.rs @@ -58,7 +58,7 @@ pub struct SearchDocument { /// SBOM (storage) identifier pub id: String, /// SBOM unique identifier - pub uid: String, + pub uid: Option, /// SBOM package name pub name: String, /// SBOM package version