(cli *cli)
| 25 | } |
| 26 | |
| 27 | func listUserBlocksCmd(cli *cli) *cobra.Command { |
| 28 | var inputs struct { |
| 29 | userIdentifier string |
| 30 | } |
| 31 | |
| 32 | cmd := &cobra.Command{ |
| 33 | Use: "list", |
| 34 | Args: cobra.MaximumNArgs(1), |
| 35 | Short: "List brute-force protection blocks for a given user", |
| 36 | Long: "List brute-force protection blocks for a given user by user ID, username, phone number or email.", |
| 37 | Example: ` auth0 users blocks list <user-id|username|email|phone-number> |
| 38 | auth0 users blocks list <user-id|username|email|phone-number> --json |
| 39 | auth0 users blocks list <user-id|username|email|phone-number> --json-compact |
| 40 | auth0 users blocks list "auth0|61b5b6e90783fa19f7c57dad" |
| 41 | auth0 users blocks list "frederik@travel0.com" |
| 42 | auth0 users blocks list <user-id|username|email|phone-number> --csv`, |
| 43 | RunE: func(cmd *cobra.Command, args []string) error { |
| 44 | if len(args) == 0 { |
| 45 | if err := userIdentifier.Ask(cmd, &inputs.userIdentifier); err != nil { |
| 46 | return err |
| 47 | } |
| 48 | } else { |
| 49 | inputs.userIdentifier = args[0] |
| 50 | } |
| 51 | |
| 52 | var userBlocks []*management.UserBlock |
| 53 | err := ansi.Waiting(func() (err error) { |
| 54 | userBlocks, err = cli.api.User.Blocks(cmd.Context(), inputs.userIdentifier) |
| 55 | if mErr, ok := err.(management.Error); ok && mErr.Status() != http.StatusBadRequest { |
| 56 | return err |
| 57 | } |
| 58 | |
| 59 | userBlocks, err = cli.api.User.BlocksByIdentifier(cmd.Context(), inputs.userIdentifier) |
| 60 | return err |
| 61 | }) |
| 62 | if err != nil { |
| 63 | return fmt.Errorf("failed to list user blocks for user with ID %q: %w", inputs.userIdentifier, err) |
| 64 | } |
| 65 | |
| 66 | cli.renderer.UserBlocksList(userBlocks) |
| 67 | return nil |
| 68 | }, |
| 69 | } |
| 70 | |
| 71 | cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") |
| 72 | cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.") |
| 73 | cmd.Flags().BoolVar(&cli.csv, "csv", false, "Output in csv format.") |
| 74 | cmd.MarkFlagsMutuallyExclusive("json", "json-compact", "csv") |
| 75 | |
| 76 | return cmd |
| 77 | } |
| 78 | |
| 79 | func deleteUserBlocksCmd(cli *cli) *cobra.Command { |
| 80 | cmd := &cobra.Command{ |
no test coverage detected