From dcfb11d6c01d7e48829557b65e7df390c9d78e54 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Mon, 18 Oct 2021 21:09:17 -0500 Subject: [PATCH] Don't ignore the media type flag to upload-blob! (#910) 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 }