Skip to content

Commit 6f6e456

Browse files
authored
⭐️ support cnquery sbom with shell (#5782)
1 parent d484786 commit 6f6e456

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

providers/sbom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func (s *sbomProviderService) Connect(req *plugin.ConnectReq, callback plugin.Pr
9595
sbom.NewCycloneDX(sbom.FormatCycloneDxXML),
9696
sbom.NewSPDX(sbom.FormatSpdxTagValue),
9797
sbom.NewSPDX(sbom.FormatSpdxJSON),
98+
sbom.New(sbom.FormatJson),
9899
)
99100

100101
var sbomReport *sbom.Sbom

sbom/cnquery_bom.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package sbom
55

66
import (
77
"encoding/json"
8+
"fmt"
89
"io"
910
)
1011

@@ -54,5 +55,10 @@ func (ccx *CnqueryBOM) Parse(r io.Reader) (*Sbom, error) {
5455
return nil, err
5556
}
5657

58+
// Test if the SBOM has a valid structure
59+
if s.Asset == nil {
60+
return nil, fmt.Errorf("unable to parse cnquery SBOM: missing asset information")
61+
}
62+
5763
return &s, nil
5864
}

sbom/spdx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ func (s *Spdx) Parse(r io.Reader) (*Sbom, error) {
168168
// try to parse all supported SPDX format
169169
if s.Format == FormatSpdxTagValue {
170170
doc, err := tagvalue.Read(r)
171-
if err == nil {
171+
if err == nil && doc.SPDXVersion != "" {
172172
return s.convertToSbom(doc), nil
173173
}
174174
} else if s.Format == FormatSpdxJSON {
175175
var doc spdx.Document
176176
err := json.NewDecoder(r).Decode(&doc)
177-
if err == nil {
177+
if err == nil && doc.SPDXVersion != "" {
178178
return s.convertToSbom(&doc), nil
179179
}
180180
}

0 commit comments

Comments
 (0)