Skip to content

Commit

Permalink
fix: add missing "number of packages" field
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Nov 6, 2024
1 parent 57006c2 commit 538070a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 12 additions & 9 deletions modules/fundamental/src/sbom/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
pub mod details;

use super::service::SbomService;
use crate::purl::model::summary::purl::PurlSummary;
use crate::source_document::model::SourceDocument;
use crate::Error;
use crate::{
purl::model::summary::purl::PurlSummary, source_document::model::SourceDocument, Error,
};
use async_graphql::SimpleObject;
use sea_orm::prelude::Uuid;
use sea_orm::ModelTrait;
use sea_orm::{prelude::Uuid, ModelTrait, PaginatorTrait};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use trustify_common::db::ConnectionOrTransaction;
use trustify_common::model::Paginated;
use trustify_common::{db::ConnectionOrTransaction, model::Paginated};
use trustify_entity::{
labels::Labels, relationship::Relationship, sbom, sbom_node, source_document,
labels::Labels, relationship::Relationship, sbom, sbom_node, sbom_package, source_document,
};
use utoipa::ToSchema;

Expand Down Expand Up @@ -64,6 +62,9 @@ pub struct SbomSummary {
pub source_document: Option<SourceDocument>,

pub described_by: Vec<SbomPackage>,

/// The number of packages this SBOM has
pub number_of_packages: u64,
}

impl SbomSummary {
Expand All @@ -72,13 +73,14 @@ impl SbomSummary {
service: &SbomService,
tx: &ConnectionOrTransaction<'_>,
) -> Result<Option<SbomSummary>, Error> {
// TODO: consider improving the n-select issue here
// TODO: consider improving the n-select issues here
let described_by = service
.describes_packages(sbom.sbom_id, Paginated::default(), ())
.await?
.items;

let source_document = sbom.find_related(source_document::Entity).one(tx).await?;
let number_of_packages = sbom.find_related(sbom_package::Entity).count(tx).await?;

Ok(match node {
Some(_) => Some(SbomSummary {
Expand All @@ -89,6 +91,7 @@ impl SbomSummary {
None
},
described_by,
number_of_packages,
}),
None => None,
})
Expand Down
12 changes: 12 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3021,11 +3021,17 @@ components:
- type: object
required:
- described_by
- number_of_packages
properties:
described_by:
type: array
items:
$ref: '#/components/schemas/SbomPackage'
number_of_packages:
type: integer
format: int64
description: The number of packages this SBOM has
minimum: 0
total:
type: integer
format: int64
Expand Down Expand Up @@ -3512,11 +3518,17 @@ components:
- type: object
required:
- described_by
- number_of_packages
properties:
described_by:
type: array
items:
$ref: '#/components/schemas/SbomPackage'
number_of_packages:
type: integer
format: int64
description: The number of packages this SBOM has
minimum: 0
Severity:
type: string
description: |-
Expand Down

0 comments on commit 538070a

Please sign in to comment.