Skip to content

Commit

Permalink
Update output to note when signatures are pushed (#1117)
Browse files Browse the repository at this point in the history
Signed-off-by: Hayden Blauzvern <[email protected]>
  • Loading branch information
haydentherapper authored Dec 1, 2021
1 parent 54fb569 commit 034e946
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/cosign/cli/generate/generate_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ func isTerminal() bool {
func getPassFromTerm(confirm bool) ([]byte, error) {
fmt.Fprint(os.Stderr, "Enter password for private key: ")
pw1, err := term.ReadPassword(0)
fmt.Fprintln(os.Stderr)
if err != nil {
return nil, err
}
if !confirm {
return pw1, nil
}
fmt.Fprintln(os.Stderr)
fmt.Fprint(os.Stderr, "Enter password for private key again: ")
pw2, err := term.ReadPassword(0)
fmt.Fprintln(os.Stderr)
Expand Down
24 changes: 13 additions & 11 deletions cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,6 @@ func signDigest(ctx context.Context, digest name.Digest, payload []byte, ko KeyO
}
}

out := os.Stdout
if output != "" {
out, err = os.Create(output)
if err != nil {
return errors.Wrap(err, "create signature file")
}
defer out.Close()
}

var s icos.Signer
s = ipayload.NewSigner(sv, nil, nil)
s = ifulcio.NewSigner(s, sv.Cert, sv.Chain)
Expand All @@ -233,8 +224,17 @@ func signDigest(ctx context.Context, digest name.Digest, payload []byte, ko KeyO
if err != nil {
return err
}
if _, err := out.Write([]byte(b64sig)); err != nil {
return errors.Wrap(err, "write signature to file")

if output != "" {
out, err := os.Create(output)
if err != nil {
return errors.Wrap(err, "create signature file")
}
defer out.Close()

if _, err := out.Write([]byte(b64sig)); err != nil {
return errors.Wrap(err, "write signature to file")
}
}

if !upload {
Expand All @@ -253,6 +253,8 @@ func signDigest(ctx context.Context, digest name.Digest, payload []byte, ko KeyO
return errors.Wrap(err, "constructing client options")
}

fmt.Fprintln(os.Stderr, "Pushing signature to:", digest.Repository)

// Publish the signatures associated with this entity
if err := ociremote.WriteSignatures(digest.Repository, newSE, walkOpts...); err != nil {
return err
Expand Down

0 comments on commit 034e946

Please sign in to comment.