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-333: Nest users unblock under users blocks unblock #617

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion docs/auth0_users.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions docs/auth0_users_blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions docs/auth0_users_blocks_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


37 changes: 37 additions & 0 deletions docs/auth0_users_blocks_unblock.md
Original file line number Diff line number Diff line change
@@ -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 <user-id>
```




## 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


1 change: 0 additions & 1 deletion docs/auth0_users_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


1 change: 0 additions & 1 deletion docs/auth0_users_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


1 change: 0 additions & 1 deletion docs/auth0_users_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


1 change: 0 additions & 1 deletion docs/auth0_users_open.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


1 change: 0 additions & 1 deletion docs/auth0_users_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


1 change: 0 additions & 1 deletion docs/auth0_users_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


45 changes: 0 additions & 45 deletions docs/auth0_users_unblock.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/auth0_users_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


91 changes: 0 additions & 91 deletions internal/cli/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <user-id>
auth0 users blocks list <user-id> --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 <user-id>`,
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
Expand Down
98 changes: 98 additions & 0 deletions internal/cli/users_blocks.go
Original file line number Diff line number Diff line change
@@ -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 <user-id>
auth0 users blocks list <user-id> --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 <user-id>`,
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
}