Skip to content

Commit

Permalink
replace ipsec completions to work with regional urls
Browse files Browse the repository at this point in the history
  • Loading branch information
avirtopeanu-ionos committed Jan 9, 2025
1 parent 0af8221 commit 43f085b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 51 deletions.
9 changes: 4 additions & 5 deletions commands/vpn/ipsec/gateway/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))

Expand Down
9 changes: 4 additions & 5 deletions commands/vpn/ipsec/gateway/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions commands/vpn/ipsec/gateway/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 4 additions & 5 deletions commands/vpn/ipsec/tunnel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
Expand Down
20 changes: 11 additions & 9 deletions commands/vpn/ipsec/tunnel/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))

Expand Down
20 changes: 11 additions & 9 deletions commands/vpn/ipsec/tunnel/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions commands/vpn/ipsec/tunnel/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
Expand Down
20 changes: 11 additions & 9 deletions commands/vpn/ipsec/tunnel/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 43f085b

Please sign in to comment.