Skip to content

Commit

Permalink
refactor: look for SBOM ref only for Os and App layers
Browse files Browse the repository at this point in the history
  • Loading branch information
afdesk committed Aug 30, 2024
1 parent 6067d5f commit 0a5090f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/sbom/io/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ func (e *Encoder) encodePackages(parent *core.Component, result types.Result) {
}
}

// existedPkgIdentifier tries to look for package identifier (BOM-ref, PURL) by component name and component type
func (e *Encoder) existedPkgIdentifier(name string, componentType core.ComponentType) ftypes.PkgIdentifier {
for _, c := range e.components {
if c.Name == name && c.Type == componentType {
return c.PkgIdentifier
}
}
return ftypes.PkgIdentifier{}
}

func (e *Encoder) resultComponent(root *core.Component, r types.Result, osFound *ftypes.OS) *core.Component {
component := &core.Component{
Name: r.Target,
Expand All @@ -284,16 +294,10 @@ func (e *Encoder) resultComponent(root *core.Component, r types.Result, osFound
component.Version = osFound.Name
}
component.Type = core.TypeOS
component.PkgIdentifier = e.existedPkgIdentifier(component.Name, component.Type)
case types.ClassLangPkg:
component.Type = core.TypeApplication
}

// try to look for BOM-ref for this component
for _, c := range e.components {
if c.Name == component.Name && c.Type == component.Type {
component.PkgIdentifier = c.PkgIdentifier
break
}
component.PkgIdentifier = e.existedPkgIdentifier(component.Name, component.Type)
}

e.bom.AddRelationship(root, component, core.RelationshipContains)
Expand Down

0 comments on commit 0a5090f

Please sign in to comment.