Skip to content

Commit 27c4d5e

Browse files
committed
add schemaValidation method
1 parent b0d4547 commit 27c4d5e

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

pkg/sbom/cdx.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type CdxDoc struct {
5151
format FileFormat
5252
ctx context.Context
5353
CdxSpec *Specs
54+
cdxValidSchema bool
5455
Comps []GetComponent
5556
CdxAuthors []GetAuthor
5657
CdxTools []GetTool
@@ -98,6 +99,7 @@ func newCDXDoc(ctx context.Context, f io.ReadSeeker, format FileFormat, sig Sign
9899
doc: bom,
99100
format: format,
100101
ctx: ctx,
102+
cdxValidSchema: true,
101103
SignatureDetail: &sig,
102104
}
103105
doc.parse()
@@ -161,6 +163,10 @@ func (c CdxDoc) Signature() GetSignature {
161163
return c.SignatureDetail
162164
}
163165

166+
func (c CdxDoc) SchemaValidation() bool {
167+
return c.cdxValidSchema
168+
}
169+
164170
func (c *CdxDoc) parse() {
165171
c.parseDoc()
166172
c.parseSpec()

pkg/sbom/document.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sbom
1919
//counterfeiter:generate . Document
2020
type Document interface {
2121
Spec() Spec
22+
SchemaValidation() bool
2223
Components() []GetComponent
2324
Relations() []GetRelation
2425
Authors() []GetAuthor

pkg/sbom/sbom.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func SupportedSBOMSpecs() []string {
6666

6767
func SupportedSBOMSpecVersions(f string) []string {
6868
switch strings.ToLower(f) {
69-
case "cyclonedx":
69+
case string(SBOMSpecCDX):
7070
return cdxSpecVersions
71-
case "spdx":
71+
case string(SBOMSpecSPDX):
7272
return spdxSpecVersions
7373
default:
7474
return []string{}
@@ -173,7 +173,7 @@ func NewSBOMDocument(ctx context.Context, f io.ReadSeeker, sig Signature) (Docum
173173
return nil, err
174174
}
175175

176-
log.Debugf("SBOM detect spec:%s format:%s", spec, format)
176+
log.Debugf("SBOM detect spec:%s version:%s format:%s ", spec, version, format)
177177

178178
var doc Document
179179

pkg/sbom/spdx.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type SpdxDoc struct {
4848
version FormatVersion
4949
ctx context.Context
5050
SpdxSpec *Specs
51+
spdxValidSchema bool
5152
Comps []GetComponent
5253
Auths []GetAuthor
5354
SpdxTools []GetTool
@@ -94,6 +95,7 @@ func newSPDXDoc(ctx context.Context, f io.ReadSeeker, format FileFormat, version
9495
format: format,
9596
ctx: ctx,
9697
version: version,
98+
spdxValidSchema: true,
9799
SignatureDetail: &sig,
98100
}
99101

@@ -163,6 +165,10 @@ func (s SpdxDoc) Signature() GetSignature {
163165
return s.SignatureDetail
164166
}
165167

168+
func (s SpdxDoc) SchemaValidation() bool {
169+
return s.spdxValidSchema
170+
}
171+
166172
func (s *SpdxDoc) parse() {
167173
s.parseDoc()
168174
s.parseSpec()

0 commit comments

Comments
 (0)