Skip to content

Commit 614d963

Browse files
committed
carve out cpe
Signed-off-by: djcrabhat <djcrabhat@sosimplerecords.com>
1 parent 12be30a commit 614d963

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/AlpineSBomGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Bom generateSBom()
6666
detailMap = produceDetailMap(software);
6767
version = getVersion(software);
6868
component = createComponents(software, detailMap, null, null,
69-
version, null, null);
69+
version, null, null, null);
7070
bom.addComponent(addPackageManager(component, PACKAGE_MANAGER));
7171
}
7272
return bom;

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/RedHatSBomGenerator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public Bom generateSBom() {
7979
LicenseChoice license = null;
8080
PackageURL purl = null;
8181
Component component = null;
82+
String cpe = null;
8283
for (String software : softwareList) {
8384
if (logger.isDebugEnabled())
8485
logger.debug("Generating Component (" + software + ")");
@@ -94,6 +95,7 @@ public Bom generateSBom() {
9495
} catch (MalformedPackageURLException e) {
9596
logger.debug("Can't get purl", e);
9697
}
98+
cpe = getCpe(software, version);
9799

98100
try {
99101
String downloadUrl = getPackageDownloadUrl(software);
@@ -104,12 +106,17 @@ public Bom generateSBom() {
104106
logger.debug("Error getting Download-Url", e);
105107
}
106108
component = createComponents(software, detailMap, license, group,
107-
version, purl, detailMap.get("Priority"));
109+
version, purl, detailMap.get("Priority"), cpe);
108110
bom.addComponent(addPackageManager(component, PACKAGE_MANAGER));
109111
}
110112
return bom;
111113
}
112114

115+
private String getCpe(String software, String version) {
116+
// TODO
117+
return null;
118+
}
119+
113120
/**
114121
* (U) This method is used to attempt to figure out which file is the license file. If any.
115122
*

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/SBomGenerator.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ public static void createBomFile(Bom bom, SBomCommons.AVAILABLE_FORMATS format)
145145
* imageUrl provided.
146146
*/
147147
public static Component createMasterComponent(String imageUrl, String name,
148-
String group, String version) throws SBomException
148+
String group, String version, String cpe) throws SBomException
149149
{
150150
Component master = null;
151151
if ((StringUtils.isValid(imageUrl)) ||
152152
(StringUtils.isValid(name) && ((StringUtils.isValid(version)))))
153153
{
154-
master = createMasterComponent(imageUrl);
154+
master = createMasterComponent(imageUrl,name,group,version, imageUrl ,cpe);
155155

156156
if (StringUtils.isValid(imageUrl))
157157
{
@@ -175,8 +175,9 @@ public static Component createMasterComponent(String imageUrl, String name,
175175
}
176176
}else{
177177
master.setType(Component.Type.OPERATING_SYSTEM);
178-
// TODO: should we set the CPE reported by hostnamectl here?
179-
//master.setCpe();
178+
if(StringUtils.isValid(cpe)){
179+
master.setCpe(cpe);
180+
}
180181
}
181182
if (StringUtils.isValid(name))
182183
master.setName(name.toLowerCase());
@@ -310,7 +311,7 @@ private static Component createMasterComponent(CommandLine cli) throws SBomExcep
310311
cpe = osUtils.getOsCpe();
311312
}
312313

313-
master = createMasterComponent(imageUrl, name, group, version);
314+
master = createMasterComponent(imageUrl, name, group, version, cpe);
314315

315316
return master;
316317
}
@@ -319,12 +320,17 @@ private static Component createMasterComponent(CommandLine cli) throws SBomExcep
319320
* (U) This method is used to create the master component. It will then fill in
320321
* the image information (if provided).
321322
*
323+
*
324+
* @param url
325+
* @param name
326+
* @param group
327+
* @param version
322328
* @param imageUrl String value of where to get the docker image from.
323329
* @return Component created, and filled in if the imageUrl is provided.
324330
* @throws SBomException in the event we are unable to pull the image via the
325331
* image URL provided.
326332
*/
327-
private static Component createMasterComponent(String imageUrl) throws SBomException
333+
private static Component createMasterComponent(String url, String name, String group, String version, String imageUrl, String cpe) throws SBomException
328334
{
329335
Component master = new Component();
330336
master.setType(org.cyclonedx.model.Component.Type.CONTAINER);

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/UbuntuSBomGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Bom generateSBom()
7171
group = detailMap.get("Release");
7272
license = processLicense(software);
7373
component = createComponents(software, detailMap, license, group,
74-
version, null, detailMap.get("Priority"));
74+
version, null, detailMap.get("Priority"), null);
7575
bom.addComponent(addPackageManager(component, PACKAGE_MANAGER));
7676
}
7777

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/UnixSBomGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ else if (priority.equalsIgnoreCase("optional"))
129129
* @param version String value to set the version to.
130130
* @param purl String to set the URL used to pull the software from.
131131
* @param scope String value to help us set the scope of the software.
132+
* @param cpe String value for cpe, if relevant
132133
* @return Component Sbom Component created from the supplied inputs.
133134
*/
134135
public Component createComponents(String software, Map<String, String> detailMap,
135-
LicenseChoice license, String group, String version, PackageURL purl, String scope)
136+
LicenseChoice license, String group, String version, PackageURL purl, String scope, String cpe)
136137
{
137138
Component component = new Component();
138139
component.setType(Type.OPERATING_SYSTEM);
@@ -146,6 +147,9 @@ public Component createComponents(String software, Map<String, String> detailMap
146147
if(purl!=null) {
147148
component.setPurl(purl);
148149
}
150+
if(cpe!=null){
151+
component.setCpe(cpe);
152+
}
149153
component.setScope(buildScope(scope));
150154
component.setVersion(version);
151155

src/test/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/UnixSBomGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void createComponentsTest()
137137
String version = detailMap.get("Version");
138138
String group = detailMap.get("Release");
139139
Component component = generator.createComponents("zip",
140-
detailMap, null, group, version, null, detailMap.get("Priority"));
140+
detailMap, null, group, version, null, detailMap.get("Priority"), null);
141141

142142
String actualComponentName = component.getName();
143143
String actualComponentVerison = component.getVersion();

0 commit comments

Comments
 (0)