| 31 | } |
| 32 | |
| 33 | func checkIPCmd(cli *cli) *cobra.Command { |
| 34 | var inputs struct { |
| 35 | IP string |
| 36 | } |
| 37 | |
| 38 | cmd := &cobra.Command{ |
| 39 | Use: "check", |
| 40 | Args: cobra.MaximumNArgs(1), |
| 41 | Short: "Check IP address", |
| 42 | Long: "Check if a given IP address is blocked via the Suspicious IP Throttling due to " + |
| 43 | "multiple suspicious attempts.", |
| 44 | Example: ` auth0 protection suspicious-ip-throttling ips check |
| 45 | auth0 ap sit ips check <ip> |
| 46 | auth0 ap sit ips check "178.178.178.178"`, |
| 47 | RunE: func(cmd *cobra.Command, args []string) error { |
| 48 | if len(args) == 0 { |
| 49 | if err := ipAddress.Ask(cmd, &inputs.IP); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | } else { |
| 53 | inputs.IP = args[0] |
| 54 | } |
| 55 | |
| 56 | var isBlocked bool |
| 57 | if err := ansi.Waiting(func() (err error) { |
| 58 | isBlocked, err = cli.api.Anomaly.CheckIP(cmd.Context(), inputs.IP) |
| 59 | return err |
| 60 | }); err != nil { |
| 61 | return fmt.Errorf("failed to check if IP %q is blocked: %w", inputs.IP, err) |
| 62 | } |
| 63 | |
| 64 | cli.renderer.Heading("ip") |
| 65 | |
| 66 | if isBlocked { |
| 67 | cli.renderer.Infof("The IP %s is blocked", inputs.IP) |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | cli.renderer.Infof("The IP %s is not blocked.", inputs.IP) |
| 72 | return nil |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | return cmd |
| 77 | } |
| 78 | |
| 79 | func unblockIPCmd(cli *cli) *cobra.Command { |
| 80 | var inputs struct { |