Skip to content

Commit a32d236

Browse files
committed
fix(redis): use dynamic zones from SDK instead of hardcoded zones
1 parent 5a8a22f commit a32d236

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

internal/namespaces/redis/v1/custom_cluster.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ type clusterConnectArgs struct {
329329
PrivateNetwork bool
330330
ClusterID string
331331
CliRedis *string
332+
CliArgs []string
332333
}
333334

334335
const (
@@ -367,6 +368,16 @@ func checkRedisCliInstalled(cliRedis string) error {
367368
return nil
368369
}
369370

371+
func getRedisZones() []scw.Zone {
372+
// Get zones dynamically from the Redis API SDK
373+
// We create a minimal client just to access the Zones() method
374+
// which doesn't require authentication
375+
client := &scw.Client{}
376+
api := redis.NewAPI(client)
377+
378+
return api.Zones()
379+
}
380+
370381
func clusterConnectCommand() *core.Command {
371382
return &core.Command{
372383
Namespace: "redis",
@@ -392,14 +403,12 @@ func clusterConnectCommand() *core.Command {
392403
Name: "cli-redis",
393404
Short: "Command line tool to use, default to redis-cli",
394405
},
395-
core.ZoneArgSpec(
396-
scw.ZoneFrPar1,
397-
scw.ZoneFrPar2,
398-
scw.ZoneNlAms1,
399-
scw.ZoneNlAms2,
400-
scw.ZonePlWaw1,
401-
scw.ZonePlWaw2,
402-
),
406+
{
407+
Name: "cli-args",
408+
Short: "Additional arguments to pass to redis-cli",
409+
Required: false,
410+
},
411+
core.ZoneArgSpec(getRedisZones()...),
403412
},
404413
Run: func(ctx context.Context, argsI any) (any, error) {
405414
args := argsI.(*clusterConnectArgs)
@@ -498,6 +507,11 @@ func clusterConnectCommand() *core.Command {
498507
cmdArgs = append(cmdArgs, "--user", cluster.UserName)
499508
}
500509

510+
// Add any additional arguments passed by the user
511+
if len(args.CliArgs) > 0 {
512+
cmdArgs = append(cmdArgs, args.CliArgs...)
513+
}
514+
501515
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) //nolint:gosec
502516
cmd.Stdin = os.Stdin
503517
cmd.Stdout = os.Stdout
@@ -518,12 +532,12 @@ func clusterConnectCommand() *core.Command {
518532
},
519533
Examples: []*core.Example{
520534
{
521-
Short: "Connect to a Redis cluster",
522-
ArgsJSON: `{"cluster-id": "11111111-1111-1111-1111-111111111111"}`,
535+
Short: "Connect to a Redis cluster",
536+
Raw: `scw redis cluster connect 11111111-1111-1111-1111-111111111111`,
523537
},
524538
{
525-
Short: "Connect to a Redis cluster via private network",
526-
ArgsJSON: `{"cluster-id": "11111111-1111-1111-1111-111111111111", "private-network": true}`,
539+
Short: "Connect to a Redis cluster via private network",
540+
Raw: `scw redis cluster connect 11111111-1111-1111-1111-111111111111 private-network=true`,
527541
},
528542
},
529543
}

0 commit comments

Comments
 (0)