Skip to content

Commit

Permalink
remove old relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
JimFuller-RedHat committed Jan 30, 2025
1 parent 19cca70 commit 56d0bc2
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 101 deletions.
56 changes: 14 additions & 42 deletions entity/src/relationship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,36 @@ use std::fmt;
// When adding a new variant, also add this to the "relationship" table.
pub enum Relationship {
#[sea_orm(num_value = 0)]
ContainedBy,
Contains,
#[sea_orm(num_value = 1)]
DependencyOf,
Dependency,
#[sea_orm(num_value = 2)]
DevDependencyOf,
DevDependency,
#[sea_orm(num_value = 3)]
OptionalDependencyOf,
OptionalDependency,
#[sea_orm(num_value = 4)]
ProvidedDependencyOf,
ProvidedDependency,
#[sea_orm(num_value = 5)]
TestDependencyOf,
TestDependency,
#[sea_orm(num_value = 6)]
RuntimeDependencyOf,
RuntimeDependency,
#[sea_orm(num_value = 7)]
ExampleOf,
Example,
#[sea_orm(num_value = 8)]
GeneratedFrom,
Generates,
#[sea_orm(num_value = 9)]
AncestorOf,
#[sea_orm(num_value = 10)]
VariantOf,
Variant,
#[sea_orm(num_value = 11)]
BuildToolOf,
BuildTool,
#[sea_orm(num_value = 12)]
DevToolOf,
DevTool,
#[sea_orm(num_value = 13)]
DescribedBy,
Describes,
#[sea_orm(num_value = 14)]
PackageOf,
Package,
#[sea_orm(num_value = 15)]
Contains,
#[sea_orm(num_value = 16)]
Dependency,
#[sea_orm(num_value = 17)]
DevDependency,
#[sea_orm(num_value = 18)]
OptionalDependency,
#[sea_orm(num_value = 19)]
ProvidedDependency,
#[sea_orm(num_value = 20)]
TestDependency,
#[sea_orm(num_value = 21)]
RuntimeDependency,
#[sea_orm(num_value = 22)]
Example,
#[sea_orm(num_value = 23)]
Generates,
#[sea_orm(num_value = 24)]
Variant,
#[sea_orm(num_value = 25)]
BuildTool,
#[sea_orm(num_value = 26)]
DevTool,
#[sea_orm(num_value = 27)]
Describes,
#[sea_orm(num_value = 28)]
Packages,
#[sea_orm(num_value = 29)]
Undefined,
}

Expand Down
28 changes: 14 additions & 14 deletions migration/src/m0000860_normalise_relationships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
const DATA: [(i32, &str); 14] = [
(16, "Contains"),
(17, "Dependency"),
(18, "DevDependency"),
(19, "OptionalDependency"),
(20, "ProvidedDependency"),
(21, "TestDependency"),
(22, "RuntimeDependency"),
(23, "Example"),
(24, "Generates"),
(25, "Variant"),
(26, "BuildTool"),
(27, "DevTool"),
(28, "Describes"),
(29, "Packages"),
(0, "Contains"),
(1, "Dependency"),
(2, "DevDependency"),
(3, "OptionalDependency"),
(4, "ProvidedDependency"),
(5, "TestDependency"),
(6, "RuntimeDependency"),
(7, "Example"),
(8, "Generates"),
(10, "Variant"),
(11, "BuildTool"),
(12, "DevTool"),
(13, "Describes"),
(14, "Packages"),
];

#[async_trait::async_trait]
Expand Down
18 changes: 9 additions & 9 deletions modules/analysis/src/model/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod test {
relationship: None,
ancestors: Some(vec![Node {
ancestors: Some(vec![]),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
..node("A")
}]),
descendants: None,
Expand All @@ -142,7 +142,7 @@ mod test {
result,
vec![Node {
base: base("A"),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
ancestors: Some(vec![]),
descendants: None,
}]
Expand All @@ -154,10 +154,10 @@ mod test {
let result = vec![Node {
ancestors: Some(vec![Node {
base: base("AA"),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
ancestors: Some(vec![Node {
ancestors: Some(vec![]),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
..node("A")
}]),
descendants: None,
Expand All @@ -170,7 +170,7 @@ mod test {
result,
vec![Node {
base: base("A"),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
ancestors: Some(vec![]),
descendants: None,
}]
Expand All @@ -182,10 +182,10 @@ mod test {
let result = vec![Node {
ancestors: Some(vec![Node {
base: base("AA"),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
ancestors: Some(vec![Node {
ancestors: Some(vec![]),
relationship: Some(Relationship::DependencyOf),
relationship: Some(Relationship::Dependency), // TODO: Is this right ?
..node("A")
}]),
descendants: None,
Expand All @@ -197,8 +197,8 @@ mod test {
assert_eq!(
result,
vec![vec![
(&base("AA"), Relationship::DependencyOf),
(&base("A"), Relationship::DependencyOf),
(&base("AA"), Relationship::Dependency), // TODO: Is this right ?
(&base("A"), Relationship::Dependency), // TODO: Is this right ?
]]
);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/analysis/src/service/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl AnalysisService {
nodes.get(&edge.left_node_id),
nodes.get(&edge.right_node_id),
) {
if edge.relationship == Relationship::DescribedBy {
if edge.relationship == Relationship::Describes {
describedby_node_id.push(*left);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/fundamental/src/sbom/service/sbom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl SbomService {
paginated,
Which::Right,
SbomNodeReference::All,
Some(Relationship::DescribedBy),
Some(Relationship::Describes), // TODO: Is this right ?
db,
)
.await
Expand Down
51 changes: 27 additions & 24 deletions modules/fundamental/tests/sbom/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ async fn ingest_sboms(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

let sbom_v1 = system
.ingest_sbom(
("source", "http://sbom.com/test.json"),
(
"sour// TODO: Is this right ?ce",
"http://sbom.com/test.json",
),
&Digests::digest("8"),
Some("a".to_string()),
(),
Expand Down Expand Up @@ -208,52 +211,52 @@ async fn transitive_dependency_of(ctx: &TrustifyContext) -> Result<(), anyhow::E

sbom1
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;

sbom1
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;

sbom1
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;

sbom1
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;

sbom1
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;

let _results = sbom1
.related_packages_transitively(
&[Relationship::DependencyOf],
&[Relationship::Dependency],
&"pkg:maven/io.quarkus/[email protected]".try_into()?,
&ctx.db,
)
Expand Down Expand Up @@ -282,9 +285,9 @@ async fn ingest_package_relates_to_package_dependency_of(

sbom1
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;
Expand All @@ -301,17 +304,17 @@ async fn ingest_package_relates_to_package_dependency_of(

sbom2
.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;

let dependencies = fetch
.related_packages(
sbom1.sbom.sbom_id,
Relationship::DependencyOf,
Relationship::Dependency,
"pkg:maven/io.quarkus/[email protected]",
&ctx.db,
)
Expand All @@ -334,7 +337,7 @@ async fn ingest_package_relates_to_package_dependency_of(
let dependencies = fetch
.related_packages(
sbom2.sbom.sbom_id,
Relationship::DependencyOf,
Relationship::Dependency,
"pkg:maven/io.quarkus/[email protected]",
&ctx.db,
)
Expand Down Expand Up @@ -381,27 +384,27 @@ async fn sbom_vulnerabilities(ctx: &TrustifyContext) -> Result<(), anyhow::Error
log::debug!("-------------------- B");

sbom.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:oci/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;
log::debug!("-------------------- C");

sbom.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
&ctx.db,
)
.await?;
log::debug!("-------------------- D");

sbom.ingest_package_relates_to_package(
Purl::from_str("pkg:maven/postgres/[email protected]")?,
Relationship::DependencyOf,
Purl::from_str("pkg:maven/io.quarkus/[email protected]")?,
Relationship::Dependency,
Purl::from_str("pkg:maven/postgres/[email protected]")?,
&ctx.db,
)
.await?;
Expand Down
4 changes: 2 additions & 2 deletions modules/fundamental/tests/sbom/spdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn parse_spdx_quarkus(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
let contains = service
.related_packages(
sbom.sbom.sbom_id,
Relationship::ContainedBy,
Relationship::Contains, // TODO: Is this right ?
first,
&ctx.db,
)
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn test_parse_spdx(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
Default::default(),
Which::Right,
first,
Some(Relationship::ContainedBy),
Some(Relationship::Contains), //TODO: Is this right ?
&ctx.db,
)
.await?
Expand Down
7 changes: 4 additions & 3 deletions modules/ingestor/src/graph/sbom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl SbomContext {
fn query_describes_packages(&self) -> Select<sbom_package::Entity> {
sbom_package::Entity::find()
.filter(sbom::Column::SbomId.eq(self.sbom.sbom_id))
.filter(package_relates_to_package::Column::Relationship.eq(Relationship::DescribedBy))
.filter(package_relates_to_package::Column::Relationship.eq(Relationship::Describes))
.select_only()
.join(JoinType::Join, sbom_package::Relation::Sbom.def())
.join(JoinType::Join, sbom_package::Relation::Node.def())
Expand Down Expand Up @@ -663,7 +663,7 @@ impl SbomContext {
) -> anyhow::Result<()> {
self.ingest_package_relates_to_package(
RelationshipReference::Root,
Relationship::DescribedBy,
Relationship::Describes,
RelationshipReference::Purl(package),
connection,
)
Expand All @@ -678,8 +678,9 @@ impl SbomContext {
connection: &C,
) -> anyhow::Result<()> {
self.ingest_package_relates_to_package(
// TODO: Is this right ?
RelationshipReference::Root,
Relationship::DescribedBy,
Relationship::Describes,
RelationshipReference::Cpe(cpe),
connection,
)
Expand Down
Loading

0 comments on commit 56d0bc2

Please sign in to comment.