Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CycloneDx: add HasMetadata to 'toplevel' package #54

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions pkg/ingestor/parser/cyclonedx/parser_cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ func (c *cyclonedxParser) GetPredicates(ctx context.Context) *assembler.IngestPr

preds.IsDependency = append(preds.IsDependency, common.CreateTopLevelIsDeps(toplevel[0], c.packagePackages, nil, "top-level package GUAC heuristic connecting to each file/package")...)
preds.HasSBOM = append(preds.HasSBOM, common.CreateTopLevelHasSBOM(toplevel[0], c.doc, c.cdxBom.SerialNumber, timestamp))
// add HasMetadata to toplevel packages
hasMetadata := assembler.HasMetadataIngest{
Pkg: toplevel[0],
PkgMatchFlag: model.MatchFlags{Pkg: generated.PkgMatchTypeSpecificVersion},
HasMetadata: &model.HasMetadataInputSpec{
Key: "topLevelPackage",
Value: asmhelpers.PkgInputSpecToPurl(toplevel[0]),
Timestamp: time.Now().UTC(),
Justification: "CyclonDX top level package reference",
Origin: "GUAC CyclonDX",
Collector: "GUAC",
},
}
preds.HasMetadata = append(preds.HasMetadata, hasMetadata)
}

for id := range c.packagePackages {
Expand Down Expand Up @@ -306,22 +320,20 @@ func (c *cyclonedxParser) GetPredicates(ctx context.Context) *assembler.IngestPr
preds.IsDependency = append(preds.IsDependency, *p)
}
// add top level package reference to each package with a HasMetadata node
if toplevel != nil {
for _, topLevelPkg := range toplevel {
hasMetadata := assembler.HasMetadataIngest{
Pkg: packNode,
PkgMatchFlag: model.MatchFlags{Pkg: generated.PkgMatchTypeSpecificVersion},
HasMetadata: &model.HasMetadataInputSpec{
Key: "topLevelPackage",
Value: asmhelpers.PkgInputSpecToPurl(topLevelPkg),
Timestamp: time.Now().UTC(),
Justification: "CyclonDX top level package reference",
Origin: "GUAC CyclonDX",
Collector: "GUAC",
},
}
preds.HasMetadata = append(preds.HasMetadata, hasMetadata)
for _, topLevelPkg := range toplevel {
hasMetadata := assembler.HasMetadataIngest{
Pkg: packNode,
PkgMatchFlag: model.MatchFlags{Pkg: generated.PkgMatchTypeSpecificVersion},
HasMetadata: &model.HasMetadataInputSpec{
Key: "topLevelPackage",
Value: asmhelpers.PkgInputSpecToPurl(topLevelPkg),
Timestamp: time.Now().UTC(),
Justification: "CyclonDX top level package reference",
Origin: "GUAC CyclonDX",
Collector: "GUAC",
},
}
preds.HasMetadata = append(preds.HasMetadata, hasMetadata)
}
}
}
Expand Down
Loading