From f4de5c0e3a84c945bc52516de29c3c9bad9e4785 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Sun, 17 Oct 2021 16:23:26 -0500 Subject: [PATCH] Don't ignore the media type flag to upload-blob! Fixes #906 Signed-off-by: Dan Lorenc --- cmd/cosign/cli/upload/blob.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/cosign/cli/upload/blob.go b/cmd/cosign/cli/upload/blob.go index 73309467e86..7580ba833c6 100644 --- a/cmd/cosign/cli/upload/blob.go +++ b/cmd/cosign/cli/upload/blob.go @@ -22,19 +22,28 @@ import ( "os" "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/types" "github.com/sigstore/cosign/cmd/cosign/cli/options" cremote "github.com/sigstore/cosign/pkg/cosign/remote" ) func BlobCmd(ctx context.Context, regOpts options.RegistryOptions, files []cremote.File, contentType, imageRef string) error { - // TODO: use contentType. ref, err := name.ParseReference(imageRef) if err != nil { return err } - dgstAddr, err := cremote.UploadFiles(ref, files, cremote.DefaultMediaTypeGetter, regOpts.GetRegistryClientOpts(ctx)...) + // We normally discover the content media type by inspecting the byte stream. + // Just pass it directly if it's set on the command line. + mt := cremote.DefaultMediaTypeGetter + if contentType != "" { + mt = func(_ []byte) types.MediaType { + return types.MediaType(contentType) + } + } + + dgstAddr, err := cremote.UploadFiles(ref, files, mt, regOpts.GetRegistryClientOpts(ctx)...) if err != nil { return err }