-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(sbom): use PURL or Group and Name in case of Java #5154
Changes from 1 commit
80378ef
fa8b37d
d38ade7
e3c0b9a
14d3f02
9d841d4
cce80e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |||||
"io" | ||||||
"sort" | ||||||
"strconv" | ||||||
"strings" | ||||||
|
||||||
"github.com/aquasecurity/trivy/pkg/sbom/cyclonedx/core" | ||||||
|
||||||
|
@@ -410,8 +411,26 @@ func toTrivyCdxComponent(component cdx.Component) ftypes.Component { | |||||
|
||||||
func getPackageName(typ string, component cdx.Component) string { | ||||||
// Jar uses `Group` field for `GroupID` | ||||||
if typ == packageurl.TypeMaven && component.Group != "" { | ||||||
return fmt.Sprintf("%s:%s", component.Group, component.Name) | ||||||
if typ == packageurl.TypeMaven { | ||||||
return convertMavenPackage(component.PackageURL) | ||||||
} | ||||||
return component.Name | ||||||
} | ||||||
|
||||||
func convertMavenPackage(pkg string) string { | ||||||
// Split the package into its parts | ||||||
parts := strings.Split(pkg, "/") | ||||||
|
||||||
// Get Group | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this comment? It almost duplicates the variable name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! Done. |
||||||
group := parts[1] | ||||||
|
||||||
// Get FullName with Version | ||||||
nameWithVersion := parts[len(parts)-1] | ||||||
|
||||||
// Remove the Version from the package | ||||||
nameWOVersion := strings.Split(nameWithVersion, "@")[0] | ||||||
|
||||||
pkgWithoutVersion := fmt.Sprintf("%s:%s", group, nameWOVersion) | ||||||
|
||||||
return pkgWithoutVersion | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks again :) Done |
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Done.