Skip to content

Commit

Permalink
add retrieve_all_sbom_roots_by_name() func
Browse files Browse the repository at this point in the history
  • Loading branch information
JimFuller-RedHat committed Nov 22, 2024
1 parent 1e9b3e9 commit 0b61581
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions modules/analysis/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,40 @@ impl AnalysisService {
Ok(paginated.paginate_array(&components))
}

pub async fn retrieve_all_sbom_roots_by_name<TX: AsRef<Transactional>>(
&self,
sbom_id: Uuid,
component_name: String,
tx: TX,
) -> Result<Vec<AncNode>, Error> {
// This function searches for a component(s) by name in a specific sbom, then returns that components
// root components.

let connection = self.db.connection(&tx);
let distinct_sbom_ids = vec![sbom_id.to_string()];
load_graphs(&connection, &distinct_sbom_ids).await;

let components = AnalysisService::query_ancestor_graph::<TX>(
Option::from(component_name),
None,
None,
distinct_sbom_ids,
)
.await;

let mut root_components = Vec::new();
for component in components {
if let Some(last_ancestor) = component.ancestors.last() {
if !root_components.contains(last_ancestor) {
// we want distinct list
root_components.push(last_ancestor.clone());
}
}
}

Ok(root_components)
}

#[instrument(skip(self, tx), err)]
pub async fn retrieve_root_components_by_name<TX: AsRef<Transactional>>(
&self,
Expand Down

0 comments on commit 0b61581

Please sign in to comment.