Skip to content

Commit

Permalink
Fix tools
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshnoronha committed Oct 23, 2024
1 parent b82d617 commit aa017d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
39 changes: 26 additions & 13 deletions pkg/edit/cdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"strings"

cydx "github.com/CycloneDX/cyclonedx-go"
"github.com/google/uuid"
Expand Down Expand Up @@ -180,20 +181,32 @@ func cdxFindComponent(b *cydx.BOM, c *configParams) *cydx.Component {
func cdxConstructTools(b *cydx.BOM, c *configParams) *cydx.ToolsChoice {
choice := cydx.ToolsChoice{}

if b.SpecVersion > cydx.SpecVersion1_4 {
choice.Components = new([]cydx.Component)
} else {
choice.Tools = new([]cydx.Tool)
}

uniqTools := make(map[string]string)

for _, tool := range c.tools {
if b.SpecVersion > cydx.SpecVersion1_4 {
choice.Components = new([]cydx.Component)
*choice.Components = append(*choice.Components, cydx.Component{
Type: cydx.ComponentTypeApplication,
Name: tool.name,
Version: tool.value,
})
} else {
choice.Tools = new([]cydx.Tool)
*choice.Tools = append(*choice.Tools, cydx.Tool{
Name: tool.name,
Version: tool.value,
})
key := fmt.Sprintf("%s-%s", strings.ToLower(tool.name), strings.ToLower(tool.value))

if _, ok := uniqTools[key]; !ok {
if b.SpecVersion > cydx.SpecVersion1_4 {
*choice.Components = append(*choice.Components, cydx.Component{
Type: cydx.ComponentTypeApplication,
Name: tool.name,
Version: tool.value,
})
} else {
*choice.Tools = append(*choice.Tools, cydx.Tool{
Name: tool.name,
Version: tool.value,
})
}

uniqTools[key] = key
}
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/edit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"regexp"
"strings"

"sigs.k8s.io/release-utils/version"
)

var supportedSubjects map[string]bool = map[string]bool{
Expand Down Expand Up @@ -243,6 +245,12 @@ func convertToConfigParams(eParams *EditParams) (*configParams, error) {
})
}

// Always add SBOMASM to the tool list
p.tools = append(p.tools, paramTuple{
name: "sbomasm",
value: version.GetVersionInfo().GitVersion,
})

p.copyright = eParams.CopyRight
p.lifecycles = eParams.Lifecycles
p.description = eParams.Description
Expand Down
14 changes: 10 additions & 4 deletions pkg/edit/spdx_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,20 @@ func (d *spdxEditDoc) tools() error {
}

tools := []spdx.Creator{}
uniqTools := make(map[string]bool)

for _, tool := range d.c.tools {
parts := []string{tool.name, tool.value}
key := fmt.Sprintf("%s-%s", strings.ToLower(tool.name), strings.ToLower(tool.value))

tools = append(tools, spdx.Creator{
CreatorType: "Tool",
Creator: strings.Join(lo.Compact(parts), "-"),
})
if _, ok := uniqTools[key]; !ok {
tools = append(tools, spdx.Creator{
CreatorType: "Tool",
Creator: strings.Join(lo.Compact(parts), "-"),
})

uniqTools[key] = true
}
}

if d.c.onMissing() {
Expand Down

0 comments on commit aa017d8

Please sign in to comment.