-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auth0 ips { check | unblock } (#297)
* auth0 ips: add check / unblock commands == Description This adds the `auth0 ips` command which supports two operations: - auth0 ips check <ip> - auth0 ips unblock <ip>
- Loading branch information
Showing
6 changed files
with
132 additions
and
1 deletion.
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,17 @@ | ||
package auth0 | ||
|
||
import "gopkg.in/auth0.v5/management" | ||
|
||
type AnomalyAPI interface { | ||
// Check if a given IP address is blocked via the multiple user accounts | ||
// trigger due to multiple failed logins. | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Anomaly/get_ips_by_id | ||
CheckIP(ip string, opts ...management.RequestOption) (isBlocked bool, err error) | ||
|
||
// Unblock an IP address currently blocked by the multiple user accounts | ||
// trigger due to multiple failed logins. | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Anomaly/delete_ips_by_id | ||
UnblockIP(ip string, opts ...management.RequestOption) (err 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,109 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
ipAddress = Argument{ | ||
Name: "IP", | ||
Help: "IP address to check.", | ||
} | ||
) | ||
|
||
func ipsCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "ips", | ||
Short: "Manage blocked IP addresses", | ||
Long: "Manage blocked IP addresses.", | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(checkIPCmd(cli)) | ||
cmd.AddCommand(unblockIPCmd(cli)) | ||
|
||
return cmd | ||
} | ||
|
||
func checkIPCmd(cli *cli) *cobra.Command { | ||
var inputs struct { | ||
IP string | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "check", | ||
Args: cobra.MaximumNArgs(1), | ||
Short: "Check IP address", | ||
Long: "Check whether a given IP address is blocked.", | ||
Example: "auth0 ips check <ip>", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
if err := ipAddress.Ask(cmd, &inputs.IP); err != nil { | ||
return err | ||
} | ||
} else { | ||
inputs.IP = args[0] | ||
} | ||
|
||
var isBlocked bool | ||
|
||
if err := ansi.Waiting(func() error { | ||
var err error | ||
isBlocked, err = cli.api.Anomaly.CheckIP(inputs.IP) | ||
return err | ||
}); err != nil { | ||
return fmt.Errorf("An unexpected error occurred: %w", err) | ||
} | ||
|
||
cli.renderer.Heading("IP") | ||
|
||
if isBlocked { | ||
cli.renderer.Infof("The IP %s is blocked", inputs.IP) | ||
} else { | ||
cli.renderer.Infof("The IP %s is not blocked", inputs.IP) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func unblockIPCmd(cli *cli) *cobra.Command { | ||
var inputs struct { | ||
IP string | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "unblock", | ||
Args: cobra.MaximumNArgs(1), | ||
Short: "Unblock IP address", | ||
Long: "Unblock an IP address which is currently blocked.", | ||
Example: "auth0 ips unblock <ip>", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
if err := ipAddress.Ask(cmd, &inputs.IP); err != nil { | ||
return err | ||
} | ||
} else { | ||
inputs.IP = args[0] | ||
} | ||
|
||
if err := ansi.Waiting(func() error { | ||
return cli.api.Anomaly.UnblockIP(inputs.IP) | ||
}); err != nil { | ||
return fmt.Errorf("An unexpected error occurred: %w", err) | ||
} | ||
|
||
cli.renderer.Heading("IP") | ||
cli.renderer.Infof("The IP %s was unblocked", inputs.IP) | ||
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