Skip to content

Commit 401e628

Browse files
Merge pull request #113 from interlynk-io/fix/edit-add-tools
Improved tool edits
2 parents b82d617 + aa017d8 commit 401e628

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

pkg/edit/cdx.go

+26-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"strings"
910

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

184+
if b.SpecVersion > cydx.SpecVersion1_4 {
185+
choice.Components = new([]cydx.Component)
186+
} else {
187+
choice.Tools = new([]cydx.Tool)
188+
}
189+
190+
uniqTools := make(map[string]string)
191+
183192
for _, tool := range c.tools {
184-
if b.SpecVersion > cydx.SpecVersion1_4 {
185-
choice.Components = new([]cydx.Component)
186-
*choice.Components = append(*choice.Components, cydx.Component{
187-
Type: cydx.ComponentTypeApplication,
188-
Name: tool.name,
189-
Version: tool.value,
190-
})
191-
} else {
192-
choice.Tools = new([]cydx.Tool)
193-
*choice.Tools = append(*choice.Tools, cydx.Tool{
194-
Name: tool.name,
195-
Version: tool.value,
196-
})
193+
key := fmt.Sprintf("%s-%s", strings.ToLower(tool.name), strings.ToLower(tool.value))
194+
195+
if _, ok := uniqTools[key]; !ok {
196+
if b.SpecVersion > cydx.SpecVersion1_4 {
197+
*choice.Components = append(*choice.Components, cydx.Component{
198+
Type: cydx.ComponentTypeApplication,
199+
Name: tool.name,
200+
Version: tool.value,
201+
})
202+
} else {
203+
*choice.Tools = append(*choice.Tools, cydx.Tool{
204+
Name: tool.name,
205+
Version: tool.value,
206+
})
207+
}
208+
209+
uniqTools[key] = key
197210
}
198211
}
199212

pkg/edit/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"os"
2121
"regexp"
2222
"strings"
23+
24+
"sigs.k8s.io/release-utils/version"
2325
)
2426

2527
var supportedSubjects map[string]bool = map[string]bool{
@@ -243,6 +245,12 @@ func convertToConfigParams(eParams *EditParams) (*configParams, error) {
243245
})
244246
}
245247

248+
// Always add SBOMASM to the tool list
249+
p.tools = append(p.tools, paramTuple{
250+
name: "sbomasm",
251+
value: version.GetVersionInfo().GitVersion,
252+
})
253+
246254
p.copyright = eParams.CopyRight
247255
p.lifecycles = eParams.Lifecycles
248256
p.description = eParams.Description

pkg/edit/spdx_edit.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,20 @@ func (d *spdxEditDoc) tools() error {
362362
}
363363

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

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

369-
tools = append(tools, spdx.Creator{
370-
CreatorType: "Tool",
371-
Creator: strings.Join(lo.Compact(parts), "-"),
372-
})
371+
if _, ok := uniqTools[key]; !ok {
372+
tools = append(tools, spdx.Creator{
373+
CreatorType: "Tool",
374+
Creator: strings.Join(lo.Compact(parts), "-"),
375+
})
376+
377+
uniqTools[key] = true
378+
}
373379
}
374380

375381
if d.c.onMissing() {

0 commit comments

Comments
 (0)