diff --git a/docs/auth0_users.md b/docs/auth0_users.md index c86055516..695761429 100644 --- a/docs/auth0_users.md +++ b/docs/auth0_users.md @@ -15,6 +15,5 @@ Manage resources for users. - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_blocks.md b/docs/auth0_users_blocks.md index 38ce725ea..d652cf667 100644 --- a/docs/auth0_users_blocks.md +++ b/docs/auth0_users_blocks.md @@ -8,4 +8,5 @@ Manage brute-force protection user blocks. ## Commands - [auth0 users blocks list](auth0_users_blocks_list.md) - List brute-force protection blocks for a given user +- [auth0 users blocks unblock](auth0_users_blocks_unblock.md) - Remove brute-force protection blocks for a given user diff --git a/docs/auth0_users_blocks_list.md b/docs/auth0_users_blocks_list.md index a02ece2b8..17fe1eb8f 100644 --- a/docs/auth0_users_blocks_list.md +++ b/docs/auth0_users_blocks_list.md @@ -38,5 +38,6 @@ auth0 users blocks list [flags] ## Related Commands - [auth0 users blocks list](auth0_users_blocks_list.md) - List brute-force protection blocks for a given user +- [auth0 users blocks unblock](auth0_users_blocks_unblock.md) - Remove brute-force protection blocks for a given user diff --git a/docs/auth0_users_blocks_unblock.md b/docs/auth0_users_blocks_unblock.md new file mode 100644 index 000000000..38276b934 --- /dev/null +++ b/docs/auth0_users_blocks_unblock.md @@ -0,0 +1,37 @@ +--- +layout: default +--- +# auth0 users blocks unblock + +Remove brute-force protection blocks for a given user. + +## Usage +``` +auth0 users blocks unblock [flags] +``` + +## Examples + +``` + auth0 users blocks unblock +``` + + + + +## InheritedFlags + +``` + --debug Enable debug mode. + --no-color Disable colors. + --no-input Disable interactivity. + --tenant string Specific tenant to use. +``` + + +## Related Commands + +- [auth0 users blocks list](auth0_users_blocks_list.md) - List brute-force protection blocks for a given user +- [auth0 users blocks unblock](auth0_users_blocks_unblock.md) - Remove brute-force protection blocks for a given user + + diff --git a/docs/auth0_users_create.md b/docs/auth0_users_create.md index da83f238c..3bb48df10 100644 --- a/docs/auth0_users_create.md +++ b/docs/auth0_users_create.md @@ -57,7 +57,6 @@ auth0 users create [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_delete.md b/docs/auth0_users_delete.md index 77c8a0235..f78707bf7 100644 --- a/docs/auth0_users_delete.md +++ b/docs/auth0_users_delete.md @@ -51,7 +51,6 @@ auth0 users delete [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_import.md b/docs/auth0_users_import.md index ffac67f59..513264647 100644 --- a/docs/auth0_users_import.md +++ b/docs/auth0_users_import.md @@ -52,7 +52,6 @@ auth0 users import [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_open.md b/docs/auth0_users_open.md index 8417ea860..4fde0b9f8 100644 --- a/docs/auth0_users_open.md +++ b/docs/auth0_users_open.md @@ -40,7 +40,6 @@ auth0 users open [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_search.md b/docs/auth0_users_search.md index 0654dddb3..695786b0b 100644 --- a/docs/auth0_users_search.md +++ b/docs/auth0_users_search.md @@ -51,7 +51,6 @@ auth0 users search [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_show.md b/docs/auth0_users_show.md index 2e040d1cb..8724aa078 100644 --- a/docs/auth0_users_show.md +++ b/docs/auth0_users_show.md @@ -46,7 +46,6 @@ auth0 users show [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/docs/auth0_users_unblock.md b/docs/auth0_users_unblock.md deleted file mode 100644 index f836a8c94..000000000 --- a/docs/auth0_users_unblock.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -layout: default ---- -# auth0 users unblock - -Remove brute-force protection blocks for a given user. - -## Usage -``` -auth0 users unblock [flags] -``` - -## Examples - -``` - auth0 users unblock -``` - - - - -## InheritedFlags - -``` - --debug Enable debug mode. - --no-color Disable colors. - --no-input Disable interactivity. - --tenant string Specific tenant to use. -``` - - -## Related Commands - -- [auth0 users blocks](auth0_users_blocks.md) - Manage brute-force protection user blocks -- [auth0 users create](auth0_users_create.md) - Create a new user -- [auth0 users delete](auth0_users_delete.md) - Delete a user -- [auth0 users import](auth0_users_import.md) - Import users from schema -- [auth0 users open](auth0_users_open.md) - Open the user's settings page -- [auth0 users roles](auth0_users_roles.md) - Manage a user's roles -- [auth0 users search](auth0_users_search.md) - Search for users -- [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user -- [auth0 users update](auth0_users_update.md) - Update a user - - diff --git a/docs/auth0_users_update.md b/docs/auth0_users_update.md index bb8861b10..74d4fe212 100644 --- a/docs/auth0_users_update.md +++ b/docs/auth0_users_update.md @@ -55,7 +55,6 @@ auth0 users update [flags] - [auth0 users roles](auth0_users_roles.md) - Manage a user's roles - [auth0 users search](auth0_users_search.md) - Search for users - [auth0 users show](auth0_users_show.md) - Show an existing user -- [auth0 users unblock](auth0_users_unblock.md) - Remove brute-force protection blocks for a given user - [auth0 users update](auth0_users_update.md) - Update a user diff --git a/internal/cli/users.go b/internal/cli/users.go index d43fc0952..e9cd7cdea 100644 --- a/internal/cli/users.go +++ b/internal/cli/users.go @@ -126,7 +126,6 @@ func usersCmd(cli *cli) *cobra.Command { cmd.AddCommand(userRolesCmd(cli)) cmd.AddCommand(openUserCmd(cli)) cmd.AddCommand(userBlocksCmd(cli)) - cmd.AddCommand(deleteUserBlocksCmd(cli)) cmd.AddCommand(importUsersCmd(cli)) return cmd @@ -531,96 +530,6 @@ func openUserCmd(cli *cli) *cobra.Command { return cmd } -func userBlocksCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "blocks", - Short: "Manage brute-force protection user blocks", - Long: "Manage brute-force protection user blocks.", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(listUserBlocksCmd(cli)) - return cmd -} - -func listUserBlocksCmd(cli *cli) *cobra.Command { - var inputs struct { - userID string - } - - cmd := &cobra.Command{ - Use: "list", - Args: cobra.MaximumNArgs(1), - Short: "List brute-force protection blocks for a given user", - Long: "List brute-force protection blocks for a given user.", - Example: ` auth0 users blocks list - auth0 users blocks list --json`, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if err := userID.Ask(cmd, &inputs.userID); err != nil { - return err - } - } else { - inputs.userID = args[0] - } - - var userBlocks []*management.UserBlock - - err := ansi.Waiting(func() error { - var err error - userBlocks, err = cli.api.User.Blocks(inputs.userID) - return err - }) - - if err != nil { - return fmt.Errorf("Unable to load user blocks %v, error: %w", inputs.userID, err) - } - - cli.renderer.UserBlocksList(userBlocks) - return nil - }, - } - - cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") - - return cmd -} - -func deleteUserBlocksCmd(cli *cli) *cobra.Command { - var inputs struct { - userID string - } - - cmd := &cobra.Command{ - Use: "unblock", - Args: cobra.MaximumNArgs(1), - Short: "Remove brute-force protection blocks for a given user", - Long: "Remove brute-force protection blocks for a given user.", - Example: ` auth0 users unblock `, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if err := userID.Ask(cmd, &inputs.userID); err != nil { - return err - } - } else { - inputs.userID = args[0] - } - - err := ansi.Spinner("Deleting blocks for user...", func() error { - return cli.api.User.Unblock(inputs.userID) - }) - - if err != nil { - return err - } - - return nil - }, - } - - return cmd -} - func importUsersCmd(cli *cli) *cobra.Command { var inputs struct { Connection string diff --git a/internal/cli/users_blocks.go b/internal/cli/users_blocks.go new file mode 100644 index 000000000..3b71a20bb --- /dev/null +++ b/internal/cli/users_blocks.go @@ -0,0 +1,98 @@ +package cli + +import ( + "fmt" + + "github.com/auth0/go-auth0/management" + "github.com/spf13/cobra" + + "github.com/auth0/auth0-cli/internal/ansi" +) + +func userBlocksCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "blocks", + Short: "Manage brute-force protection user blocks", + Long: "Manage brute-force protection user blocks.", + } + + cmd.SetUsageTemplate(resourceUsageTemplate()) + cmd.AddCommand(listUserBlocksCmd(cli)) + cmd.AddCommand(deleteUserBlocksCmd(cli)) + + return cmd +} + +func listUserBlocksCmd(cli *cli) *cobra.Command { + var inputs struct { + userID string + } + + cmd := &cobra.Command{ + Use: "list", + Args: cobra.MaximumNArgs(1), + Short: "List brute-force protection blocks for a given user", + Long: "List brute-force protection blocks for a given user.", + Example: ` auth0 users blocks list + auth0 users blocks list --json`, + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 0 { + if err := userID.Ask(cmd, &inputs.userID); err != nil { + return err + } + } else { + inputs.userID = args[0] + } + + var userBlocks []*management.UserBlock + err := ansi.Waiting(func() (err error) { + userBlocks, err = cli.api.User.Blocks(inputs.userID) + return err + }) + if err != nil { + return fmt.Errorf("failed to list user blocks for user with ID %s: %w", inputs.userID, err) + } + + cli.renderer.UserBlocksList(userBlocks) + return nil + }, + } + + cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") + + return cmd +} + +func deleteUserBlocksCmd(cli *cli) *cobra.Command { + var inputs struct { + userID string + } + + cmd := &cobra.Command{ + Use: "unblock", + Args: cobra.MaximumNArgs(1), + Short: "Remove brute-force protection blocks for a given user", + Long: "Remove brute-force protection blocks for a given user.", + Example: ` auth0 users blocks unblock `, + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 0 { + if err := userID.Ask(cmd, &inputs.userID); err != nil { + return err + } + } else { + inputs.userID = args[0] + } + + err := ansi.Spinner("Unblocking user...", func() error { + return cli.api.User.Unblock(inputs.userID) + }) + if err != nil { + return fmt.Errorf("failed to unblock user with ID %s: %w", inputs.userID, err) + } + + return nil + }, + } + + return cmd +}