Skip to content

Commit

Permalink
feat: use stdin as an input for predicate (#2269)
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
  • Loading branch information
developer-guy authored Sep 23, 2022
1 parent 1c25987 commit 45b9402
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit 45b9402

Please sign in to comment.