@@ -12,6 +12,7 @@ import (
12
12
"github.com/spf13/cobra"
13
13
14
14
"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless"
15
+ "github.com/argoproj/argo-cd/v2/cmd/argocd/commands/utils"
15
16
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
16
17
projectpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/project"
17
18
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
@@ -169,8 +170,15 @@ ID ISSUED-AT EXPIRES-AT
169
170
}
170
171
role .Policies [duplicateIndex ] = role .Policies [len (role .Policies )- 1 ]
171
172
proj .Spec .Roles [roleIndex ].Policies = role .Policies [:len (role .Policies )- 1 ]
172
- _ , err = projIf .Update (ctx , & projectpkg.ProjectUpdateRequest {Project : proj })
173
- errors .CheckError (err )
173
+
174
+ promptUtil := utils .NewPrompt (clientOpts .PromptsEnabled )
175
+ canDelete := promptUtil .Confirm (fmt .Sprintf ("Are you sure you want to delete '%s' policy? [y/n]" , policyToRemove ))
176
+ if canDelete {
177
+ _ , err = projIf .Update (ctx , & projectpkg.ProjectUpdateRequest {Project : proj })
178
+ errors .CheckError (err )
179
+ } else {
180
+ fmt .Printf ("The command to delete policy '%s' was cancelled.\n " , policyToRemove )
181
+ }
174
182
},
175
183
}
176
184
addPolicyFlags (command , & opts )
@@ -237,6 +245,8 @@ func NewProjectRoleDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.
237
245
conn , projIf := headless .NewClientOrDie (clientOpts , c ).NewProjectClientOrDie ()
238
246
defer io .Close (conn )
239
247
248
+ promptUtil := utils .NewPrompt (clientOpts .PromptsEnabled )
249
+
240
250
proj , err := projIf .Get (ctx , & projectpkg.ProjectQuery {Name : projName })
241
251
errors .CheckError (err )
242
252
@@ -248,9 +258,14 @@ func NewProjectRoleDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.
248
258
proj .Spec .Roles [index ] = proj .Spec .Roles [len (proj .Spec .Roles )- 1 ]
249
259
proj .Spec .Roles = proj .Spec .Roles [:len (proj .Spec .Roles )- 1 ]
250
260
251
- _ , err = projIf .Update (ctx , & projectpkg.ProjectUpdateRequest {Project : proj })
252
- errors .CheckError (err )
253
- fmt .Printf ("Role '%s' deleted\n " , roleName )
261
+ canDelete := promptUtil .Confirm (fmt .Sprintf ("Are you sure you want to delete '%s' role? [y/n]" , roleName ))
262
+ if canDelete {
263
+ _ , err = projIf .Update (ctx , & projectpkg.ProjectUpdateRequest {Project : proj })
264
+ errors .CheckError (err )
265
+ fmt .Printf ("Role '%s' deleted\n " , roleName )
266
+ } else {
267
+ fmt .Printf ("The command to delete role '%s' was cancelled.\n " , roleName )
268
+ }
254
269
},
255
270
}
256
271
return command
@@ -437,14 +452,22 @@ $ argocd proj role delete-token test-project test-role 1696769937
437
452
}
438
453
projName := args [0 ]
439
454
roleName := args [1 ]
440
- issuedAt , err := strconv .ParseInt (args [2 ], 10 , 64 )
455
+ tokenId := args [2 ]
456
+ issuedAt , err := strconv .ParseInt (tokenId , 10 , 64 )
441
457
errors .CheckError (err )
442
458
459
+ promptUtil := utils .NewPrompt (clientOpts .PromptsEnabled )
460
+
443
461
conn , projIf := headless .NewClientOrDie (clientOpts , c ).NewProjectClientOrDie ()
444
462
defer io .Close (conn )
445
463
446
- _ , err = projIf .DeleteToken (ctx , & projectpkg.ProjectTokenDeleteRequest {Project : projName , Role : roleName , Iat : issuedAt })
447
- errors .CheckError (err )
464
+ canDelete := promptUtil .Confirm (fmt .Sprintf ("Are you sure you want to delete '%s' project token? [y/n]" , tokenId ))
465
+ if canDelete {
466
+ _ , err = projIf .DeleteToken (ctx , & projectpkg.ProjectTokenDeleteRequest {Project : projName , Role : roleName , Iat : issuedAt })
467
+ errors .CheckError (err )
468
+ } else {
469
+ fmt .Printf ("The command to delete project token '%s' was cancelled.\n " , tokenId )
470
+ }
448
471
},
449
472
}
450
473
return command
@@ -621,9 +644,18 @@ func NewProjectRoleRemoveGroupCommand(clientOpts *argocdclient.ClientOptions) *c
621
644
fmt .Printf ("Group '%s' not present in role '%s'\n " , groupName , roleName )
622
645
return
623
646
}
624
- _ , err = projIf .Update (ctx , & projectpkg.ProjectUpdateRequest {Project : proj })
625
- errors .CheckError (err )
626
- fmt .Printf ("Group '%s' removed from role '%s'\n " , groupName , roleName )
647
+
648
+ promptUtil := utils .NewPrompt (clientOpts .PromptsEnabled )
649
+
650
+ canDelete := promptUtil .Confirm (fmt .Sprintf ("Are you sure you want to remove '%s' group from role '%s'? [y/n]" , groupName , roleName ))
651
+
652
+ if canDelete {
653
+ _ , err = projIf .Update (ctx , & projectpkg.ProjectUpdateRequest {Project : proj })
654
+ errors .CheckError (err )
655
+ fmt .Printf ("Group '%s' removed from role '%s'\n " , groupName , roleName )
656
+ } else {
657
+ fmt .Printf ("The command to remove group '%s' from role '%s' was cancelled.\n " , groupName , roleName )
658
+ }
627
659
},
628
660
}
629
661
return command
0 commit comments