Skip to content

Commit

Permalink
Update prompt to only prompt for non-destructive actions
Browse files Browse the repository at this point in the history
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
  • Loading branch information
haydentherapper committed May 24, 2022
1 parent 3911422 commit 10e050d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/cosign/cli/clean.go
Expand Up @@ -51,7 +51,7 @@ func Clean() *cobra.Command {

func CleanCmd(ctx context.Context, regOpts options.RegistryOptions, cleanType, imageRef string, force bool) error {
if !force {
ok, err := cosign.ConfirmPrompt(prompt(cleanType))
ok, err := cosign.ConfirmPrompt(prompt(cleanType), true /*destructive*/)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cosign/cli/fulcio/fulcio.go
Expand Up @@ -155,7 +155,7 @@ func NewSigner(ctx context.Context, ko options.KeyOpts) (*Signer, error) {
fmt.Fprintln(os.Stderr, "Non-interactive mode detected, using device flow.")
flow = FlowDevice
default:
ok, err := cosign.ConfirmPrompt(PrivacyStatementConfirmation)
ok, err := cosign.ConfirmPrompt(PrivacyStatementConfirmation, false /*destructive*/)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cosign/cli/options/root.go
Expand Up @@ -46,5 +46,5 @@ func (o *RootOptions) AddFlags(cmd *cobra.Command) {
"timeout for commands")

cmd.PersistentFlags().BoolVarP(&o.SkipConfirmation, "yes", "y", false,
"skip confirmation prompts")
"skip confirmation prompts for non-destructive operations")
}
7 changes: 5 additions & 2 deletions pkg/cosign/common.go
Expand Up @@ -43,8 +43,11 @@ func FileExists(filename string) bool {
return !info.IsDir()
}

func ConfirmPrompt(msg string) (bool, error) {
if skipConfirmation {
// ConfirmPrompt prompts the user for confirmation for an action. Supports skipping
// the confirmation prompt when the global skipConfirmation is set, and when the
// action is non-destructive.
func ConfirmPrompt(msg string, destructive bool) (bool, error) {
if skipConfirmation && !destructive {
return skipConfirmation, nil
}

Expand Down

0 comments on commit 10e050d

Please sign in to comment.