Skip to content

Commit

Permalink
Streamline SignBlobCmd API with SignCmd (sigstore#1454)
Browse files Browse the repository at this point in the history
In `SignCmd` we do not pass a context any more but use the timeout from
the root options. This is now done in `SignBlobCmd` too.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert authored and Marc Hildenbrand committed Apr 19, 2022
1 parent fbe192f commit a2d769f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions cmd/cosign/cli/sign/sign_blob.go
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"os"
"path/filepath"
"time"

"github.com/pkg/errors"
cbundle "github.com/sigstore/cosign/pkg/cosign/bundle"
Expand Down Expand Up @@ -54,7 +53,7 @@ type KeyOpts struct {
}

// nolint
func SignBlobCmd(ctx context.Context, ko KeyOpts, regOpts options.RegistryOptions, payloadPath string, b64 bool, outputSignature string, outputCertificate string, timeout time.Duration) ([]byte, error) {
func SignBlobCmd(ro *options.RootOptions, ko KeyOpts, regOpts options.RegistryOptions, payloadPath string, b64 bool, outputSignature string, outputCertificate string) ([]byte, error) {
var payload []byte
var err error
var rekorBytes []byte
Expand All @@ -68,11 +67,9 @@ func SignBlobCmd(ctx context.Context, ko KeyOpts, regOpts options.RegistryOption
if err != nil {
return nil, err
}
if timeout != 0 {
var cancelFn context.CancelFunc
ctx, cancelFn = context.WithTimeout(ctx, timeout)
defer cancelFn()
}

ctx, cancel := context.WithTimeout(context.Background(), ro.Timeout)
defer cancel()

sv, err := SignerFromKeyOpts(ctx, "", ko)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cosign/cli/signblob.go
Expand Up @@ -84,7 +84,7 @@ func SignBlob() *cobra.Command {
fmt.Fprintln(os.Stderr, "WARNING: the '--output' flag is deprecated and will be removed in the future. Use '--output-signature'")
o.OutputSignature = o.Output
}
if _, err := sign.SignBlobCmd(cmd.Context(), ko, o.Registry, blob, o.Base64Output, o.OutputSignature, o.OutputCertificate, ro.Timeout); err != nil {
if _, err := sign.SignBlobCmd(ro, ko, o.Registry, blob, o.Base64Output, o.OutputSignature, o.OutputCertificate); err != nil {
return errors.Wrapf(err, "signing %s", blob)
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/e2e_test.go
Expand Up @@ -509,7 +509,7 @@ func TestSignBlob(t *testing.T) {
KeyRef: privKeyPath1,
PassFunc: passFunc,
}
sig, err := sign.SignBlobCmd(ctx, ko, options.RegistryOptions{}, bp, true, "", "", 30*time.Second)
sig, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -549,15 +549,15 @@ func TestSignBlobBundle(t *testing.T) {
BundlePath: bundlePath,
RekorURL: rekorURL,
}
if _, err := sign.SignBlobCmd(ctx, ko, options.RegistryOptions{}, bp, true, "", "", 30*time.Second); err != nil {
if _, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", ""); err != nil {
t.Fatal(err)
}
// Now verify should work
must(cliverify.VerifyBlobCmd(ctx, ko1, "", "", "", "", bp), t)

// Now we turn on the tlog and sign again
defer setenv(t, options.ExperimentalEnv, "1")()
if _, err := sign.SignBlobCmd(ctx, ko, options.RegistryOptions{}, bp, true, "", "", 30*time.Second); err != nil {
if _, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", ""); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit a2d769f

Please sign in to comment.