Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT 586 select multiple ids for delete resource #928

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4461350
Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908)
dependabot[bot] Nov 13, 2023
2054394
dxcdt-615-goreleaser-upgrade (#909)
Nov 13, 2023
1da3631
DXCDT-582: Convert audience into a drop down in interactive mode in t…
sergiught Nov 11, 2023
7dbf8ea
Merge branch 'main' of https://github.com/auth0/auth0-cli
Nov 13, 2023
1fd7dc2
Merge branch 'main' of https://github.com/auth0/auth0-cli
Nov 16, 2023
60f801c
Merge branch 'main' of https://github.com/auth0/auth0-cli
Nov 22, 2023
b0fd941
Merge remote-tracking branch 'upstream/main'
Nov 29, 2023
651dd2e
Added batch deletes to actions
Nov 30, 2023
70123ac
Add batch deletions
Nov 30, 2023
cd22471
DXCDT-595: Add ability to update signing alg for apis (#926)
sergiught Nov 30, 2023
d5637f0
Bump github.com/auth0/go-auth0 from 1.3.0 to 1.3.1 (#929)
dependabot[bot] Dec 1, 2023
e42a552
Updated docs
Dec 1, 2023
c506642
Simplify args loops
Dec 1, 2023
55393af
Merge branch 'main' of https://github.com/auth0/auth0-cli into DXCDT-…
Dec 1, 2023
d6189a8
Merge branch 'main' of github.com:auth0/auth0-cli into DXCDT-586-sele…
Dec 1, 2023
e590a59
Updates for code review
Dec 4, 2023
2d7e444
Validate input for askMultiSelect
Dec 4, 2023
1da47fa
Update docs
Dec 4, 2023
16d0d6b
Remove unused variable
Dec 4, 2023
e514e21
Use Batch deletion for integration test cleanup
Dec 5, 2023
ec53715
Merge branch 'main' into DXCDT-586-select-multiple-ids-for-delete-res…
Dec 5, 2023
3c0bddc
Merge branch 'main' into DXCDT-586-select-multiple-ids-for-delete-res…
willvedd Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/auth0_actions_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 actions delete [flags]
auth0 actions rm
auth0 actions delete <action-id>
auth0 actions delete <action-id> --force
auth0 actions delete <action-id> <action-id2> <action-idn>
auth0 actions delete <action-id> <action-id2> <action-idn> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_apis_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 apis delete [flags]
auth0 apis rm
auth0 apis delete <api-id|api-audience>
auth0 apis delete <api-id|api-audience> --force
auth0 apis delete <api-id|api-audience> <api-id2> <api-idn>
auth0 apis delete <api-id|api-audience> <api-id2> <api-idn> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_apps_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 apps delete [flags]
auth0 apps rm
auth0 apps delete <app-id>
auth0 apps delete <app-id> --force
auth0 apps delete <app-id> <app-id2> <app-idn>
auth0 apps delete <app-id> <app-id2> <app-idn> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_domains_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 domains delete [flags]
auth0 domains rm
auth0 domains delete <domain-id>
auth0 domains delete <domain-id> --force
auth0 domains delete <domain-id> <domain-id2>
auth0 domains delete <domain-id> <domain-id2> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_logs_streams_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 logs streams delete [flags]
auth0 logs streams rm
auth0 logs streams delete <log-stream-id>
auth0 logs streams delete <log-stream-id> --force
auth0 logs streams delete <log-stream-id> <log-stream-id2>
auth0 logs streams delete <log-stream-id> <log-stream-id2> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_orgs_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 orgs delete [flags]
auth0 orgs rm
auth0 orgs delete <org-id>
auth0 orgs delete <org-id> --force
auth0 orgs delete <org-id> <org-id2> <org-idn>
auth0 orgs delete <org-id> <org-id2> <org-idn> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_roles_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 roles delete [flags]
auth0 roles rm
auth0 roles delete <role-id>
auth0 roles delete <role-id> --force
auth0 roles delete <role-id> <role-id2> <role-idn>
auth0 roles delete <role-id> <role-id2> <role-idn> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_rules_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ auth0 rules delete [flags]
auth0 rules rm
auth0 rules delete <rule-id>
auth0 rules delete <rule-id> --force
auth0 rules delete <rule-id> <rule-id2> <rule-idn>
auth0 rules delete <rule-id> <rule-id2> <rule-idn> --force
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_users_blocks_unblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ auth0 users blocks unblock [flags]
## Examples

```
auth0 users blocks unblock
auth0 users blocks unblock <user-id>
auth0 users blocks unblock <user-id> <user-id2> <user-idn>
```


Expand Down
2 changes: 2 additions & 0 deletions docs/auth0_users_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ auth0 users delete [flags]
auth0 users rm
auth0 users delete <user-id>
auth0 users delete <user-id> --force
auth0 users delete <user-id> <user-id2> <user-idn>
auth0 users delete <user-id> <user-id2> <user-idn> --force
```


Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/auth0/auth0-cli

go 1.20
go 1.21

require (
github.com/AlecAivazis/survey/v2 v2.3.7
Expand Down
26 changes: 16 additions & 10 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,29 +358,27 @@ func updateActionCmd(cli *cli) *cobra.Command {
}

func deleteActionCmd(cli *cli) *cobra.Command {
var inputs struct {
ID string
}

cmd := &cobra.Command{
Use: "delete",
Aliases: []string{"rm"},
Args: cobra.MaximumNArgs(1),
Short: "Delete an action",
Long: "Delete an action.\n\n" +
"To delete interactively, use `auth0 actions delete` with no arguments.\n\n" +
"To delete non-interactively, supply the action id and the `--force` flag to skip confirmation.",
Example: ` auth0 actions delete
auth0 actions rm
auth0 actions delete <action-id>
auth0 actions delete <action-id> --force`,
auth0 actions delete <action-id> --force
auth0 actions delete <action-id> <action-id2> <action-idn>
auth0 actions delete <action-id> <action-id2> <action-idn> --force`,
RunE: func(cmd *cobra.Command, args []string) error {
ids := make([]string, len(args))
if len(args) == 0 {
if err := actionID.Pick(cmd, &inputs.ID, cli.actionPickerOptions); err != nil {
if err := actionID.PickMany(cmd, &ids, cli.actionPickerOptions); err != nil {
return err
}
} else {
inputs.ID = args[0]
ids = append(ids, args...)
}

if !cli.force && canPrompt(cmd) {
Expand All @@ -389,8 +387,16 @@ func deleteActionCmd(cli *cli) *cobra.Command {
}
}

return ansi.Spinner("Deleting action", func() error {
return cli.api.Action.Delete(cmd.Context(), inputs.ID)
return ansi.Spinner("Deleting action(s)", func() error {
var errs []error
for _, id := range ids {
if id != "" {
if err := cli.api.Action.Delete(cmd.Context(), id); err != nil {
errs = append(errs, err)
}
}
}
return errors.Join(errs...)
})
},
}
Expand Down
34 changes: 19 additions & 15 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,30 +416,27 @@ func updateAPICmd(cli *cli) *cobra.Command {
}

func deleteAPICmd(cli *cli) *cobra.Command {
var inputs struct {
ID string
}

cmd := &cobra.Command{
Use: "delete",
Aliases: []string{"rm"},
Args: cobra.MaximumNArgs(1),
Short: "Delete an API",
Long: "Delete an API.\n\n" +
"To delete interactively, use `auth0 apis delete` with no arguments.\n\n" +
"To delete non-interactively, supply the API id and the `--force` flag to skip confirmation.",
Example: ` auth0 apis delete
auth0 apis rm
auth0 apis delete <api-id|api-audience>
auth0 apis delete <api-id|api-audience> --force`,
auth0 apis delete <api-id|api-audience> --force
auth0 apis delete <api-id|api-audience> <api-id2> <api-idn>
auth0 apis delete <api-id|api-audience> <api-id2> <api-idn> --force`,
RunE: func(cmd *cobra.Command, args []string) error {
var ids []string
if len(args) == 0 {
err := apiID.Pick(cmd, &inputs.ID, cli.apiPickerOptions)
if err != nil {
if err := apiID.PickMany(cmd, &ids, cli.apiPickerOptions); err != nil {
return err
}
} else {
inputs.ID = args[0]
ids = append(ids, args...)
}

if !cli.force && canPrompt(cmd) {
Expand All @@ -448,14 +445,21 @@ func deleteAPICmd(cli *cli) *cobra.Command {
}
}

return ansi.Spinner("Deleting API", func() error {
_, err := cli.api.ResourceServer.Read(cmd.Context(), url.PathEscape(inputs.ID))
return ansi.Spinner("Deleting API(s)", func() error {
var errs []error
for _, id := range ids {
if id != "" {
if _, err := cli.api.ResourceServer.Read(cmd.Context(), url.PathEscape(id)); err != nil {
errs = append(errs, fmt.Errorf("Unable to delete API (%s): %w", id, err))
continue
}

if err != nil {
return fmt.Errorf("Unable to delete API: %w", err)
if err := cli.api.ResourceServer.Delete(cmd.Context(), url.PathEscape(id)); err != nil {
errs = append(errs, fmt.Errorf("Unable to delete API (%s): %w", id, err))
}
}
}

return cli.api.ResourceServer.Delete(cmd.Context(), url.PathEscape(inputs.ID))
return errors.Join(errs...)
})
},
}
Expand Down
33 changes: 19 additions & 14 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,9 @@
}

func deleteAppCmd(cli *cli) *cobra.Command {
var inputs struct {
ID string
}

cmd := &cobra.Command{
Use: "delete",
Aliases: []string{"rm"},
Args: cobra.MaximumNArgs(1),
Short: "Delete an application",
Long: "Delete an application.\n\n" +
"To delete interactively, use `auth0 apps delete` with no arguments.\n\n" +
Expand All @@ -318,34 +313,44 @@
Example: ` auth0 apps delete
auth0 apps rm
auth0 apps delete <app-id>
auth0 apps delete <app-id> --force`,
auth0 apps delete <app-id> --force
auth0 apps delete <app-id> <app-id2> <app-idn>
auth0 apps delete <app-id> <app-id2> <app-idn> --force`,
RunE: func(cmd *cobra.Command, args []string) error {
ids := make([]string, len(args))
if len(args) == 0 {
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
err := appID.PickMany(cmd, &ids, cli.appPickerOptions())
if err != nil {
return err
}
} else {
inputs.ID = args[0]
ids = append(ids, args...)
}

if !cli.force && canPrompt(cmd) {
if tenant, _ := cli.Config.GetTenant(cli.tenant); tenant.ClientID == inputs.ID {

Check failure on line 331 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

undefined: inputs

Check failure on line 331 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Checks

undefined: inputs

Check failure on line 331 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: inputs

Check failure on line 331 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Build

undefined: inputs

Check failure on line 331 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Build

undefined: inputs

Check failure on line 331 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Build

undefined: inputs
cli.renderer.Warnf("Warning: You're about to delete the client used to authenticate the CLI. If deleted, the CLI will cease to operate once the access token has expired.", inputs.ID)

Check failure on line 332 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

undefined: inputs

Check failure on line 332 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Checks

undefined: inputs

Check failure on line 332 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: inputs

Check failure on line 332 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Build

undefined: inputs

Check failure on line 332 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Build

undefined: inputs

Check failure on line 332 in internal/cli/apps.go

View workflow job for this annotation

GitHub Actions / Build

undefined: inputs
}
if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed {
return nil
}
}

return ansi.Spinner("Deleting Application", func() error {
_, err := cli.api.Client.Read(cmd.Context(), inputs.ID)
return ansi.Spinner("Deleting Application(s)", func() error {
var errs []error
for _, id := range ids {
if id != "" {
if _, err := cli.api.Client.Read(cmd.Context(), id); err != nil {
errs = append(errs, fmt.Errorf("Unable to delete application (%s): %w", id, err))
continue
}

if err != nil {
return fmt.Errorf("Unable to delete application: %w", err)
if err := cli.api.Client.Delete(cmd.Context(), id); err != nil {
errs = append(errs, fmt.Errorf("Unable to delete application (%s): %w", id, err))
}
}
}

return cli.api.Client.Delete(cmd.Context(), inputs.ID)
return errors.Join(errs...)
})
},
}
Expand Down
21 changes: 21 additions & 0 deletions internal/cli/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ func (a *Argument) Pick(cmd *cobra.Command, result *string, fn pickerOptionsFunc
return nil
}

func (a *Argument) PickMany(cmd *cobra.Command, result *[]string, fn pickerOptionsFunc) error {
var opts pickerOptions
err := ansi.Waiting(func() error {
var err error
opts, err = fn(cmd.Context())
return err
})

if err != nil {
return err
}

var values []string
if err := askMultiSelect(a, &values, opts.labels()...); err != nil {
return err
}

*result = opts.getValues(values...)
return nil
}

func selectArgument(cmd *cobra.Command, a *Argument, value interface{}, options []string, defaultValue *string) error {
if canPrompt(cmd) {
return _select(a, value, options, defaultValue, false)
Expand Down
32 changes: 19 additions & 13 deletions internal/cli/custom_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -323,14 +324,9 @@ func updateCustomDomainCmd(cli *cli) *cobra.Command {
}

func deleteCustomDomainCmd(cli *cli) *cobra.Command {
var inputs struct {
ID string
}

cmd := &cobra.Command{
Use: "delete",
Aliases: []string{"rm"},
Args: cobra.MaximumNArgs(1),
Short: "Delete a custom domain",
Long: "Delete a custom domain.\n\n" +
"To delete interactively, use `auth0 domains delete` with no arguments.\n\n" +
Expand All @@ -339,15 +335,18 @@ func deleteCustomDomainCmd(cli *cli) *cobra.Command {
Example: ` auth0 domains delete
auth0 domains rm
auth0 domains delete <domain-id>
auth0 domains delete <domain-id> --force`,
auth0 domains delete <domain-id> --force
auth0 domains delete <domain-id> <domain-id2>
auth0 domains delete <domain-id> <domain-id2> --force`,
RunE: func(cmd *cobra.Command, args []string) error {
ids := make([]string, len(args))
if len(args) == 0 {
err := customDomainID.Pick(cmd, &inputs.ID, cli.customDomainsPickerOptions)
err := customDomainID.PickMany(cmd, &ids, cli.customDomainsPickerOptions)
if err != nil {
return err
}
} else {
inputs.ID = args[0]
ids = append(ids, args...)
}

if !cli.force && canPrompt(cmd) {
Expand All @@ -357,13 +356,20 @@ func deleteCustomDomainCmd(cli *cli) *cobra.Command {
}

return ansi.Spinner("Deleting custom domain", func() error {
_, err := cli.api.CustomDomain.Read(cmd.Context(), url.PathEscape(inputs.ID))

if err != nil {
return fmt.Errorf("Unable to delete custom domain: %w", err)
var errs []error
for _, id := range ids {
if id != "" {
if _, err := cli.api.CustomDomain.Read(cmd.Context(), url.PathEscape(id)); err != nil {
return fmt.Errorf("Unable to delete custom domain (%s): %w", id, err)
}

if err := cli.api.CustomDomain.Delete(cmd.Context(), url.PathEscape(id)); err != nil {
return fmt.Errorf("Unable to delete custom domain (%s): %w", id, err)
}
}
}

return cli.api.CustomDomain.Delete(cmd.Context(), url.PathEscape(inputs.ID))
return errors.Join(errs...)
})
},
}
Expand Down
Loading
Loading