Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
16 changes: 8 additions & 8 deletions internal/formats/common/spdxhelpers/originator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_Originator(t *testing.T) {
},
},
},
expected: "auth1",
expected: "Person: auth1",
},
{
name: "from npm",
Expand All @@ -38,7 +38,7 @@ func Test_Originator(t *testing.T) {
Author: "auth",
},
},
expected: "auth",
expected: "Person: auth",
},
{
name: "from apk",
Expand All @@ -47,7 +47,7 @@ func Test_Originator(t *testing.T) {
Maintainer: "auth",
},
},
expected: "auth",
expected: "Person: auth",
},
{
name: "from python - just name",
Expand All @@ -56,7 +56,7 @@ func Test_Originator(t *testing.T) {
Author: "auth",
},
},
expected: "auth",
expected: "Person: auth",
},
{
name: "from python - just email",
Expand All @@ -65,7 +65,7 @@ func Test_Originator(t *testing.T) {
AuthorEmail: "[email protected]",
},
},
expected: "[email protected]",
expected: "Person: [email protected]",
},
{
name: "from python - both name and email",
Expand All @@ -75,7 +75,7 @@ func Test_Originator(t *testing.T) {
AuthorEmail: "[email protected]",
},
},
expected: "auth <[email protected]>",
expected: "Person: auth ([email protected])",
},
{
name: "from rpm",
Expand All @@ -84,7 +84,7 @@ func Test_Originator(t *testing.T) {
Vendor: "auth",
},
},
expected: "auth",
expected: "Organization: auth",
},
{
name: "from dpkg",
Expand All @@ -93,7 +93,7 @@ func Test_Originator(t *testing.T) {
Maintainer: "auth",
},
},
expected: "auth",
expected: "Person: auth",
},
{
// note: since this is an optional field, no value is preferred over NONE or NOASSERTION
Expand Down
28 changes: 16 additions & 12 deletions internal/formats/common/spdxhelpers/origintor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,35 @@ import (
"github.com/anchore/syft/syft/pkg"
)

// Originator needs to conform to the SPDX spec here:
// https://spdx.github.io/spdx-spec/package-information/#76-package-originator-field
// Available options are: <omit>, NOASSERTION, Person: <person>, Organization: <org>
func Originator(p pkg.Package) string {
if hasMetadata(p) {
author := ""
switch metadata := p.Metadata.(type) {
case pkg.ApkMetadata:
return metadata.Maintainer
author = metadata.Maintainer
case pkg.NpmPackageJSONMetadata:
return metadata.Author
author = metadata.Author
case pkg.PythonPackageMetadata:
author := metadata.Author
author = metadata.Author
if author == "" {
return metadata.AuthorEmail
author = metadata.AuthorEmail
} else if metadata.AuthorEmail != "" {
author = fmt.Sprintf("%s (%s)", author, metadata.AuthorEmail)
}
if metadata.AuthorEmail != "" {
author += fmt.Sprintf(" <%s>", metadata.AuthorEmail)
}
return author
case pkg.GemMetadata:
if len(metadata.Authors) > 0 {
return metadata.Authors[0]
author = metadata.Authors[0]
}
return ""
case pkg.RpmdbMetadata:
return metadata.Vendor
return "Organization: " + metadata.Vendor
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this also be Person: ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we won't be able to tell 100% of the time (org is a good guess)

case pkg.DpkgMetadata:
return metadata.Maintainer
author = metadata.Maintainer
}
if author != "" {
return "Person: " + author
}
}
return ""
Expand Down
2 changes: 1 addition & 1 deletion internal/formats/spdx22json/model/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package model
type Element struct {
SPDXID string `json:"SPDXID"`
// Identify name of this SpdxElement.
Name string `json:"name"`
Name string `json:"name,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this will have other adverse effects since it is used by things such as spdx22json.Package .Item.Element but not allowed in spdx22json.File, something like this is needed.

// Relationships referenced in the SPDX document
Relationships []Relationship `json:"relationships,omitempty"`
// Provide additional information about an SpdxElement.
Expand Down
8 changes: 3 additions & 5 deletions internal/formats/spdx22json/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spdx22json

import (
"fmt"
"path/filepath"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -131,8 +130,7 @@ func toFiles(s sbom.SBOM) []model.File {
results = append(results, model.File{
Item: model.Item{
Element: model.Element{
SPDXID: string(coordinates.ID()),
Name: filepath.Base(coordinates.RealPath),
SPDXID: model.ElementID(coordinates.ID()).String(),
Comment: comment,
},
// required, no attempt made to determine license information
Expand Down Expand Up @@ -206,9 +204,9 @@ func toRelationships(relationships []artifact.Relationship) (result []model.Rela
}

result = append(result, model.Relationship{
SpdxElementID: string(r.From.ID()),
SpdxElementID: model.ElementID(r.From.ID()).String(),
RelationshipType: relationshipType,
RelatedSpdxElement: string(r.To.ID()),
RelatedSpdxElement: model.ElementID(r.To.ID()).String(),
Comment: comment,
})
}
Expand Down