Skip to content

Commit 4d0bd0c

Browse files
committed
TC-1842 CycloneDX CPE management
Signed-off-by: mrizzi <[email protected]>
1 parent 18910f4 commit 4d0bd0c

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

bombastic/index/src/sbom/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ impl Index {
334334
});
335335
}
336336

337+
if let Some(cpe) = &component.cpe {
338+
document.add_text(fields.cpe, cpe);
339+
};
340+
337341
document.add_text(fields.classifier, component.component_type.to_string());
338342
}
339343

@@ -791,8 +795,16 @@ mod tests {
791795
let result = search(&index, "ubi9-containe in:package");
792796
assert_eq!(result.0.len(), 1);
793797

798+
// SPDX CPE
794799
let result = search(&index, "\"cpe:/a:redhat:kernel_module_management:1.0::el9\" in:package");
795800
assert_eq!(result.0.len(), 1);
801+
802+
// CycloneDX CPE
803+
let result = search(
804+
&index,
805+
"\"cpe:/o:io.seedwing:seedwing-java-example:1.0.0-SNAPSHOT::\" in:package",
806+
);
807+
assert_eq!(result.0.len(), 1);
796808
});
797809
}
798810

bombastic/testdata/my-sbom.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"licenses" : [ ],
5454
"purl" : "pkg:maven/io.seedwing/[email protected]?type=jar",
5555
"type" : "library",
56-
"bom-ref" : "pkg:maven/io.seedwing/[email protected]?type=jar"
56+
"bom-ref" : "pkg:maven/io.seedwing/[email protected]?type=jar",
57+
"cpe": "cpe:/o:io.seedwing:seedwing-java-example:1.0.0-SNAPSHOT::"
5758
}
5859
},
5960
"components" : [
@@ -7296,4 +7297,5 @@
72967297
]
72977298
}
72987299
]
7299-
}
7300+
}
7301+

spog/ui/crates/components/src/cyclonedx/mod.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
mod packages;
22

3+
use std::collections::BTreeMap;
34
use std::rc::Rc;
45

56
pub use packages::*;
67

78
use patternfly_yew::prelude::*;
89
use serde_json::Value;
10+
use spog_ui_common::utils::OrNone;
911
use yew::prelude::*;
1012

1113
#[derive(PartialEq, Properties)]
@@ -71,3 +73,56 @@ pub fn cyclonedx_creator(bom: &cyclonedx_bom::prelude::Bom) -> Html {
7173
</Card>
7274
)
7375
}
76+
77+
pub fn cyclonedx_main(bom: &cyclonedx_bom::prelude::Bom) -> Html {
78+
match bom.metadata.as_ref() {
79+
Some(metadata) => match metadata.component.as_ref() {
80+
Some(component) => {
81+
html!(
82+
<Card>
83+
<CardTitle><Title size={Size::XLarge}>{ "Package" }</Title></CardTitle>
84+
<CardBody>
85+
<DescriptionList>
86+
<DescriptionGroup term="Name">{ component.name.to_string() }</DescriptionGroup>
87+
<DescriptionGroup term="Version">{ OrNone(component.version.as_ref()) }</DescriptionGroup>
88+
<DescriptionGroup term="Type">{ component.component_type.to_string() }</DescriptionGroup>
89+
<DescriptionGroup term="External References"> { cyclonedx_external_references(component)} </DescriptionGroup>
90+
</DescriptionList>
91+
</CardBody>
92+
</Card>
93+
)
94+
}
95+
None => html!(),
96+
},
97+
None => html!(),
98+
}
99+
}
100+
101+
pub fn cyclonedx_external_references(component: &cyclonedx_bom::prelude::Component) -> Html {
102+
let mut external_references = BTreeMap::new();
103+
// since in SPDX SBOM both CPE and PURL are listed in the external references
104+
// for UX conistency among the UI, they are managed in the same way in Cyclone SBOM
105+
if let Some(cpe) = component.cpe.as_ref() {
106+
external_references.insert(cpe.to_string(), "CPE".to_string());
107+
}
108+
if let Some(purl) = component.purl.as_ref() {
109+
external_references.insert(purl.to_string(), "PURL".to_string());
110+
}
111+
if let Some(ext_refs) = component.external_references.as_ref() {
112+
ext_refs.0.iter().for_each(|e| {
113+
external_references.insert(e.url.to_string(), e.external_reference_type.to_string());
114+
})
115+
}
116+
html!(
117+
<List>
118+
{ for external_references.iter()
119+
.map(|(value, label)| {
120+
html_nested!( <ListItem>
121+
{&value} { " " }
122+
<Label label={format!("{}", label)} color={Color::Grey} />
123+
</ListItem> )
124+
})
125+
}
126+
</List>
127+
)
128+
}

spog/ui/src/pages/sbom/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ fn details(props: &DetailsProps) -> Html {
258258
</GridItem>
259259
</Grid>
260260
</StackItem>
261+
<StackItem>
262+
<Grid gutter=true>
263+
<GridItem cols={[12]}>{cyclonedx_main(bom)}</GridItem>
264+
</Grid>
265+
</StackItem>
261266
</Stack>
262267
</PageSection>
263268

0 commit comments

Comments
 (0)