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(sbom): use PURL or Group and Name in case of Java #5154

Merged
merged 7 commits into from
Oct 3, 2023
Merged
Changes from 1 commit
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
23 changes: 21 additions & 2 deletions pkg/sbom/cyclonedx/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"sort"
"strconv"
"strings"

"github.com/aquasecurity/trivy/pkg/sbom/cyclonedx/core"

Expand Down Expand Up @@ -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`
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this comment? It almost duplicates the variable name

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return pkgWithoutVersion
return fmt.Sprintf("%s:%s", group, nameWOVersion)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again :) Done

}