Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add --location for Regional APIs. Fix API-queried regional completions #468

Merged
merged 26 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3571771
change: remove old functionality
avirtopeanu-ionos Nov 29, 2024
f3056ab
change: remove old GetServerURL workarounds
avirtopeanu-ionos Nov 29, 2024
13904f8
feat: withRegionalFlags decorator
avirtopeanu-ionos Nov 29, 2024
10a4e79
feat: withCompletions option
avirtopeanu-ionos Nov 29, 2024
97eb1b0
change: remove old dns completer workarounds
avirtopeanu-ionos Nov 29, 2024
01730a6
revert: don't apply the new funcs yet
avirtopeanu-ionos Nov 29, 2024
70a4ea2
add comments, remove print statements
avirtopeanu-ionos Nov 29, 2024
3ab8abb
change: allow users to force a location for completions
avirtopeanu-ionos Nov 29, 2024
a475ed3
WithRegionalFlags allow force custom location but warn
avirtopeanu-ionos Nov 29, 2024
89e4880
replace: dns zone completions
avirtopeanu-ionos Dec 4, 2024
35a58e2
replace: dns record completions
avirtopeanu-ionos Dec 4, 2024
a18235f
clouadpi ipblock completion in a dns command
avirtopeanu-ionos Dec 4, 2024
dff9976
replace: dnssec completions
avirtopeanu-ionos Dec 4, 2024
8bfbd97
fix: use regional API flags for Logging API
avirtopeanu-ionos Dec 4, 2024
a2277e0
fix: stop testing credentials if the URL is overriden
avirtopeanu-ionos Dec 4, 2024
754557c
replace: logging pipeline completions
avirtopeanu-ionos Dec 4, 2024
74fbf39
replace: logging logs completions
avirtopeanu-ionos Dec 4, 2024
702bb0c
make cdn a regional command
avirtopeanu-ionos Dec 4, 2024
c7a8a87
feat: cdn completions
avirtopeanu-ionos Dec 4, 2024
35fa2c3
better constant names
avirtopeanu-ionos Dec 4, 2024
6606e02
replace: MariaDB add regional support
avirtopeanu-ionos Dec 4, 2024
5cb78a8
replace: mariadb backups regional completions
avirtopeanu-ionos Dec 4, 2024
14aab60
doc: update docs
avirtopeanu-ionos Dec 4, 2024
6784631
goimports
avirtopeanu-ionos Dec 4, 2024
4f57fa4
test: fix config tests
avirtopeanu-ionos Dec 4, 2024
f092aee
Merge branch 'master' into replace/regional-api
avirtopeanu-ionos Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion commands/cdn/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cdn

import (
"github.com/ionos-cloud/ionosctl/v6/commands/cdn/distribution"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"github.com/spf13/cobra"
)
Expand All @@ -15,5 +16,6 @@ func Command() *core.Command {
},
}
cmd.AddCommand(distribution.Command())
return cmd

return core.WithRegionalFlags(cmd, constants.CDNApiRegionalURL, constants.CDNLocations)
}
1 change: 1 addition & 0 deletions commands/cdn/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package completer

import (
"context"

"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/pkg/functional"
cdn "github.com/ionos-cloud/sdk-go-cdn"
Expand Down
3 changes: 2 additions & 1 deletion commands/cdn/distribution/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"github.com/ionos-cloud/ionosctl/v6/pkg/pointer"
"github.com/ionos-cloud/ionosctl/v6/pkg/uuidgen"
cdn "github.com/ionos-cloud/sdk-go-cdn"
"github.com/spf13/viper"
"os"
)

func Create() *core.Command {
Expand Down
16 changes: 9 additions & 7 deletions commands/cdn/distribution/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package distribution
import (
"context"
"fmt"

"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/pkg/confirm"
"github.com/ionos-cloud/ionosctl/v6/pkg/functional"
cdn "github.com/ionos-cloud/sdk-go-cdn"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/ionos-cloud/ionosctl/v6/internal/core"
Expand Down Expand Up @@ -41,12 +41,14 @@ func Delete() *core.Command {
InitClient: true,
})

cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution you want to retrieve", core.RequiredFlagOption())
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagCDNDistributionID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
}), cobra.ShellCompDirectiveNoFileComp
})
cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution you want to delete",
core.RequiredFlagOption(),
core.WithCompletion(func() []string {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
})
}, constants.CDNApiRegionalURL),
)
cmd.AddBoolFlag(constants.ArgAll, constants.ArgAllShort, false, "Delete all records if set", core.RequiredFlagOption())

cmd.Command.SilenceUsage = true
Expand Down
20 changes: 11 additions & 9 deletions commands/cdn/distribution/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package distribution
import (
"context"
"fmt"
"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
cdn "github.com/ionos-cloud/sdk-go-cdn"
"github.com/spf13/cobra"

"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"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"
cdn "github.com/ionos-cloud/sdk-go-cdn"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -52,12 +51,15 @@ func FindByID() *core.Command {
},
InitClient: true,
})
cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution you want to retrieve", core.RequiredFlagOption())
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagCDNDistributionID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
}), cobra.ShellCompDirectiveNoFileComp
})

cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution you want to retrieve",
core.RequiredFlagOption(),
core.WithCompletion(func() []string {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
})
}, constants.CDNApiRegionalURL),
)
cmd.Command.SilenceUsage = true
cmd.Command.Flags().SortFlags = false
return cmd
Expand Down
1 change: 1 addition & 0 deletions commands/cdn/distribution/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package distribution
import (
"context"
"fmt"

"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
Expand Down
15 changes: 9 additions & 6 deletions commands/cdn/distribution/routingrules/routing_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package routingrules
import (
"context"
"fmt"

"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
Expand Down Expand Up @@ -78,12 +79,14 @@ func GetDistributionRoutingRules() *core.Command {
},
InitClient: true,
})
cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution you want to retrieve", core.RequiredFlagOption())
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagCDNDistributionID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
}), cobra.ShellCompDirectiveNoFileComp
})
cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution",
core.RequiredFlagOption(),
core.WithCompletion(func() []string {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
})
}, constants.CDNApiRegionalURL),
)
cmd.Command.SilenceUsage = true
cmd.Command.Flags().SortFlags = false
return cmd
Expand Down
17 changes: 9 additions & 8 deletions commands/cdn/distribution/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package distribution
import (
"context"
"fmt"
"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
"github.com/spf13/cobra"

"github.com/ionos-cloud/ionosctl/v6/commands/cdn/completer"
"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths"
Expand Down Expand Up @@ -49,12 +48,14 @@ func Update() *core.Command {
InitClient: true,
})

cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the CDN distribution", core.RequiredFlagOption())
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagCDNDistributionID, func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
}), cobra.ShellCompDirectiveNoFileComp
})
cmd.AddStringFlag(constants.FlagCDNDistributionID, constants.FlagIdShort, "", "The ID of the distribution you want to update",
core.RequiredFlagOption(),
core.WithCompletion(func() []string {
return completer.DistributionsProperty(func(r cdn.Distribution) string {
return *r.Id
})
}, constants.CDNApiRegionalURL),
)
cmd.Command.SilenceUsage = true
cmd.Command.Flags().SortFlags = false

Expand Down
9 changes: 9 additions & 0 deletions commands/dbaas/mariadb/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ionos-cloud/ionosctl/v6/commands/dbaas/mariadb/cluster"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders"
"github.com/ionos-cloud/ionosctl/v6/pkg/functional"
ionoscloud "github.com/ionos-cloud/sdk-go-dbaas-mariadb"

"github.com/ionos-cloud/ionosctl/v6/internal/client"
Expand Down Expand Up @@ -73,3 +74,11 @@ func FilterPaginationFlags(c *core.CommandConfig) Filter {
return req
}
}

func BackupsProperty[V any](f func(c ionoscloud.BackupResponse) V, fs ...Filter) []V {
recs, err := Backups(fs...)
if err != nil {
return nil
}
return functional.Map(*recs.Items, f)
}
16 changes: 14 additions & 2 deletions commands/dbaas/mariadb/backup/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

ionoscloud "github.com/ionos-cloud/sdk-go-dbaas-mariadb"

"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
Expand Down Expand Up @@ -46,7 +48,17 @@ func Get() *core.Command {
InitClient: true,
})

cmd.AddStringFlag(constants.FlagBackupId, "", "", "The ID of the Backup to be retrieved")

cmd.AddStringFlag(constants.FlagBackupId, "", "", "The ID of the Backup to be retrieved",
core.RequiredFlagOption(),
core.WithCompletion(
func() []string {
return BackupsProperty(func(c ionoscloud.BackupResponse) string {
if c.Id == nil {
return ""
}
return *c.Id + "\t" + fmt.Sprintf("(%d MiB)", *c.Properties.Size)
})
}, constants.MariaDBApiRegionalURL),
)
return cmd
}
22 changes: 12 additions & 10 deletions commands/dbaas/mariadb/backup/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"
ionoscloud "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -58,15 +57,18 @@ func List() *core.Command {
InitClient: true,
})

cmd.AddStringFlag(constants.FlagClusterId, constants.FlagIdShort, "", "Optionally limit shown backups to those of a certain cluster")
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagClusterId, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return cluster.ClustersProperty(func(c ionoscloud.ClusterResponse) string {
if c.Id == nil {
return ""
}
return *c.Id
}), cobra.ShellCompDirectiveNoFileComp
})
cmd.AddStringFlag(constants.FlagClusterId, constants.FlagIdShort, "", "Optionally limit shown backups to those of a certain cluster",
core.RequiredFlagOption(),
core.WithCompletion(
func() []string {
return cluster.ClustersProperty(func(c ionoscloud.ClusterResponse) string {
if c.Id == nil {
return ""
}
return *c.Id
})
}, constants.MariaDBApiRegionalURL),
)
cmd.AddInt32Flag(constants.FlagMaxResults, constants.FlagMaxResultsShort, 0, constants.DescMaxResults)
cmd.AddInt32Flag(constants.FlagOffset, "", 0, "Skip a certain number of results")

Expand Down
21 changes: 12 additions & 9 deletions commands/dbaas/mariadb/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ ionosctl db mar c d --all --name <name>`,
InitClient: true,
})

cmd.AddStringFlag(constants.FlagClusterId, constants.FlagIdShort, "", "The unique ID of the cluster", core.RequiredFlagOption())
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagClusterId, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return ClustersProperty(func(c sdkgo.ClusterResponse) string {
if c.Id == nil {
return ""
}
return *c.Id
}), cobra.ShellCompDirectiveNoFileComp
})
cmd.AddStringFlag(constants.FlagClusterId, constants.FlagIdShort, "", "The unique ID of the cluster",
core.RequiredFlagOption(),
core.WithCompletion(
func() []string {
return ClustersProperty(func(c sdkgo.ClusterResponse) string {
if c.Id == nil {
return ""
}
return *c.Id
})
}, constants.MariaDBApiRegionalURL),
)
cmd.AddBoolFlag(constants.ArgAll, constants.ArgAllShort, false, "Delete all mariadb clusters")
cmd.AddBoolFlag(constants.FlagName, "", false, "When deleting all clusters, filter the clusters by a name")
cmd.AddStringSliceFlag(constants.ArgCols, "", nil, tabheaders.ColsMessage(allCols))
Expand Down
22 changes: 12 additions & 10 deletions commands/dbaas/mariadb/cluster/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders"
ionoscloud "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -50,15 +49,18 @@ func Get() *core.Command {
InitClient: true,
})

cmd.AddStringFlag(constants.FlagClusterId, constants.FlagIdShort, "", "The unique ID of the cluster", core.RequiredFlagOption())
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagClusterId, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return ClustersProperty(func(c ionoscloud.ClusterResponse) string {
if c.Id == nil {
return ""
}
return *c.Id
}), cobra.ShellCompDirectiveNoFileComp
})
cmd.AddStringFlag(constants.FlagClusterId, constants.FlagIdShort, "", "The unique ID of the cluster",
core.RequiredFlagOption(),
core.WithCompletion(
func() []string {
return ClustersProperty(func(c ionoscloud.ClusterResponse) string {
if c.Id == nil {
return ""
}
return *c.Id
})
}, constants.MariaDBApiRegionalURL),
)

cmd.Command.SilenceUsage = true

Expand Down
4 changes: 3 additions & 1 deletion commands/dbaas/mariadb/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mariadb
import (
"github.com/ionos-cloud/ionosctl/v6/commands/dbaas/mariadb/backup"
"github.com/ionos-cloud/ionosctl/v6/commands/dbaas/mariadb/cluster"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"github.com/spf13/cobra"
)
Expand All @@ -18,5 +19,6 @@ func Root() *core.Command {
}
cmd.AddCommand(cluster.Root())
cmd.AddCommand(backup.Root())
return cmd

return core.WithRegionalFlags(cmd, constants.MariaDBApiRegionalURL, constants.MariaDBLocations)
}
2 changes: 1 addition & 1 deletion commands/dns/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths"
"github.com/ionos-cloud/ionosctl/v6/pkg/functional"

"github.com/ionos-cloud/sdk-go-dns"
ionoscloud "github.com/ionos-cloud/sdk-go-dns"
"github.com/spf13/viper"
)

Expand Down
5 changes: 3 additions & 2 deletions commands/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
reverse_record "github.com/ionos-cloud/ionosctl/v6/commands/dns/reverse-record"
secondary_zones "github.com/ionos-cloud/ionosctl/v6/commands/dns/secondary-zones"
"github.com/ionos-cloud/ionosctl/v6/commands/dns/zone"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"github.com/spf13/cobra"
)

func DNSCommand() *core.Command {
func Root() *core.Command {
cmd := &core.Command{
Command: &cobra.Command{
Use: "dns",
Expand All @@ -26,5 +27,5 @@ func DNSCommand() *core.Command {
cmd.AddCommand(dnssec.Root())
cmd.AddCommand(secondary_zones.Root())

return cmd
return core.WithRegionalFlags(cmd, constants.DNSApiRegionalURL, constants.DNSLocations)
}
Loading
Loading