Skip to content

Commit

Permalink
feat: reimplament vulnerability endpoint logic and api so we can retr…
Browse files Browse the repository at this point in the history
…ieve purls for affected sboms
  • Loading branch information
dejanb committed Dec 13, 2024
1 parent c4a3768 commit 7c2c140
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 397 deletions.
6 changes: 6 additions & 0 deletions entity/src/package_relates_to_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pub enum Relation {
to = "super::sbom::Column::SbomId"
)]
Sbom,
#[sea_orm(
belongs_to = "super::sbom_package::Entity",
from = "(Column::SbomId, Column::LeftNodeId)",
to = "(super::sbom_package::Column::SbomId, super::sbom_package::Column::NodeId)"
)]
LeftPackage,
}

impl ActiveModelBehavior for ActiveModel {}
Expand Down
6 changes: 6 additions & 0 deletions entity/src/product_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pub enum Relation {
to = "super::cpe::Column::Id"
)]
ContextCpe,

#[sea_orm(belongs_to = "super::base_purl::Entity",
from = "Column::Package"
to = "super::base_purl::Column::Name"
)]
BasePurl,
}

impl Related<super::product_version_range::Entity> for Entity {
Expand Down
6 changes: 6 additions & 0 deletions entity/src/sbom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub enum Relation {
PackageRelatesToPackages,
#[sea_orm(has_one = "super::product_version::Entity")]
ProductVersion,
#[sea_orm(
belongs_to = "super::sbom_node::Entity",
from = "(Column::NodeId, Column::SbomId)",
to = "(super::sbom_node::Column::NodeId, super::sbom_node::Column::SbomId)"
)]
SbomNode,
}

pub struct SbomPurlsLink;
Expand Down
13 changes: 13 additions & 0 deletions entity/src/sbom_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ pub enum Relation {
to = "(super::sbom::Column::NodeId, super::sbom::Column::SbomId)"
)]
SbomNode,
#[sea_orm(
belongs_to = "super::package_relates_to_package::Entity",
from = "Column::SbomId",
to = "super::package_relates_to_package::Column::SbomId",
on_condition = r#"super::package_relates_to_package::Column::Relationship.eq(13)"#
)]
DescribesSbom,
}

impl Related<super::sbom_package::Entity> for Entity {
Expand All @@ -57,4 +64,10 @@ impl Related<super::sbom::Entity> for Entity {
}
}

impl Related<super::package_relates_to_package::Entity> for Entity {
fn to() -> RelationDef {
Relation::DescribesSbom.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
6 changes: 3 additions & 3 deletions modules/fundamental/src/purl/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use utoipa::ToSchema;
pub mod details;
pub mod summary;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema, Hash)]
pub struct BasePurlHead {
/// The ID of the base PURL
pub uuid: Uuid,
Expand Down Expand Up @@ -44,7 +44,7 @@ impl BasePurlHead {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema, Hash)]
pub struct VersionedPurlHead {
/// The ID of the versioned PURL
pub uuid: Uuid,
Expand Down Expand Up @@ -74,7 +74,7 @@ impl VersionedPurlHead {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema, Hash)]
pub struct PurlHead {
/// The ID of the qualified PURL
pub uuid: Uuid,
Expand Down
2 changes: 1 addition & 1 deletion modules/fundamental/src/purl/model/summary/purl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::BTreeMap;
use trustify_entity::{base_purl, qualified_purl, versioned_purl};
use utoipa::ToSchema;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, ToSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, ToSchema, Hash)]
pub struct PurlSummary {
#[serde(flatten)]
pub head: PurlHead,
Expand Down
Loading

0 comments on commit 7c2c140

Please sign in to comment.