-
Notifications
You must be signed in to change notification settings - Fork 55
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
CLI-80: users blocks commands #219
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16d9ed7
CLI-80: user-blocks commands with user_id
mhsu-auth0 8bdd9d3
rename commands
mhsu-auth0 57fcffb
fix linter
mhsu-auth0 84ae950
Merge branch 'main' into user-blocks
mhsu-auth0 caa106c
update and rename commands
mhsu-auth0 98917ff
Merge branch 'main' into user-blocks
mhsu-auth0 cec7305
Fix formatting
mhsu-auth0 2bd0d8b
fix formatting
mhsu-auth0 0ef6f36
use argument instead of flag
mhsu-auth0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:generate mockgen -source=user.go -destination=user_mock.go -package=auth0 | ||
|
||
package auth0 | ||
|
||
import "gopkg.in/auth0.v5/management" | ||
|
||
type UserAPI interface { | ||
// Retrieves a list of blocked IP addresses of a particular user. | ||
Blocks(id string, opts ...management.RequestOption) ([]*management.UserBlock, error) | ||
|
||
// Unblock a user that was blocked due to an excessive amount of incorrectly | ||
// provided credentials. | ||
Unblock(id string, opts ...management.RequestOption) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
func usersCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "users", | ||
Short: "Manage resources for users", | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(userBlocksCmd(cli)) | ||
return cmd | ||
} | ||
|
||
func userBlocksCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "blocks", | ||
Short: "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: | ||
|
||
auth0 users blocks list <User ID> | ||
cyx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
prepareInteractivity(cmd) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) > 0 { | ||
inputs.userID = args[0] | ||
cyx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
return errors.New("User ID is required.") | ||
} | ||
|
||
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 | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func deleteUserBlocksCmd(cli *cli) *cobra.Command { | ||
var inputs struct { | ||
userID string | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
mhsu-auth0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Args: cobra.MaximumNArgs(1), | ||
Short: "Delete brute-force protection blocks for a given user", | ||
Long: `Delete brute-force protection blocks for a given user: | ||
|
||
auth0 users blocks delete <User ID> | ||
`, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
prepareInteractivity(cmd) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) > 0 { | ||
inputs.userID = args[0] | ||
mhsu-auth0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
return errors.New("User ID is required.") | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package display | ||
|
||
import ( | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
type userBlockView struct { | ||
Identifier string | ||
IP string | ||
} | ||
|
||
func (v *userBlockView) AsTableHeader() []string { | ||
return []string{"Identifier", "IP"} | ||
} | ||
|
||
func (v *userBlockView) AsTableRow() []string { | ||
return []string{v.Identifier, v.IP} | ||
} | ||
|
||
func (v *userBlockView) KeyValues() [][]string { | ||
return [][]string{ | ||
[]string{"Identifier", v.Identifier}, | ||
[]string{"IP", v.IP}, | ||
} | ||
} | ||
|
||
func (r *Renderer) UserBlocksList(userBlocks []*management.UserBlock) { | ||
resource := "user blocks" | ||
|
||
r.Heading(resource) | ||
|
||
if len(userBlocks) == 0 { | ||
r.EmptyState(resource) | ||
return | ||
} | ||
|
||
var res []View | ||
|
||
for _, userBlock := range userBlocks { | ||
res = append(res, &userBlockView{ | ||
Identifier: *userBlock.Identifier, | ||
IP: *userBlock.IP, | ||
}) | ||
} | ||
|
||
r.Results(res) | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not yet, deleting user blocks only require
update:users