Skip to content

Commit

Permalink
refactor shouldUploadTlog
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Sanders <jsand@google.com>
  • Loading branch information
Jake Sanders committed Nov 21, 2021
1 parent 79aff71 commit 549781c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ import (
sigPayload "github.com/sigstore/sigstore/pkg/signature/payload"
)

func ShouldUploadToTlog(ref name.Reference, force bool, url string) (bool, error) {
func shouldUploadToTlog(ref name.Reference, force bool, url string) bool {
// Check whether experimental is on!
if !options.EnableExperimental() {
return false, nil
return false
}
// We are forcing publishing to the Tlog.
if force {
return true, nil
return true
}

// Check if the image is public (no auth in Get)
Expand All @@ -77,14 +77,14 @@ func ShouldUploadToTlog(ref name.Reference, force bool, url string) (bool, error

var tlogConfirmResponse string
if _, err := fmt.Scanln(&tlogConfirmResponse); err != nil {
return false, err
panic(err)
}
if strings.ToUpper(tlogConfirmResponse) != "Y" {
fmt.Fprintln(os.Stderr, "not uploading to transparency log")
return false, nil
return false
}
}
return true, nil
return true
}

type Uploader func(*rekGenClient.Rekor, []byte) (*models.LogEntryAnon, error)
Expand Down Expand Up @@ -255,11 +255,7 @@ func signDigest(ctx context.Context, digest name.Digest, payload []byte, ko KeyO
if sv.Cert != nil {
opts = append(opts, static.WithCertChain(sv.Cert, sv.Chain))
}

// Check whether we should be uploading to the transparency log
if uploadTLog, err := ShouldUploadToTlog(digest, force, ko.RekorURL); err != nil {
return err
} else if uploadTLog {
if shouldUploadToTlog(digest, force, ko.RekorURL) {
bundle, err := UploadToTlog(ctx, sv, ko.RekorURL, func(r *rekGenClient.Rekor, b []byte) (*models.LogEntryAnon, error) {
// TODO - Defaulting the timeout to zero as the CLI doesn't accept timeout.
return cosign.TLogUpload(r, signature, payload, b, time.Duration(0))
Expand Down

0 comments on commit 549781c

Please sign in to comment.