Skip to content

Commit 67ce2d8

Browse files
refactor: query params (#617)
* refactor: remove queryParams invocations * rm: queryparams from func definitions * rm: queryparams from func definitions * rm: queryparams from func definitions * rm: queryparams from func definitions * rm: queryparams from func definitions * update calls * update calls * update calls * update calls * update calls * update calls * update calls * test: update queryparam in tests * add queryparams to client * replace flag usage * replace flag usage * replace flag usage * remove deprecated 'D' for 'datacenter-id' only on psql * applyFilters * applyFilters * improve filters: apply globally * refactor: better names * refactor: remove old Filters flag * refactor: remove old Filters flag * refactor: remove old Filters flag * refactor: remove old query pkg * refactor: remove old query pkg * rm unused root vars * rm checked todos * fix: multi-value per key filters * fix tests, regen docs * improve request listing err * remove old depth constant * rm firewallrule -D * doc: changelog * test: add queryparam test * fix: use 'maxResults' instead of 'limit' for image API * fix: workaround for an API bug when using maxResults and filtering for /images * fix: shorthand -F not working * remove --filter helper due to Cobra not being able to bind * improve tests * fix: ignore depth for apigateway and logging API * doc: regen docs * test: add retries to ssh test
1 parent 255a6e0 commit 67ce2d8

610 files changed

Lines changed: 5320 additions & 10327 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77
- Added support for '--limit' and '--offset' as global flags.
88
- Added descriptions for the following flag completions: '--location', '--user-id', '--group-id', '--ipblock-id', '--volume-id'
99
- Added support for '--query' which allows querying JSON outputs with JMESPath queries.
10+
- Added support for all query paramters as global flags:
11+
- `--depth`, `--order-by`, `--limit`, `--offset`, `--filter`,
12+
- `--max-results` / `-M` has been deprecated. Setting this flag will now just set `--limit` accordingly.
13+
- Added a clearer error for 'request list' if using a too-low depth, and receiving an empty output.
14+
- Added '--filter' as a hidden flag which just sets '--filters' as a QoL improvement.
1015

1116
### Changed
1217
- Flag '--max-results' has been deprecated and hidden in favor of the new global flag '--limit'. Setting '--max-results' will now just set '--limit' accordingly.
1318
WARNING: After this change, you may now find different results when using both '--filter' and '--max-results' together, as '--max-results' was applied before filtering, while '--limit' is applied after filtering.
1419

20+
- Removed the following deprecated short-hand flags, due to conflicts with '-D' for '--depth' (previously, '--depth' was either not supported, or not implemented with a shorthand here):
21+
- '-D' for '--destination-ip' on 'firewallrule' commands (two usages)
22+
- '-D' for '--datacenter-id' on 'psql' commands (two usages)
23+
- These flags have changed their meaning to '--depth' instead, which is now supported globally.
24+
1525
### Fixed
1626
- Fixed completions for '--datacenter-id' and '--lan-id' for DBaaS Replicaset commands
1727
- Fixed a panic when deleting a VPN Gateway due to description being nil.

commands/cloudapi-v6/applicationloadbalancer.go

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/ionos-cloud/ionosctl/v6/commands/cloudapi-v6/completer"
10-
"github.com/ionos-cloud/ionosctl/v6/commands/cloudapi-v6/query"
1110
"github.com/ionos-cloud/ionosctl/v6/commands/cloudapi-v6/waiter"
1211
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
1312
"github.com/ionos-cloud/ionosctl/v6/internal/core"
@@ -67,15 +66,7 @@ func ApplicationLoadBalancerCmd() *core.Command {
6766
_ = list.Command.RegisterFlagCompletionFunc(cloudapiv6.ArgDataCenterId, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
6867
return completer.DataCentersIds(), cobra.ShellCompDirectiveNoFileComp
6968
})
70-
list.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultListDepth, cloudapiv6.ArgDepthDescription)
71-
list.AddStringFlag(cloudapiv6.ArgOrderBy, "", "", cloudapiv6.ArgOrderByDescription)
72-
_ = list.Command.RegisterFlagCompletionFunc(cloudapiv6.ArgOrderBy, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
73-
return completer.BackupUnitsFilters(), cobra.ShellCompDirectiveNoFileComp
74-
})
75-
list.AddStringSliceFlag(cloudapiv6.ArgFilters, cloudapiv6.ArgFiltersShort, []string{""}, cloudapiv6.ArgFiltersDescription)
76-
_ = list.Command.RegisterFlagCompletionFunc(cloudapiv6.ArgFilters, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
77-
return completer.BackupUnitsFilters(), cobra.ShellCompDirectiveNoFileComp
78-
})
69+
7970
list.AddBoolFlag(cloudapiv6.ArgAll, cloudapiv6.ArgAllShort, false, cloudapiv6.ArgListAllDescription)
8071

8172
/*
@@ -102,7 +93,7 @@ func ApplicationLoadBalancerCmd() *core.Command {
10293
return completer.ApplicationLoadBalancersIds(viper.GetString(core.GetFlagName(get.NS, cloudapiv6.ArgDataCenterId))), cobra.ShellCompDirectiveNoFileComp
10394
})
10495
get.AddBoolFlag(constants.ArgWaitForState, constants.ArgWaitForStateShort, constants.DefaultWait, "Wait for specified Application Load Balancer to be in AVAILABLE state")
105-
get.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultGetDepth, cloudapiv6.ArgDepthDescription)
96+
10697
get.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, cloudapiv6.LbTimeoutSeconds, "Timeout option for waiting for Application Load Balancer to be in AVAILABLE state [seconds]")
10798

10899
/*
@@ -137,7 +128,6 @@ Required values to run command:
137128
create.AddStringSliceFlag(cloudapiv6.ArgPrivateIps, "", nil, "Collection of private IP addresses with the subnet mask of the Application Load Balancer. IPs must contain valid a subnet mask. If no IP is provided, the system will generate an IP with /24 subnet.")
138129
create.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait, "Wait for the Request for Application Load Balancer creation to be executed")
139130
create.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, cloudapiv6.AlbTimeoutSeconds, "Timeout option for Request for Application Load Balancer creation [seconds]")
140-
create.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultCreateDepth, cloudapiv6.ArgDepthDescription)
141131

142132
/*
143133
Update Command
@@ -176,7 +166,6 @@ Required values to run command:
176166
update.AddStringSliceFlag(cloudapiv6.ArgPrivateIps, "", nil, "Collection of private IP addresses with the subnet mask of the Application Load Balancer. IPs must contain valid a subnet mask. If no IP is provided, the system will generate an IP with /24 subnet.")
177167
update.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait, "Wait for the Request for Application Load Balancer update to be executed")
178168
update.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, cloudapiv6.LbTimeoutSeconds, "Timeout option for Request for Application Load Balancer update [seconds]")
179-
update.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultUpdateDepth, cloudapiv6.ArgDepthDescription)
180169

181170
/*
182171
Delete Command
@@ -211,7 +200,6 @@ Required values to run command:
211200
deleteCmd.AddBoolFlag(cloudapiv6.ArgAll, cloudapiv6.ArgAllShort, false, "Delete all Application Load Balancers")
212201
deleteCmd.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait, "Wait for the Request for Application Load Balancer deletion to be executed")
213202
deleteCmd.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, cloudapiv6.LbTimeoutSeconds, "Timeout option for Request for Application Load Balancer deletion [seconds]")
214-
deleteCmd.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultDeleteDepth, cloudapiv6.ArgDepthDescription)
215203

216204
applicationloadbalancerCmd.AddCommand(ApplicationLoadBalancerRuleCmd())
217205
applicationloadbalancerCmd.AddCommand(ApplicationLoadBalancerFlowLogCmd())
@@ -237,19 +225,11 @@ func PreRunApplicationLoadBalancerList(c *core.PreCommandConfig) error {
237225
); err != nil {
238226
return err
239227
}
240-
if viper.IsSet(core.GetFlagName(c.NS, cloudapiv6.ArgFilters)) {
241-
return query.ValidateFilters(c, completer.ApplicationLoadBalancersFilters(), completer.ApplicationLoadBalancersFiltersUsage())
242-
}
243228
return nil
244229
}
245230

246231
func RunApplicationLoadBalancerListAll(c *core.CommandConfig) error {
247-
listQueryParams, err := query.GetListQueryParams(c)
248-
if err != nil {
249-
return err
250-
}
251-
252-
datacenters, _, err := c.CloudApiV6Services.DataCenters().List(cloudapiv6.ParentResourceListQueryParams)
232+
datacenters, _, err := c.CloudApiV6Services.DataCenters().List()
253233
if err != nil {
254234
return err
255235
}
@@ -264,7 +244,7 @@ func RunApplicationLoadBalancerListAll(c *core.CommandConfig) error {
264244
return fmt.Errorf("could not retrieve Datacenter Id")
265245
}
266246

267-
ApplicationLoadBalancers, resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().List(*dcId, listQueryParams)
247+
ApplicationLoadBalancers, resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().List(*dcId)
268248
if err != nil {
269249
return err
270250
}
@@ -297,18 +277,13 @@ func RunApplicationLoadBalancerList(c *core.CommandConfig) error {
297277
return RunApplicationLoadBalancerListAll(c)
298278
}
299279

300-
listQueryParams, err := query.GetListQueryParams(c)
301-
if err != nil {
302-
return err
303-
}
304-
305280
dcId := viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId))
306281
cols := viper.GetStringSlice(core.GetFlagName(c.Resource, constants.ArgCols))
307282

308283
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(
309284
"Getting ApplicationLoadBalancers from Datacenter with ID: %v", viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId))))
310285

311-
applicationloadbalancers, resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().List(dcId, listQueryParams)
286+
applicationloadbalancers, resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().List(dcId)
312287
if resp != nil {
313288
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(constants.MessageRequestTime, resp.RequestTime))
314289
}
@@ -325,14 +300,7 @@ func RunApplicationLoadBalancerList(c *core.CommandConfig) error {
325300
}
326301

327302
func RunApplicationLoadBalancerGet(c *core.CommandConfig) error {
328-
listQueryParams, err := query.GetListQueryParams(c)
329-
if err != nil {
330-
return err
331-
}
332-
333303
cols := viper.GetStringSlice(core.GetFlagName(c.Resource, constants.ArgCols))
334-
335-
queryParams := listQueryParams.QueryParams
336304
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s",
337305
jsontabwriter.GenerateVerboseOutput(
338306
constants.DatacenterId, viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId))))
@@ -346,7 +314,6 @@ func RunApplicationLoadBalancerGet(c *core.CommandConfig) error {
346314
ng, resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().Get(
347315
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)),
348316
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgApplicationLoadBalancerId)),
349-
queryParams,
350317
)
351318
if resp != nil {
352319
fmt.Fprintf(c.Command.Command.OutOrStdout(), "%s", jsontabwriter.GenerateVerboseOutput(constants.MessageRequestTime, resp.RequestTime))
@@ -365,14 +332,7 @@ func RunApplicationLoadBalancerGet(c *core.CommandConfig) error {
365332
}
366333

367334
func RunApplicationLoadBalancerCreate(c *core.CommandConfig) error {
368-
listQueryParams, err := query.GetListQueryParams(c)
369-
if err != nil {
370-
return err
371-
}
372-
373335
cols := viper.GetStringSlice(core.GetFlagName(c.Resource, constants.ArgCols))
374-
375-
queryParams := listQueryParams.QueryParams
376336
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(
377337
constants.DatacenterId, viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId))))
378338
proper := getNewApplicationLoadBalancerInfo(c)
@@ -403,7 +363,6 @@ func RunApplicationLoadBalancerCreate(c *core.CommandConfig) error {
403363
Properties: &proper.ApplicationLoadBalancerProperties,
404364
},
405365
},
406-
queryParams,
407366
)
408367
if resp != nil {
409368
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput("Request href: %v ", resp.Header.Get("location")))
@@ -429,14 +388,7 @@ func RunApplicationLoadBalancerCreate(c *core.CommandConfig) error {
429388
}
430389

431390
func RunApplicationLoadBalancerUpdate(c *core.CommandConfig) error {
432-
listQueryParams, err := query.GetListQueryParams(c)
433-
if err != nil {
434-
return err
435-
}
436-
437391
cols := viper.GetStringSlice(core.GetFlagName(c.Resource, constants.ArgCols))
438-
439-
queryParams := listQueryParams.QueryParams
440392
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(
441393
constants.DatacenterId, viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId))))
442394

@@ -448,7 +400,6 @@ func RunApplicationLoadBalancerUpdate(c *core.CommandConfig) error {
448400
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)),
449401
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgApplicationLoadBalancerId)),
450402
*input,
451-
queryParams,
452403
)
453404
if resp != nil {
454405
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(constants.MessageRequestTime, resp.RequestTime))
@@ -470,19 +421,13 @@ func RunApplicationLoadBalancerUpdate(c *core.CommandConfig) error {
470421
}
471422

472423
func RunApplicationLoadBalancerDelete(c *core.CommandConfig) error {
473-
listQueryParams, err := query.GetListQueryParams(c)
474-
if err != nil {
475-
return err
476-
}
477-
478-
queryParams := listQueryParams.QueryParams
479424
var resp *resources.Response
480425

481426
if viper.GetBool(core.GetFlagName(c.NS, cloudapiv6.ArgAll)) {
482427
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(
483428
constants.DatacenterId, viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId))))
484429

485-
err = DeleteAllApplicationLoadBalancer(c)
430+
err := DeleteAllApplicationLoadBalancer(c)
486431
if err != nil {
487432
return err
488433
}
@@ -501,8 +446,8 @@ func RunApplicationLoadBalancerDelete(c *core.CommandConfig) error {
501446

502447
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput("Starting deleting ApplicationLoadBalancer"))
503448

504-
resp, err = c.CloudApiV6Services.ApplicationLoadBalancers().Delete(viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)),
505-
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgApplicationLoadBalancerId)), queryParams)
449+
resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().Delete(viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)),
450+
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgApplicationLoadBalancerId)))
506451
if resp != nil {
507452
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(constants.MessageRequestTime, resp.RequestTime))
508453
}
@@ -520,17 +465,10 @@ func RunApplicationLoadBalancerDelete(c *core.CommandConfig) error {
520465
}
521466

522467
func DeleteAllApplicationLoadBalancer(c *core.CommandConfig) error {
523-
listQueryParams, err := query.GetListQueryParams(c)
524-
if err != nil {
525-
return err
526-
}
527-
528-
queryParams := listQueryParams.QueryParams
529-
530468
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateLogOutput("Getting Application Load Balancers..."))
531469

532470
applicationLoadBalancers, resp, err := c.CloudApiV6Services.ApplicationLoadBalancers().List(
533-
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)), cloudapiv6.ParentResourceListQueryParams)
471+
viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)))
534472
if err != nil {
535473
return err
536474
}
@@ -554,7 +492,7 @@ func DeleteAllApplicationLoadBalancer(c *core.CommandConfig) error {
554492
return fmt.Errorf(confirm.UserDenied)
555493
}
556494

557-
resp, err = c.CloudApiV6Services.ApplicationLoadBalancers().Delete(viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)), *id, queryParams)
495+
resp, err = c.CloudApiV6Services.ApplicationLoadBalancers().Delete(viper.GetString(core.GetFlagName(c.NS, cloudapiv6.ArgDataCenterId)), *id)
558496
if resp != nil && request.GetId(resp) != "" {
559497
fmt.Fprintf(c.Command.Command.ErrOrStderr(), "%s", jsontabwriter.GenerateVerboseOutput(
560498
constants.MessageRequestInfo, request.GetId(resp), resp.RequestTime))

0 commit comments

Comments
 (0)