Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NetworkVpnCmd = &cobra.Command{
Use: "vpn",
Short: "Manage VPN for a network",
}
NetworkVpnCmd is the root command for VPN management.
View Source
var NetworkVpnDisableCmd = &cobra.Command{ Use: "disable", Short: "Disable VPN 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, &vpnDisableOpts); err != nil { return err } client := http.NewClient(token) resp, err := client.DisableNetworkVpn(zoneID, vpnDisableOpts.NetworkID) if err != nil { if strings.Contains(err.Error(), "The network should be Implemented") { slog.Error("network not implemented, need to connect instance", "error", err) return fmt.Errorf("first need to connect an instance to this network") } slog.Error("failed to disable VPN", "error", err) return fmt.Errorf("error: %w", err) } if resp.Data.Success { slog.Info("VPN disable started successfully") fmt.Println("VPN disable started successfully.") } else { slog.Error("VPN disable unsuccessful", "response", resp) return fmt.Errorf("failed to start VPN disable") } return nil }, }
NetworkVpnDisableCmd is the command to disable VPN for a network.
View Source
var NetworkVpnEnableCmd = &cobra.Command{ Use: "enable", Short: "Enable VPN 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, &vpnEnableOpts); err != nil { return err } client := http.NewClient(token) resp, err := client.EnableNetworkVpn(zoneID, vpnEnableOpts.NetworkID) if err != nil { if strings.Contains(err.Error(), "The network should be Implemented") { slog.Error("network not implemented, need to connect instance", "error", err) return fmt.Errorf("first need to connect an instance to this network") } slog.Error("failed to enable VPN", "error", err) return fmt.Errorf("error: %w", err) } if resp.Data.Success { slog.Info("VPN enable started successfully") fmt.Println("VPN enable started successfully.") } else { slog.Error("VPN enable unsuccessful", "response", resp) return fmt.Errorf("failed to start VPN enable") } return nil }, }
NetworkVpnEnableCmd is the command to enable VPN for a network.
View Source
var NetworkVpnShowCmd = &cobra.Command{ Use: "show", Short: "Show VPN details 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, &vpnShowOpts); err != nil { return err } client := http.NewClient(token) resp, err := client.GetNetworkVpnDetails(zoneID, vpnShowOpts.NetworkID) if err != nil { slog.Error("failed to get VPN details", "error", err) return fmt.Errorf("error: %w", err) } fmt.Printf("VPN IP Address: %s\nUsername: %s\nPassword: %s\nPreshared Key: %s\nStatus: %s\n", resp.Data.IPAddress, resp.Data.Username, resp.Data.Password, resp.Data.PresharedKey, resp.Data.Status) return nil }, }
NetworkVpnShowCmd is the command to show VPN details for a network.
View Source
var NetworkVpnUpdateCmd = &cobra.Command{ Use: "update", Short: "Update VPN credentials 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, &vpnUpdateOpts); err != nil { return err } client := http.NewClient(token) resp, err := client.UpdateNetworkVpnCredentials(zoneID, vpnUpdateOpts.NetworkID) if err != nil { if strings.Contains(err.Error(), "The network should be Implemented") { slog.Error("network not implemented, need to connect instance", "error", err) return fmt.Errorf("first need to connect an instance to this network") } slog.Error("failed to update VPN credentials", "error", err) return fmt.Errorf("error: %w", err) } if resp.Data.Success { slog.Info("VPN credentials update started successfully") fmt.Println("VPN credentials update started successfully.") } else { slog.Error("VPN credentials update unsuccessful", "response", resp) return fmt.Errorf("failed to start VPN credentials update") } return nil }, }
NetworkVpnUpdateCmd is the command to update VPN credentials for a network.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.