Skip to content

Commit

Permalink
Merge pull request #7 from interlynk-io/fix/uniq-checks
Browse files Browse the repository at this point in the history
Use ID for checking unique components. Name can be repetitive
  • Loading branch information
riteshnoronha committed Feb 2, 2023
2 parents 1b06ef7 + a2dea0c commit 6c8c1e7
Show file tree
Hide file tree
Showing 6 changed files with 54,941 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/sbom/cdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (c *cdxDoc) parseComps() {
nc.cpes = []string{sc.CPE}
nc.checksums = c.checksums(index)
nc.licenses = c.licenses(index)
nc.id = sc.BOMRef

c.comps = append(c.comps, nc)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/sbom/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package sbom

type Component interface {
ID() string
SupplierName() string
Name() string
Version() string
Expand Down Expand Up @@ -42,6 +43,7 @@ type component struct {

purpose string
isReqFieldsPresent bool
id string
}

func newComponent() *component {
Expand Down Expand Up @@ -75,3 +77,7 @@ func (c component) PrimaryPurpose() string {
func (c component) RequiredFields() bool {
return c.isReqFieldsPresent
}

func (c component) ID() string {
return c.id
}
1 change: 1 addition & 0 deletions pkg/sbom/spdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (s *spdxDoc) parseComps() {
nc.cpes = s.cpes(index)
nc.checksums = s.checksums(index)
nc.licenses = s.licenses(index)
nc.id = string(sc.PackageSPDXIdentifier)

s.comps = append(s.comps, nc)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/scorer/ntia.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func compWithUniqIDScore(d sbom.Document) score {

withCpe := lo.FilterMap(d.Components(), func(c sbom.Component, _ int) (string, bool) {
if len(c.Cpes()) > 0 {
return c.Name(), true
return c.ID(), true
}
return c.Name(), false
return c.ID(), false
})
withPurl := lo.FilterMap(d.Components(), func(c sbom.Component, _ int) (string, bool) {
if len(c.Purls()) > 0 {
return c.Name(), true
return c.ID(), true
}
return c.Name(), false
return c.ID(), false
})

compWithIDs := append(withCpe, withPurl...)
Expand Down
8 changes: 4 additions & 4 deletions pkg/scorer/quality.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func compWithAllIdScore(d sbom.Document) score {

withCpe := lo.FilterMap(d.Components(), func(c sbom.Component, _ int) (string, bool) {
if len(c.Cpes()) > 0 {
return c.Name(), true
return c.ID(), true
}
return c.Name(), false
return c.ID(), false
})
withPurl := lo.FilterMap(d.Components(), func(c sbom.Component, _ int) (string, bool) {
if len(c.Purls()) > 0 {
return c.Name(), true
return c.ID(), true
}
return c.Name(), false
return c.ID(), false
})

compsWithCPE := len(withCpe)
Expand Down
Loading

0 comments on commit 6c8c1e7

Please sign in to comment.