File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,12 +25,12 @@ import (
2525
2626func 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 == "" {
Original file line number Diff line number Diff line change 5454const (
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+
521527func isAPITokenPreferred (cmd * cobra.Command ) bool {
522528 return cmd .Annotations [useAPIToken ] == trueString
523529}
You can’t perform that action at this time.
0 commit comments