Skip to content

Commit

Permalink
For components in an SBOM that have no explicitly defined relationshi…
Browse files Browse the repository at this point in the history
…ps we now set an implied relationship in analysis graph.
  • Loading branch information
JimFuller-RedHat committed Nov 21, 2024
1 parent 66c20fd commit 31d5465
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 59 deletions.
2 changes: 2 additions & 0 deletions entity/src/relationship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub enum Relationship {
DescribedBy,
#[sea_orm(num_value = 14)]
PackageOf,
#[sea_orm(num_value = 15)]
Undefined,
}

impl fmt::Display for Relationship {
Expand Down
10 changes: 9 additions & 1 deletion modules/analysis/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ mod test {
);
assert_eq!(
response["items"][0]["deps"][0]["purl"],
"pkg:rpm/redhat/[email protected]?arch=src"
);
assert_eq!(
response["items"][0]["deps"][1]["purl"],
"pkg:rpm/redhat/[email protected]"
);

Expand All @@ -344,6 +348,10 @@ mod test {
);
assert_eq!(
response["items"][0]["deps"][0]["purl"],
"pkg:rpm/redhat/[email protected]?arch=src"
);
assert_eq!(
response["items"][0]["deps"][1]["purl"],
"pkg:rpm/redhat/[email protected]"
);

Expand Down Expand Up @@ -429,7 +437,7 @@ mod test {
let uri = format!("/api/v1/analysis/root-component?q=sbom_id={}", sbom_id);
let request: Request = TestRequest::get().uri(uri.clone().as_str()).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(&response["total"], 7);
assert_eq!(&response["total"], 8);

// negative test
let uri = "/api/v1/analysis/root-component?q=sbom_id=urn:uuid:99999999-9999-9999-9999-999999999999";
Expand Down
6 changes: 6 additions & 0 deletions modules/analysis/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl fmt::Display for PackageNode {
pub struct AncNode {
pub sbom_id: String,
pub node_id: String,
pub relationship: String,
pub purl: String,
pub name: String,
pub version: String,
Expand Down Expand Up @@ -141,6 +142,11 @@ impl GraphMap {
self.map.get(key)
}

// Retrieve all sbom ids(read access)
pub fn sbom_ids(&self) -> Vec<String> {
self.map.keys().cloned().collect()
}

// Get the singleton instance of GraphMap
pub fn get_instance() -> Arc<RwLock<GraphMap>> {
G.get_or_init(|| Arc::new(RwLock::new(GraphMap::new())))
Expand Down
Loading

0 comments on commit 31d5465

Please sign in to comment.