Skip to content

Commit

Permalink
Dxcdt 586 select multiple ids for delete resource (#935)
Browse files Browse the repository at this point in the history
* Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908)

Bumps [github.com/auth0/go-auth0](https://github.com/auth0/go-auth0) from 1.2.0 to 1.3.0.
- [Release notes](https://github.com/auth0/go-auth0/releases)
- [Changelog](https://github.com/auth0/go-auth0/blob/main/CHANGELOG.md)
- [Commits](auth0/go-auth0@v1.2.0...v1.3.0)

---
updated-dependencies:
- dependency-name: github.com/auth0/go-auth0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* dxcdt-615-goreleaser-upgrade (#909)

* Fix: Remove or replace deprecations for GoReleaser config

Remove deprecated replacements
Replace deprecated brews tap
Replace deprecated scoop entries
Fix name_template to reflect exact current naming conventions

* DXCDT-582: Convert audience into a drop down in interactive mode in test token cmd (#906)

Convert audience into a drop down in interactive mode in test token cmd

* Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908)

Bumps [github.com/auth0/go-auth0](https://github.com/auth0/go-auth0) from 1.2.0 to 1.3.0.
- [Release notes](https://github.com/auth0/go-auth0/releases)
- [Changelog](https://github.com/auth0/go-auth0/blob/main/CHANGELOG.md)
- [Commits](auth0/go-auth0@v1.2.0...v1.3.0)

---
updated-dependencies:
- dependency-name: github.com/auth0/go-auth0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Sergiu Ghitea <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* DXCDT-582: Convert audience into a drop down in interactive mode in test token cmd (#906)

Convert audience into a drop down in interactive mode in test token cmd

Title Os for final release name fit

* Added batch deletes to actions

* Add batch deletions

Added batch deletion to actions command
Added batch deletion to apis command
Added batch deletion to apps command
Added batch deletion to custom domains command
Added batch deletion to log streams command
Added batch deletion for organizations command
Added batch deletion for roles command
Added batch deletion for rules command
Added batch deletion for users non-interactive command
Added batch deletion for user blocks non-interactive command
Update required golang minimum version

* DXCDT-595: Add ability to update signing alg for apis (#926)

* Add ability to update signing alg for apis

* Removing short alias

---------

Co-authored-by: Will Vedder <[email protected]>

* Bump github.com/auth0/go-auth0 from 1.3.0 to 1.3.1 (#929)

* Updated docs

* Simplify args loops

* Updates for code review

Ensure valid id before deletion process
Normalize messages for deletion
Remove unnecessary path escapes
Continue on read failure instead of attempting delete
Inform user of failed id on batch deletion
Only document at most two ids likely

* Validate input for askMultiSelect

* Update docs

* Remove unused variable

* Use Batch deletion for integration test cleanup

* Check to see if the tenant id is contained in the ids

* Remove unused ids variable in warning

* Fix print typo

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sergiu Ghitea <[email protected]>
Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
4 people authored Dec 5, 2023
1 parent 3ea19cd commit dba337f
Show file tree
Hide file tree
Showing 27 changed files with 319 additions and 279 deletions.
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
38 changes: 22 additions & 16 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"

"github.com/auth0/go-auth0/management"
Expand Down Expand Up @@ -302,14 +303,9 @@ func showAppCmd(cli *cli) *cobra.Command {
}

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 +314,44 @@ func deleteAppCmd(cli *cli) *cobra.Command {
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 {
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)
if tenant, _ := cli.Config.GetTenant(cli.tenant); slices.Contains(ids, tenant.ClientID) {
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.")
}
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

0 comments on commit dba337f

Please sign in to comment.