From 43f085bcef1264e1a4f18393c3f5bfb93e41ff69 Mon Sep 17 00:00:00 2001 From: Alexandru Claudius Virtopeanu Date: Fri, 6 Dec 2024 16:11:47 +0200 Subject: [PATCH] replace ipsec completions to work with regional urls --- commands/vpn/ipsec/gateway/delete.go | 9 ++++----- commands/vpn/ipsec/gateway/get.go | 9 ++++----- commands/vpn/ipsec/gateway/update.go | 8 ++++---- commands/vpn/ipsec/tunnel/create.go | 9 ++++----- commands/vpn/ipsec/tunnel/delete.go | 20 +++++++++++--------- commands/vpn/ipsec/tunnel/get.go | 20 +++++++++++--------- commands/vpn/ipsec/tunnel/list.go | 9 ++++----- commands/vpn/ipsec/tunnel/update.go | 20 +++++++++++--------- 8 files changed, 53 insertions(+), 51 deletions(-) diff --git a/commands/vpn/ipsec/gateway/delete.go b/commands/vpn/ipsec/gateway/delete.go index 5e1f28ee1..c413f1730 100644 --- a/commands/vpn/ipsec/gateway/delete.go +++ b/commands/vpn/ipsec/gateway/delete.go @@ -13,7 +13,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/pkg/confirm" "github.com/ionos-cloud/ionosctl/v6/pkg/functional" vpn "github.com/ionos-cloud/sdk-go-vpn" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -52,10 +51,10 @@ func Delete() *core.Command { InitClient: true, }) - cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) cmd.AddBoolFlag(constants.ArgAll, constants.ArgAllShort, false, fmt.Sprintf("Delete all gateways. Required or --%s", constants.FlagGatewayID)) diff --git a/commands/vpn/ipsec/gateway/get.go b/commands/vpn/ipsec/gateway/get.go index 689167c85..f58622c31 100644 --- a/commands/vpn/ipsec/gateway/get.go +++ b/commands/vpn/ipsec/gateway/get.go @@ -12,7 +12,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/resource2table" "github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter" "github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -53,10 +52,10 @@ func Get() *core.Command { InitClient: true, }) - cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) cmd.Command.SilenceUsage = true cmd.Command.Flags().SortFlags = false diff --git a/commands/vpn/ipsec/gateway/update.go b/commands/vpn/ipsec/gateway/update.go index 0caa258f7..dc723f17b 100644 --- a/commands/vpn/ipsec/gateway/update.go +++ b/commands/vpn/ipsec/gateway/update.go @@ -115,10 +115,10 @@ func Update() *core.Command { InitClient: true, }) - cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) cmd.AddStringFlag(constants.FlagName, constants.FlagNameShort, "", "Name of the IPSec Gateway", core.RequiredFlagOption()) cmd.AddStringFlag(constants.FlagDescription, "", "", "Description of the IPSec Gateway") diff --git a/commands/vpn/ipsec/tunnel/create.go b/commands/vpn/ipsec/tunnel/create.go index 0733c8f7a..d599fcdc1 100644 --- a/commands/vpn/ipsec/tunnel/create.go +++ b/commands/vpn/ipsec/tunnel/create.go @@ -14,7 +14,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" "github.com/ionos-cloud/ionosctl/v6/pkg/pointer" vpn "github.com/ionos-cloud/sdk-go-vpn" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -64,10 +63,10 @@ func Create() *core.Command { }, }) - cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) cmd.AddStringFlag(constants.FlagName, "", "", "Name of the IPSec Tunnel", core.RequiredFlagOption()) cmd.AddStringFlag(constants.FlagDescription, "", "", "Description of the IPSec Tunnel") diff --git a/commands/vpn/ipsec/tunnel/delete.go b/commands/vpn/ipsec/tunnel/delete.go index 3e3bce67e..bce1b741c 100644 --- a/commands/vpn/ipsec/tunnel/delete.go +++ b/commands/vpn/ipsec/tunnel/delete.go @@ -13,7 +13,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/pkg/confirm" "github.com/ionos-cloud/ionosctl/v6/pkg/functional" vpn "github.com/ionos-cloud/sdk-go-vpn" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -55,14 +54,17 @@ func Delete() *core.Command { }, }) - cmd.AddStringFlag(constants.FlagGatewayID, "", "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) - cmd.AddStringFlag(constants.FlagTunnelID, constants.FlagIdShort, "", "The ID of the IPSec Tunnel you want to delete", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagTunnelID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.TunnelIDs(viper.GetString(core.GetFlagName(cmd.NS, constants.FlagTunnelID))), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) + cmd.AddStringFlag(constants.FlagTunnelID, constants.FlagIdShort, "", "The ID of the IPSec Tunnel you want to delete", + core.RequiredFlagOption(), + core.WithCompletion(func() []string { + gatewayID := viper.GetString(core.GetFlagName(cmd.NS, constants.FlagGatewayID)) + return completer.TunnelIDs(gatewayID) + }, constants.VPNApiRegionalURL), + ) cmd.AddBoolFlag(constants.ArgAll, constants.ArgAllShort, false, fmt.Sprintf("Delete all tunnels. Required or --%s", constants.FlagTunnelID)) diff --git a/commands/vpn/ipsec/tunnel/get.go b/commands/vpn/ipsec/tunnel/get.go index caed2f26d..648bc90c3 100644 --- a/commands/vpn/ipsec/tunnel/get.go +++ b/commands/vpn/ipsec/tunnel/get.go @@ -12,7 +12,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths" "github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter" "github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -50,14 +49,17 @@ func Get() *core.Command { InitClient: true, }) - cmd.AddStringFlag(constants.FlagGatewayID, "", "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) - cmd.AddStringFlag(constants.FlagTunnelID, constants.FlagIdShort, "", "The ID of the IPSec Tunnel you want to delete", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagTunnelID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.TunnelIDs(viper.GetString(core.GetFlagName(cmd.NS, constants.FlagTunnelID))), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) + cmd.AddStringFlag(constants.FlagTunnelID, constants.FlagIdShort, "", "The ID of the IPSec Tunnel", + core.RequiredFlagOption(), + core.WithCompletion(func() []string { + gatewayID := viper.GetString(core.GetFlagName(cmd.NS, constants.FlagGatewayID)) + return completer.TunnelIDs(gatewayID) + }, constants.VPNApiRegionalURL), + ) cmd.Command.SilenceUsage = true cmd.Command.Flags().SortFlags = false diff --git a/commands/vpn/ipsec/tunnel/list.go b/commands/vpn/ipsec/tunnel/list.go index f3a512285..3e8c17748 100644 --- a/commands/vpn/ipsec/tunnel/list.go +++ b/commands/vpn/ipsec/tunnel/list.go @@ -12,7 +12,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter" "github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" vpn "github.com/ionos-cloud/sdk-go-vpn" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -56,10 +55,10 @@ func List() *core.Command { }, }) - cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) cmd.AddInt32Flag(constants.FlagMaxResults, constants.FlagMaxResultsShort, 0, constants.DescMaxResults) cmd.AddInt32Flag(constants.FlagOffset, "", 0, "Skip a certain number of results") diff --git a/commands/vpn/ipsec/tunnel/update.go b/commands/vpn/ipsec/tunnel/update.go index 0114ea51c..b419d3e29 100644 --- a/commands/vpn/ipsec/tunnel/update.go +++ b/commands/vpn/ipsec/tunnel/update.go @@ -10,7 +10,6 @@ import ( "github.com/ionos-cloud/ionosctl/v6/internal/constants" "github.com/ionos-cloud/ionosctl/v6/internal/core" vpn "github.com/ionos-cloud/sdk-go-vpn" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -40,14 +39,17 @@ func Update() *core.Command { }, }) - cmd.AddStringFlag(constants.FlagGatewayID, "", "", "The ID of the IPSec Gateway", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagGatewayID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.GatewayIDs(), cobra.ShellCompDirectiveNoFileComp - }) - cmd.AddStringFlag(constants.FlagTunnelID, constants.FlagIdShort, "", "The ID of the IPSec Tunnel you want to delete", core.RequiredFlagOption()) - cmd.Command.RegisterFlagCompletionFunc(constants.FlagTunnelID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completer.TunnelIDs(viper.GetString(core.GetFlagName(cmd.NS, constants.FlagTunnelID))), cobra.ShellCompDirectiveNoFileComp - }) + cmd.AddStringFlag(constants.FlagGatewayID, constants.FlagIdShort, "", "The ID of the IPSec Gateway", + core.RequiredFlagOption(), + core.WithCompletion(completer.GatewayIDs, constants.VPNApiRegionalURL), + ) + cmd.AddStringFlag(constants.FlagTunnelID, constants.FlagIdShort, "", "The ID of the IPSec Tunnel", + core.RequiredFlagOption(), + core.WithCompletion(func() []string { + gatewayID := viper.GetString(core.GetFlagName(cmd.NS, constants.FlagGatewayID)) + return completer.TunnelIDs(gatewayID) + }, constants.VPNApiRegionalURL), + ) cmd.AddStringFlag(constants.FlagName, "", "", "Name of the IPSec Tunnel", core.RequiredFlagOption()) cmd.AddStringFlag(constants.FlagDescription, "", "", "Description of the IPSec Tunnel")