Skip to content

Commit 44ef67c

Browse files
authored
fix: only ask for confirmation on att init (#1905)
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent 2be01cb commit 44ef67c

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

app/cli/cmd/attestation_init.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525

2626
func newAttestationInitCmd() *cobra.Command {
2727
var (
28-
force bool
29-
contractRevision int
30-
attestationDryRun bool
31-
workflowName string
32-
projectName string
33-
projectVersion string
28+
force bool
29+
contractRevision int
30+
attestationDryRun bool
31+
workflowName string
32+
projectName string
33+
projectVersion string
3434
projectVersionRelease bool
3535
newWorkflowcontract string
3636
)
@@ -39,7 +39,8 @@ func newAttestationInitCmd() *cobra.Command {
3939
Use: "init",
4040
Short: "start attestation crafting process",
4141
Annotations: map[string]string{
42-
useAPIToken: "true",
42+
useAPIToken: trueString,
43+
confirmWhenUserToken: trueString,
4344
},
4445
PreRunE: func(_ *cobra.Command, _ []string) error {
4546
if workflowName == "" {

app/cli/cmd/root.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ var (
5454
const (
5555
// preference to use an API token if available
5656
useAPIToken = "withAPITokenAuth"
57-
appName = "chainloop"
57+
// Ask for confirmation when user token is used and API token is preferred
58+
confirmWhenUserToken = "confirmWhenUserToken"
59+
appName = "chainloop"
5860
//nolint:gosec
5961
tokenEnvVarName = "CHAINLOOP_TOKEN"
6062
userAudience = "user-auth.chainloop"
@@ -150,7 +152,7 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
150152
}
151153

152154
// Warn users when the session is interactive, and the operation is supposed to use an API token instead
153-
if isAPITokenPreferred(cmd) && isUserToken && !flagYes {
155+
if shouldAskForConfirmation(cmd) && isUserToken && !flagYes {
154156
if !confirmationPrompt(fmt.Sprintf("This command is will run against the organization %q", orgName)) {
155157
return errors.New("command canceled by user")
156158
}
@@ -518,6 +520,10 @@ func setLocalOrganization(orgName string) error {
518520
return viper.WriteConfig()
519521
}
520522

523+
func shouldAskForConfirmation(cmd *cobra.Command) bool {
524+
return isAPITokenPreferred(cmd) && cmd.Annotations[confirmWhenUserToken] == trueString
525+
}
526+
521527
func isAPITokenPreferred(cmd *cobra.Command) bool {
522528
return cmd.Annotations[useAPIToken] == trueString
523529
}

0 commit comments

Comments
 (0)