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

Make SBOM generation less bad #799

Closed
Tracked by #781
jonjohnsonjr opened this issue Jul 10, 2023 · 0 comments · Fixed by #800 or #801
Closed
Tracked by #781

Make SBOM generation less bad #799

jonjohnsonjr opened this issue Jul 10, 2023 · 0 comments · Fixed by #800 or #801

Comments

@jonjohnsonjr
Copy link
Contributor

This is quadratic:

func (sx *SPDX) ProcessInternalApkSBOM(opts *options.Options, doc *Document, p *Package) error {
// Check if apk installed an SBOM
path, err := locateApkSBOM(sx.fs, p)
if err != nil {
return fmt.Errorf("inspecting FS for internal apk SBOM: %w", err)
}
if path == "" {
return nil
}
// TODO: Logf("composing packages from %s into image SBOM", path)
internalDoc, err := sx.ParseInternalSBOM(opts, path)
if err != nil {
// TODO: Log error parsing apk SBOM
return nil
}
targetElementIDs := []string{}
// Cycle the top level elements...
for _, elementID := range internalDoc.DocumentDescribes {
// ... searching for a 1st level package
for _, pkg := range internalDoc.Packages {
// that matches the name
if pkg.ID == elementID && p.Name == pkg.Name {
targetElementIDs = append(targetElementIDs, pkg.ID)
// TODO: Logf("Found package %s describing %s", pkg.ID, p.Name)
}
}
// Copy the targetElementIDs
copiedElements := &map[string]struct{}{}
for _, id := range targetElementIDs {
if err := copySBOMElement(id, internalDoc, doc, copiedElements); err != nil {
return fmt.Errorf("copying element: %w", err)
}
// Search for a package in the new SBOM describing the same thing
for _, pkg := range doc.Packages {
// TODO: Think if we need to match version too
if pkg.Name == p.Name {
replacePackage(doc, pkg.ID, id)
break
}
}
}
}
return nil
}

This was referenced Jul 10, 2023
@jonjohnsonjr jonjohnsonjr reopened this Jul 10, 2023
@jonjohnsonjr jonjohnsonjr changed the title Make SBOM generation not bad Make SBOM generation less bad Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant