(cli *cli)
| 612 | } |
| 613 | |
| 614 | func createNetworkACLCmd(cli *cli) *cobra.Command { |
| 615 | var inputs struct { |
| 616 | Description string |
| 617 | Active bool |
| 618 | ActiveStr string // Added for handling --active true/false. |
| 619 | Priority int |
| 620 | RuleJSON string |
| 621 | Action string |
| 622 | RedirectURI string |
| 623 | ASNs []int |
| 624 | CountryCodes []string |
| 625 | SubdivCodes []string |
| 626 | IPv4CIDRs []string |
| 627 | IPv6CIDRs []string |
| 628 | JA3 []string |
| 629 | JA4 []string |
| 630 | UserAgents []string |
| 631 | Scope string |
| 632 | isMatchRule bool |
| 633 | } |
| 634 | |
| 635 | cmd := &cobra.Command{ |
| 636 | Use: "create", |
| 637 | Args: cobra.NoArgs, |
| 638 | Short: "Create a new network ACL", |
| 639 | Long: `Create a new network ACL. |
| 640 | To create interactively, use "auth0 network-acl create" with no arguments. |
| 641 | To create non-interactively, supply the required parameters (description, active, priority, and rule) through flags. |
| 642 | The --rule parameter is required and must contain a valid JSON object with action, scope, and match properties.`, |
| 643 | Example: ` auth0 network-acl create |
| 644 | auth0 network-acl create --description "Block IPs" --priority 1 --active true --rule '{"action":{"block":true},"scope":"tenant","match":{"ipv4_cidrs":["192.168.1.0/24","10.0.0.0/8"]}}' |
| 645 | auth0 network-acl create --description "Geo Block" --priority 2 --active true --rule '{"action":{"block":true},"scope":"authentication","match":{"geo_country_codes":["US","CA"]}}' |
| 646 | auth0 network-acl create --description "Redirect Traffic" --priority 3 --active true --rule '{"action":{"redirect":true,"redirect_uri":"https://example.com"},"scope":"management","match":{"ipv4_cidrs":["192.168.1.0/24"]}}' |
| 647 | auth0 network-acl create -d "Block Bots" -p 4 --active true --rule '{"action":{"block":true},"scope":"tenant","match":{"user_agents":["badbot/*","malicious/*"],"ja3_fingerprints":["deadbeef","cafebabe"]}}' |
| 648 | auth0 network-acl create --description "Complex Rule" --priority 5 --active true --rule '{"action":{"block":true},"scope":"tenant","match":{"ipv4_cidrs":["192.168.1.0/24"],"geo_country_codes":["US"]}}'`, |
| 649 | RunE: func(cmd *cobra.Command, args []string) error { |
| 650 | // Check if we're in non-interactive mode (flags provided) but rule JSON is missing. |
| 651 | if !canPrompt(cmd) && !cmd.Flags().Changed("rule") { |
| 652 | return fmt.Errorf("the --rule parameter is required for non-interactive mode. Please provide a valid JSON rule") |
| 653 | } |
| 654 | |
| 655 | // Parse the active flag if provided. |
| 656 | if cmd.Flags().Changed("active") { |
| 657 | switch inputs.ActiveStr { |
| 658 | case "true": |
| 659 | inputs.Active = true |
| 660 | case "false": |
| 661 | inputs.Active = false |
| 662 | default: |
| 663 | return fmt.Errorf("--active must be either 'true' or 'false', got %q", inputs.ActiveStr) |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | // Check if rule JSON was provided. |
| 668 | if cmd.Flags().Changed("rule") { |
| 669 | // Parse the rule JSON. |
| 670 | var rule map[string]interface{} |
| 671 | if err := json.Unmarshal([]byte(inputs.RuleJSON), &rule); err != nil { |
no test coverage detected