Skip to content

SBOM.FilterProperties for namespace-scoped property pruning#2

Merged
andrew merged 1 commit into
mainfrom
filter-properties
May 12, 2026
Merged

SBOM.FilterProperties for namespace-scoped property pruning#2
andrew merged 1 commit into
mainfrom
filter-properties

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 12, 2026

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.

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:")
    })
@andrew andrew merged commit ed210ba into main May 12, 2026
5 checks passed
@andrew andrew deleted the filter-properties branch May 12, 2026 17:05
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 this pull request may close these issues.

1 participant