Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use stdin as an input for predicate #2269

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions cmd/cosign/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
_ "crypto/sha256" // for `crypto.SHA256`
"encoding/json"
"fmt"
"io"
"os"
"time"

Expand Down Expand Up @@ -64,7 +65,7 @@ func uploadToTlog(ctx context.Context, sv *sign.SignerVerifier, rekorURL string,
return cbundle.EntryToBundle(entry), nil
}

//nolint
// nolint
func AttestCmd(ctx context.Context, ko options.KeyOpts, regOpts options.RegistryOptions, imageRef string, certPath string, certChainPath string,
noUpload bool, predicatePath string, force bool, predicateType string, replace bool, timeout time.Duration, noTlogUpload bool) error {
// A key file or token is required unless we're in experimental mode!
Expand Down Expand Up @@ -116,12 +117,18 @@ func AttestCmd(ctx context.Context, ko options.KeyOpts, regOpts options.Registry
wrapped := dsse.WrapSigner(sv, types.IntotoPayloadType)
dd := cremote.NewDupeDetector(sv)

fmt.Fprintln(os.Stderr, "Using payload from:", predicatePath)
predicate, err := os.Open(predicatePath)
if err != nil {
return err
var predicate io.ReadCloser
if predicatePath == "-" {
fmt.Fprintln(os.Stderr, "Using payload from: standard input")
predicate = os.Stdin
} else {
fmt.Fprintln(os.Stderr, "Using payload from:", predicatePath)
predicate, err = os.Open(predicatePath)
if err != nil {
return err
}
defer predicate.Close()
}
defer predicate.Close()

sh, err := attestation.GenerateStatement(attestation.GenerateOpts{
Predicate: predicate,
Expand Down