Skip to content

Commit

Permalink
Do a pass cleaning up regOpts.GetRegistryClientOpts (#755)
Browse files Browse the repository at this point in the history
I noticed a bunch of places were just reimplementing `regOpts.ClientOpts`, and noticed a couple other little cleanups as I was auditing calls:
 * Have `GenerateCmd` call `image.Digest`
 * Remove dead call in `wasm.go`

Signed-off-by: Matt Moore <[email protected]>
  • Loading branch information
mattmoor authored Sep 22, 2021
1 parent 09a2302 commit b6b0a2f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
6 changes: 2 additions & 4 deletions cmd/cosign/cli/download/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ func SBOMCmd(ctx context.Context, regOpts options.RegistryOpts, imageRef string,
return nil, err
}

remoteOpts := regOpts.GetRegistryClientOpts(ctx)

dstRef, err := remote.SBOMTag(ref, remote.WithRemoteOptions(remoteOpts...))
dstRef, err := remote.SBOMTag(ref, regOpts.ClientOpts(ctx)...)
if err != nil {
return nil, err
}
img, err := remote.Signatures(dstRef, remote.WithRemoteOptions(remoteOpts...))
img, err := remote.Signatures(dstRef, regOpts.ClientOpts(ctx)...)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/cosign/cli/download/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/peterbourgon/ff/v3/ffcli"

"github.com/sigstore/cosign/cmd/cosign/cli/options"
ociremote "github.com/sigstore/cosign/internal/oci/remote"
"github.com/sigstore/cosign/pkg/cosign"
)

Expand Down Expand Up @@ -54,8 +53,7 @@ func SignatureCmd(ctx context.Context, regOpts options.RegistryOpts, imageRef st
if err != nil {
return err
}
regClientOpts := regOpts.GetRegistryClientOpts(ctx)
signatures, err := cosign.FetchSignaturesForReference(ctx, ref, ociremote.WithRemoteOptions(regClientOpts...))
signatures, err := cosign.FetchSignaturesForReference(ctx, ref, regOpts.ClientOpts(ctx)...)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/cosign/cli/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"os"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/peterbourgon/ff/v3/ffcli"

"github.com/sigstore/cosign/cmd/cosign/cli/options"
"github.com/sigstore/cosign/pkg/image"
"github.com/sigstore/cosign/pkg/signature"
"github.com/sigstore/sigstore/pkg/signature/payload"
)
Expand Down Expand Up @@ -74,12 +74,11 @@ func GenerateCmd(ctx context.Context, regOpts options.RegistryOpts, imageRef str
return err
}

get, err := remote.Get(ref, regOpts.GetRegistryClientOpts(ctx)...)
h, err := image.Digest(ref, regOpts.GetRegistryClientOpts(ctx)...)
if err != nil {
return err
}
repo := ref.Context()
img := repo.Digest(get.Digest.String())
img := ref.Context().Digest(h.String())

json, err := (&payload.Cosign{Image: img, Annotations: annotations}).MarshalJSON()
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions cmd/cosign/cli/triangulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func MungeCmd(ctx context.Context, regOpts options.RegistryOpts, imageRef string
return err
}

remoteOpts := regOpts.GetRegistryClientOpts(ctx)
var dstRef name.Tag
switch attachmentType {
case cosign.Signature:
dstRef, err = ociremote.SignatureTag(ref, ociremote.WithRemoteOptions(remoteOpts...))
dstRef, err = ociremote.SignatureTag(ref, regOpts.ClientOpts(ctx)...)
case cosign.SBOM:
dstRef, err = ociremote.SBOMTag(ref, ociremote.WithRemoteOptions(remoteOpts...))
dstRef, err = ociremote.SBOMTag(ref, regOpts.ClientOpts(ctx)...)
case cosign.Attestation:
dstRef, err = ociremote.AttestationTag(ref, ociremote.WithRemoteOptions(remoteOpts...))
dstRef, err = ociremote.AttestationTag(ref, regOpts.ClientOpts(ctx)...)
default:
err = fmt.Errorf("unknown attachment type %s", attachmentType)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/cosign/cli/upload/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func WasmCmd(ctx context.Context, regOpts options.RegistryOpts, wasmPath, imageR
if err != nil {
return err
}
regOpts.GetRegistryClientOpts(ctx)
fmt.Fprintf(os.Stderr, "Uploading wasm file from [%s] to [%s].\n", wasmPath, ref.Name())
if _, err := cremote.UploadFile(b, ref, types.WasmLayerMediaType, types.WasmConfigMediaType, regOpts.GetRegistryClientOpts(ctx)...); err != nil {
return err
Expand Down

0 comments on commit b6b0a2f

Please sign in to comment.