SBOM.FilterProperties for namespace-scoped property pruning#2
Merged
Conversation
Walks every package's Properties slice and removes entries where the
keep predicate returns false. Useful when handing a document to a
downstream consumer that doesn't recognise a particular property
namespace — strip the tool-specific prefix before sharing outside
the team that produced it.
The filter mutates the SBOM in place. Document- and Component-level
metadata is untouched; only the per-package Properties slice is
affected (which mirrors where Property entries actually live in the
parsed model).
Usage:
doc.FilterProperties(func(name string) bool {
return !strings.HasPrefix(name, "mytool:")
})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds `(*SBOM).FilterProperties(keep func(name string) bool)` — walks every package's `Properties` slice and removes entries where `keep` returns false. Useful when handing a document to a downstream consumer that doesn't recognise a particular property namespace.
Why
Tools often emit ecosystem- or product-specific properties under a namespace prefix (`mytool:type`, `mytool:size`, etc.) to attach metadata that survives the CycloneDX / SPDX shape but isn't part of the standard schema. When that document is handed off to a downstream consumer (Dependency-Track, GUAC, OSV-scanner, an internal pipeline), the namespace properties are dead weight at best and confusing at worst.
The filter is one method call:
```go
doc.FilterProperties(func(name string) bool {
return !strings.HasPrefix(name, "mytool:")
})
```
In-place mutation. Document- and Component-level metadata is untouched — `Properties` only lives on `Package` in the parsed model, so that's the only level the filter visits.
Tests
Three: happy path with a prefix predicate, nil predicate is a safe no-op, and empty-packages doesn't panic.