Skip to content

Commit 1d6b092

Browse files
authored
Merge pull request #17 from aniruth37/main
feat: introduce min-score parameter as a score threshold
2 parents 64c0c74 + b458cb4 commit 1d6b092

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ Make sure `$GOBIN` is in your path.
1919

2020
Example:
2121
```sh
22-
cdsbom -out enhanced-sbom.json input-sbom.json
22+
cdsbom -min-score 50 -out enhanced-sbom.json input-sbom.json
2323
```
2424

2525
This will read `input-sbom.json` and query ClearlyDefined for License
2626
information. The License fields in the SBOM will be replaced to use the license
27-
data returned from ClearlyDefined. A new sbom will be written to
28-
`enhanced-sbom.json` with the updated fields in the same format as the input
29-
sbom.
27+
data returned from ClearlyDefined (with the Clearly Defined effective score greater than or equal to the **min-score**).
28+
A new sbom will be written to `enhanced-sbom.json` with the updated fields in the same format as the input sbom.
3029

3130
Supported formats are the [same as
3231
Protobom](https://github.com/protobom/protobom/blob/main/README.md#supported-versions-and-formats).

main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
)
2323

2424
func main() {
25-
inFile, outFile := flags()
25+
inFile, outFile, minScore := flags()
2626

2727
document, format := read(inFile)
2828

29-
if err := enhance.Do(context.Background(), document); err != nil {
29+
if err := enhance.Do(context.Background(), document, minScore); err != nil {
3030
fmt.Printf("Error enhancing sbom: %v\n", err)
3131
os.Exit(1)
3232
}
@@ -36,9 +36,10 @@ func main() {
3636
}
3737

3838
// flags sets up and parses flags. Return values are input file and output file
39-
// respecively.
40-
func flags() (string, string) {
39+
// respectively.
40+
func flags() (string, string, int) {
4141
o := flag.String("out", "", "Name of output file, default is <infile>-new.json")
42+
s := flag.Int("min-score", 0, "The minimum effective cd score for license confidence (0-100). Default is 0.")
4243

4344
flag.Usage = func() {
4445
fmt.Printf("Usage of %s:\n", os.Args[0])
@@ -66,7 +67,7 @@ func flags() (string, string) {
6667
}
6768
}
6869

69-
return i, *o
70+
return i, *o, *s
7071
}
7172

7273
// read reads in the sbom document and also returns the format.

pkg/enhance/enhance.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func init() {
4545
// provided protobom Document with results from ClearlyDefined Warnings and
4646
// updates are printed to stdout. TODO: Update to use a provided io.Writer or
4747
// logger, also to use provided http client/transport and context.
48-
func Do(ctx context.Context, s *sbom.Document) error {
48+
func Do(ctx context.Context, s *sbom.Document, minScore int) error {
4949
coords := CoordList(s)
5050
defs, err := getDefs(ctx, coords)
5151
if err != nil {
5252
return err
5353
}
54-
updateLicenses(s, defs)
54+
updateLicenses(s, defs, minScore)
5555
return nil
5656
}
5757

@@ -121,13 +121,13 @@ func getDefsFromService(ctx context.Context, coords []string) (map[string]*cd.De
121121
return defs, nil
122122
}
123123

124-
func updateLicenses(s *sbom.Document, defs map[string]*cd.Definition) {
124+
func updateLicenses(s *sbom.Document, defs map[string]*cd.Definition, minScore int) {
125125
for _, node := range s.GetNodeList().GetNodes() {
126-
updateNode(node, defs)
126+
updateNode(node, defs, minScore)
127127
}
128128
}
129129

130-
func updateNode(n *sbom.Node, defs map[string]*cd.Definition) {
130+
func updateNode(n *sbom.Node, defs map[string]*cd.Definition, minScore int) {
131131
p := n.GetIdentifiers()[int32(sbom.SoftwareIdentifierType_PURL)]
132132
if p == "" {
133133
return
@@ -145,7 +145,7 @@ func updateNode(n *sbom.Node, defs map[string]*cd.Definition) {
145145
}
146146
old := strings.Join(n.GetLicenses(), " AND ")
147147
new := d.Licensed.Declared
148-
if old != new {
148+
if old != new && d.Scores.Effective >= minScore {
149149
fmt.Printf("Update Declared License\n")
150150
fmt.Printf("Name: %v\tVersion: %v\n", n.GetName(), n.GetVersion())
151151
fmt.Printf("\t\t\t\tSBOM License: %q\tCD License: %q\n", old, new)
@@ -154,7 +154,7 @@ func updateNode(n *sbom.Node, defs map[string]*cd.Definition) {
154154

155155
oldDisc := n.GetLicenseConcluded()
156156
newDisc := strings.Join(d.Licensed.Facets.Core.Discovered.Expressions, " AND ")
157-
if oldDisc != newDisc {
157+
if oldDisc != newDisc && d.Scores.Effective >= minScore {
158158
fmt.Printf("Update Discovered License\n")
159159
fmt.Printf("Name: %v\tVersion: %v\n", n.GetName(), n.GetVersion())
160160
fmt.Printf("\t\t\t\tSBOM License: %q\tCD License: %q\n", oldDisc, newDisc)

0 commit comments

Comments
 (0)