Skip to content

Commit

Permalink
Use the timeout flag value in verify* commands. (#3391)
Browse files Browse the repository at this point in the history
* Use the timeout flag value in verify* commands.

Signed-off-by: zhaoyonghe <yonghe.zhao@yahoo.com>

* Solve "Error: lostcancel: the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak (govet)".

Signed-off-by: zhaoyonghe <yonghe.zhao@yahoo.com>

---------

Signed-off-by: zhaoyonghe <yonghe.zhao@yahoo.com>
  • Loading branch information
zhaoyonghe committed Nov 28, 2023
1 parent da53b08 commit 6b06819
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/cosign/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package cli

import (
"context"
"fmt"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -142,7 +143,8 @@ against the transparency log.`,
v.NameOptions = append(v.NameOptions, name.Insecure)
}

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

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "signature"))
Expand Down Expand Up @@ -241,7 +243,8 @@ against the transparency log.`,
return fmt.Errorf("please set the --max-worker flag to a value that is greater than 0")
}

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

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "attestation"))
Expand Down Expand Up @@ -336,7 +339,8 @@ The blob may be specified as a path to a file or - for stdin.`,
IgnoreTlog: o.CommonVerifyOptions.IgnoreTlog,
}

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

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "blob"))
Expand Down Expand Up @@ -411,7 +415,8 @@ The blob may be specified as a path to a file.`,
path = args[0]
}

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

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "blob attestation"))
Expand Down

0 comments on commit 6b06819

Please sign in to comment.