Skip to content

Commit

Permalink
Refactor verification output. (sigstore#632)
Browse files Browse the repository at this point in the history
This will make it easier to customize for attestation output.

Signed-off-by: Dan Lorenc <lorenc.d@gmail.com>
  • Loading branch information
dlorenc committed Sep 12, 2021
1 parent f2a1276 commit 60cf6b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions cmd/cosign/cli/verify.go
Expand Up @@ -180,14 +180,14 @@ func (c *VerifyCommand) Exec(ctx context.Context, args []string) (err error) {
return err
}

PrintVerification(imageRef, verified, co, c.Output)
PrintVerificationHeader(imageRef, co)
PrintVerification(imageRef, verified, c.Output)
}

return nil
}

// PrintVerification logs details about the verification to stdout
func PrintVerification(imgRef string, verified []cosign.SignedPayload, co *cosign.CheckOpts, output string) {
func PrintVerificationHeader(imgRef string, co *cosign.CheckOpts) {
fmt.Fprintf(os.Stderr, "\nVerification for %s --\n", imgRef)
fmt.Fprintln(os.Stderr, "The following checks were performed on each of these signatures:")
if co.ClaimVerifier != nil {
Expand All @@ -206,6 +206,10 @@ func PrintVerification(imgRef string, verified []cosign.SignedPayload, co *cosig
fmt.Fprintln(os.Stderr, " - The signatures were verified against the specified public key")
}
fmt.Fprintln(os.Stderr, " - Any certificates were verified against the Fulcio roots.")
}

// PrintVerification logs details about the verification to stdout
func PrintVerification(imgRef string, verified []cosign.SignedPayload, output string) {

switch output {
case "text":
Expand Down
3 changes: 2 additions & 1 deletion cmd/cosign/cli/verify_attestation.go
Expand Up @@ -170,8 +170,9 @@ func (c *VerifyAttestationCommand) Exec(ctx context.Context, args []string) (err
return err
}

PrintVerificationHeader(imageRef, co)
// The attestations are always JSON, so use the raw "text" mode for outputting them instead of conversion
PrintVerification(imageRef, verified, co, "text")
PrintVerification(imageRef, verified, "text")
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/sget/cli/sget.go
Expand Up @@ -68,7 +68,8 @@ func SgetCmd(ctx context.Context, imageRef, keyRef string) (io.ReadCloser, error
if err != nil {
return nil, err
}
cli.PrintVerification(imageRef, sp, co, "text")
cli.PrintVerificationHeader(imageRef, co)
cli.PrintVerification(imageRef, sp, "text")
}

img, err := remote.Image(ref, co.RegistryClientOpts...)
Expand Down

0 comments on commit 60cf6b8

Please sign in to comment.