ipv6

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NetworkFirewallIPv6Cmd = &cobra.Command{
	Use:   "ipv6",
	Short: "Manage IPv6 firewall rules",
}
View Source
var NetworkFirewallIPv6CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Create an IPv6 firewall rule for a network",
	PreRunE: func(cmd *cobra.Command, args []string) error {

		if err := cli.Preflight(true)(cmd, args); err != nil {
			return err
		}

		return cli.Validate(cmd,
			cli.Required("networkId"),
			cli.Required("trafficType"),
			cli.Required("protocolType"),
			cli.Required("ipSource"),
			cli.Required("ipDestination"),
			cli.OneOf("trafficType", "Ingress", "Egress"),
			cli.OneOf("protocolType", "TCP", "UDP", "ICMP"),
		)
	},
	RunE: func(cmd *cobra.Command, args []string) error {

		token := cli.TokenFromContext(cmd.Context())
		zoneId := cli.ZoneIDFromContext(cmd.Context())
		if err := cli.LoadFromCobraFlags(cmd, &firewallIPv6CreateOptions); err != nil {
			return err
		}

		httpClient := http.NewClient(token)
		body := map[string]interface{}{
			"traffic_type":   firewallIPv6CreateOptions.TrafficType,
			"protocol_type":  firewallIPv6CreateOptions.ProtocolType,
			"ip_source":      firewallIPv6CreateOptions.IPSource,
			"ip_destination": firewallIPv6CreateOptions.IPDestination,
			"port_start":     firewallIPv6CreateOptions.PortStart,
			"port_end":       firewallIPv6CreateOptions.PortEnd,
			"icmp_code":      firewallIPv6CreateOptions.ICMPCode,
			"icmp_type":      firewallIPv6CreateOptions.ICMPType,
		}
		resp, err := httpClient.CreateIPv6FirewallRule(zoneId, firewallIPv6CreateOptions.NetworkID, body)
		if err != nil {
			slog.Error("failed to create IPv6 firewall rule", "error", err)
			return fmt.Errorf("failed to create IPv6 firewall rule: %w", err)
		}
		if resp.Data.Success {
			fmt.Println("IPv6 firewall rule created successfully.")
		} else {
			fmt.Println("Failed to create IPv6 firewall rule.")
		}
		return nil
	},
}
View Source
var NetworkFirewallIPv6DeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "Delete an IPv6 firewall rule from a network",
	PreRunE: func(cmd *cobra.Command, args []string) error {

		if err := cli.Preflight(true)(cmd, args); err != nil {
			return err
		}

		return cli.Validate(cmd,
			cli.Required("networkId"),
			cli.Required("ruleId"),
		)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		token := cli.TokenFromContext(cmd.Context())
		zoneId := cli.ZoneIDFromContext(cmd.Context())

		if err := cli.LoadFromCobraFlags(cmd, &firewallIPv6DeleteOpts); err != nil {
			return err
		}

		httpClient := http.NewClient(token)
		resp, err := httpClient.DeleteIPv6FirewallRule(zoneId, firewallIPv6DeleteOpts.NetworkId, firewallIPv6DeleteOpts.RuleId)
		if err != nil {
			slog.Error("failed to delete IPv6 firewall rule", "error", err)
			return fmt.Errorf("failed to delete IPv6 firewall rule: %w", err)
		}

		if resp.Data.Success {
			fmt.Println("IPv6 firewall rule deleted successfully.")
		} else {
			return fmt.Errorf("failed to delete IPv6 firewall rule")
		}
		return nil
	},
}
View Source
var NetworkFirewallIPv6ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List IPv6 firewall rules for a network",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if err := cli.Preflight(true)(cmd, args); err != nil {
			return err
		}
		return cli.Validate(cmd,
			cli.Required("networkId"),
		)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		token := cli.TokenFromContext(cmd.Context())
		zoneId := cli.ZoneIDFromContext(cmd.Context())

		if err := cli.LoadFromCobraFlags(cmd, &firewallIPv6ListOpts); err != nil {
			return err
		}

		httpClient := http.NewClient(token)
		resp, err := httpClient.ListIPv6FirewallRules(zoneId, firewallIPv6ListOpts.NetworkId)
		if err != nil {
			slog.Error("failed to list IPv6 firewall rules", "error", err)
			return fmt.Errorf("failed to list IPv6 firewall rules: %w", err)
		}

		if len(resp.Data) == 0 {
			fmt.Println("No IPv6 firewall rules found.")
			return nil
		}

		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"ID", "Protocol", "TrafficType", "Source", "Destination", "Status", "CreatedAt"})
		for _, rule := range resp.Data {
			table.Append([]string{rule.ID, rule.Protocol, rule.TrafficType, rule.IPSource, rule.IPDestination, rule.Status, fmt.Sprintf("%d", rule.CreatedAt)})
		}
		table.Render()
		return nil
	},
}

Functions

This section is empty.

Types

type NetworkFirewallIPv6CreateOptions

type NetworkFirewallIPv6CreateOptions struct {
	ZoneID        string `flag:"zoneId" usage:"Zone ID to use (optional if default.zoneId is set in config)"`
	NetworkID     string `flag:"networkId"`
	TrafficType   string `flag:"trafficType"`
	ProtocolType  string `flag:"protocolType"`
	IPSource      string `flag:"ipSource"`
	IPDestination string `flag:"ipDestination"`
	PortStart     int    `flag:"portStart"`
	PortEnd       int    `flag:"portEnd"`
	ICMPCode      int    `flag:"icmpCode"`
	ICMPType      int    `flag:"icmpType"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL