imagetools: supress warnings for dsse mediatypes

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2024-02-28 19:25:42 -08:00
parent b748185f48
commit dcdcce6c52
No known key found for this signature in database
GPG Key ID: AFA9DE5F8AB7AF39
1 changed files with 14 additions and 3 deletions

View File

@ -23,7 +23,11 @@ import (
"golang.org/x/sync/errgroup"
)
const inTotoGenericMime = "application/vnd.in-toto+json"
const (
inTotoGenericMime = "application/vnd.in-toto+json"
inTotoSPDXDSSEMime = "application/vnd.in-toto.spdx+dsse"
inTotoProvenanceDSSEMime = "application/vnd.in-toto.provenance+dsse"
)
var (
annotationReferences = []string{
@ -278,7 +282,7 @@ type sbomStub struct {
}
func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
ctx = remotes.WithMediaTypeKeyPrefix(ctx, inTotoGenericMime, "intoto")
ctx = withIntotoMediaTypes(ctx)
as.deferredSbom = func() (*sbomStub, error) {
var sbom *sbomStub
for _, dgst := range refs {
@ -329,7 +333,7 @@ type provenanceStub struct {
}
func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
ctx = remotes.WithMediaTypeKeyPrefix(ctx, inTotoGenericMime, "intoto")
ctx = withIntotoMediaTypes(ctx)
as.deferredProvenance = func() (*provenanceStub, error) {
var provenance *provenanceStub
for _, dgst := range refs {
@ -459,3 +463,10 @@ func decodeDSSE(dt []byte, mime string) ([]byte, error) {
return dt, nil
}
func withIntotoMediaTypes(ctx context.Context) context.Context {
for _, mime := range []string{inTotoGenericMime, inTotoSPDXDSSEMime, inTotoProvenanceDSSEMime} {
ctx = remotes.WithMediaTypeKeyPrefix(ctx, mime, "intoto")
}
return ctx
}