Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: purl of components in sbom sometimes shows [Object Object] #42

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/cyclone_dx_sbom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {PackageURL} from "packageurl-js";

/**
*
* @param component {PackageURL}
Expand All @@ -7,25 +9,32 @@
*/
function getComponent(component,type) {
let componentObject;
if(component.namespace) {
componentObject = {
"group": component.namespace,
"name": component.name,
"version": component.version,
"purl": component.toString(),
"type": type,
"bom-ref": component.toString()
if(component instanceof PackageURL)
{
if(component.namespace) {
componentObject = {
"group": component.namespace,
"name": component.name,
"version": component.version,
"purl": component.toString(),
"type": type,
"bom-ref": component.toString()
}
}
else
{
componentObject = {
"name": component.name,
"version": component.version,
"purl": component.toString(),
"type": type,
"bom-ref": component.toString()
}
}
}
else
{
componentObject = {
"name": component.name,
"version": component.version,
"purl": component.toString(),
"type": type,
"bom-ref": component.toString()
}
componentObject = component
}
return componentObject
}
Expand Down Expand Up @@ -76,7 +85,7 @@ export default class CycloneDxSbom {
}

/**
* @param {Component} sourceRef current target Component ( Starting from root component by clients)
* @param {component} sourceRef current target Component ( Starting from root component by clients)
* @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
* @return Sbom
*/
Expand Down Expand Up @@ -139,7 +148,7 @@ export default class CycloneDxSbom {

/**
*
* @param {Component} theComponent - Component Object with purl field.
* @param {component} theComponent - Component Object with purl field.
* @return {int} index of the found component entry, if not found returns -1.
* @private
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,25 +1191,28 @@
"bom-ref": "pkg:golang/golang.org/x/[email protected]"
},
{
"group": "github.com/kr",
"name": "pretty",
"version": "v0.2.0",
"purl": "[object Object]",
"purl": "pkg:golang/github.com/kr/[email protected]",
"type": "library",
"bom-ref": "[object Object]"
"bom-ref": "pkg:golang/github.com/kr/[email protected]"
},
{
"group": "github.com/stoewer",
"name": "go-strcase",
"version": "v1.2.0",
"purl": "[object Object]",
"purl": "pkg:golang/github.com/stoewer/[email protected]",
"type": "library",
"bom-ref": "[object Object]"
"bom-ref": "pkg:golang/github.com/stoewer/[email protected]"
},
{
"group": "golang.org/x",
"name": "tools",
"version": "v0.0.0-20190524140312-2c0ae7006135",
"purl": "[object Object]",
"purl": "pkg:golang/golang.org/x/[email protected]",
"type": "library",
"bom-ref": "[object Object]"
"bom-ref": "pkg:golang/golang.org/x/[email protected]"
},
{
"group": "golang.org/x",
Expand All @@ -1219,13 +1222,6 @@
"type": "library",
"bom-ref": "pkg:golang/golang.org/x/[email protected]"
},
{
"name": "tools",
"version": "v0.0.0-20190524140312-2c0ae7006135",
"purl": "[object Object]",
"type": "library",
"bom-ref": "[object Object]"
},
{
"group": "golang.org/x",
"name": "sync",
Expand All @@ -1235,11 +1231,12 @@
"bom-ref": "pkg:golang/golang.org/x/[email protected]"
},
{
"group": "google.golang.org",
"name": "genproto",
"version": "v0.0.0-20201019141844-1ed22bb0c154",
"purl": "[object Object]",
"purl": "pkg:golang/google.golang.org/[email protected]",
"type": "library",
"bom-ref": "[object Object]"
"bom-ref": "pkg:golang/google.golang.org/[email protected]"
},
{
"group": "github.com/golang",
Expand All @@ -1249,13 +1246,6 @@
"type": "library",
"bom-ref": "pkg:golang/github.com/golang/[email protected]"
},
{
"name": "genproto",
"version": "v0.0.0-20201019141844-1ed22bb0c154",
"purl": "[object Object]",
"type": "library",
"bom-ref": "[object Object]"
},
{
"group": "golang.org/x",
"name": "lint",
Expand All @@ -1264,28 +1254,6 @@
"type": "library",
"bom-ref": "pkg:golang/golang.org/x/[email protected]"
},
{
"name": "genproto",
"version": "v0.0.0-20201019141844-1ed22bb0c154",
"purl": "[object Object]",
"type": "library",
"bom-ref": "[object Object]"
},
{
"group": "golang.org/x",
"name": "tools",
"version": "v0.0.0-20190524140312-2c0ae7006135",
"purl": "pkg:golang/golang.org/x/[email protected]",
"type": "library",
"bom-ref": "pkg:golang/golang.org/x/[email protected]"
},
{
"name": "genproto",
"version": "v0.0.0-20201019141844-1ed22bb0c154",
"purl": "[object Object]",
"type": "library",
"bom-ref": "[object Object]"
},
{
"group": "google.golang.org",
"name": "grpc",
Expand All @@ -1294,13 +1262,6 @@
"type": "library",
"bom-ref": "pkg:golang/google.golang.org/[email protected]"
},
{
"name": "genproto",
"version": "v0.0.0-20201019141844-1ed22bb0c154",
"purl": "[object Object]",
"type": "library",
"bom-ref": "[object Object]"
},
{
"group": "google.golang.org",
"name": "protobuf",
Expand Down
Loading