Skip to content

feat(redis): update acl rules #4868

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

Merged
merged 6 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions cmd/scw/testdata/test-all-usage-redis-acl-update-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Update an ACL rule (IP/description) for a Redis™ Database Instance (Redis™ cluster). This command simulates an update by fetching, deleting, and re-adding the rule.

USAGE:
scw redis acl update <acl-id ...> [arg=value ...]

ARGS:
cluster-id UUID of the Redis cluster
acl-id UUID of the ACL rule to update
[ip-cidr] New IPv4 network address of the rule (optional, defaults to current)
[description] New description of the rule (optional, defaults to current)
zone Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)

FLAGS:
-h, --help help for update

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-redis-acl-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AVAILABLE COMMANDS:
delete Delete an ACL rule for a cluster
get Get an ACL rule
set Set ACL rules for a cluster
update Update an ACL rule for a Redis™ Database Instance (network rule)

FLAGS:
-h, --help help for acl
Expand Down
24 changes: 24 additions & 0 deletions docs/commands/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This API allows you to manage your Managed Databases for Redis™.
- [Delete an ACL rule for a cluster](#delete-an-acl-rule-for-a-cluster)
- [Get an ACL rule](#get-an-acl-rule)
- [Set ACL rules for a cluster](#set-acl-rules-for-a-cluster)
- [Update an ACL rule for a Redis™ Database Instance (network rule)](#update-an-acl-rule-for-a-redis™-database-instance-(network-rule))
- [Cluster management commands](#cluster-management-commands)
- [Create a Redis™ Database Instance](#create-a-redis™-database-instance)
- [Delete a Redis™ Database Instance](#delete-a-redis™-database-instance)
Expand Down Expand Up @@ -123,6 +124,29 @@ scw redis acl set [arg=value ...]



### Update an ACL rule for a Redis™ Database Instance (network rule)

Update an ACL rule (IP/description) for a Redis™ Database Instance (Redis™ cluster). This command simulates an update by fetching, deleting, and re-adding the rule.

**Usage:**

```
scw redis acl update <acl-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| cluster-id | Required | UUID of the Redis cluster |
| acl-id | Required | UUID of the ACL rule to update |
| ip-cidr | | New IPv4 network address of the rule (optional, defaults to current) |
| description | | New description of the rule (optional, defaults to current) |
| zone | Required | Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2) |



## Cluster management commands

A Redis™ Database Instance, also known as a Redis™ cluster, consists of either one standalone node or a cluster composed of three to six nodes. The cluster uses partitioning to split the keyspace. Each partition is replicated and can be reassigned or elected as the primary when necessary. Standalone mode creates a standalone database provisioned on a single node.
Expand Down
2 changes: 2 additions & 0 deletions internal/namespaces/redis/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ func GetCommands() *core.Commands {
cmds.MustFind("redis", "setting", "add").Override(redisSettingAddBuilder)
cmds.MustFind("redis", "cluster", "migrate").Override(redisClusterMigrateBuilder)

cmds.Merge(core.NewCommands(redisACLUpdateCommand()))

return cmds
}
127 changes: 127 additions & 0 deletions internal/namespaces/redis/v1/custom_acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package redis

import (
"context"
"fmt"
"net"
"reflect"

"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-sdk-go/api/redis/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func redisACLUpdateCommand() *core.Command {
return &core.Command{
Short: "Update an ACL rule for a Redis™ Database Instance (network rule)",
Long: "Update an ACL rule (IP/description) for a Redis™ Database Instance (Redis™ cluster). This command simulates an update by fetching, deleting, and re-adding the rule.",
Namespace: "redis",
Resource: "acl",
Verb: "update",
ArgsType: reflect.TypeOf(redisUpdateACLRuleRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "cluster-id",
Short: "UUID of the Redis cluster",
Required: true,
Positional: false,
},
{
Name: "acl-id",
Short: "UUID of the ACL rule to update",
Required: true,
Positional: true,
},
{
Name: "ip-cidr",
Short: "New IPv4 network address of the rule (optional, defaults to current)",
Required: false,
},
{
Name: "description",
Short: "New description of the rule (optional, defaults to current)",
Required: false,
},
{
Name: "zone",
Short: "Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)",
Required: true,
},
},
Run: func(ctx context.Context, argsI any) (any, error) {
args := argsI.(*redisUpdateACLRuleRequest)
api := redis.NewAPI(core.ExtractClient(ctx))

// 1. Get the existing rule
rule, err := api.GetACLRule(&redis.GetACLRuleRequest{
ACLID: args.ACLID,
Zone: scw.Zone(args.Zone),
})
if err != nil {
return nil, fmt.Errorf("failed to get ACL rule: %w", err)
}

// 2. Delete the existing rule
_, err = api.DeleteACLRule(&redis.DeleteACLRuleRequest{
ACLID: args.ACLID,
Zone: scw.Zone(args.Zone),
})
if err != nil {
return nil, fmt.Errorf("failed to delete ACL rule: %w", err)
}

waitReq := &redis.WaitForClusterRequest{
ClusterID: args.ClusterID,
Zone: scw.Zone(args.Zone),
Timeout: scw.TimeDurationPtr(redisActionTimeout),
}
_, err = api.WaitForCluster(waitReq)
if err != nil {
return nil, fmt.Errorf("failed to wait for cluster to be ready: %w", err)
}

// 3. Add a new rule with updated fields
ipCIDR := args.IPCidr
if ipCIDR == "" {
ipCIDR = rule.IPCidr.String()
}
desc := args.Description
if desc == "" {
desc = *rule.Description
}
_, ipnet, err := net.ParseCIDR(ipCIDR)
if err != nil {
return nil, fmt.Errorf("invalid ip-cidr: %w", err)
}
scwIPNet := scw.IPNet{IPNet: *ipnet}
addResp, err := api.AddACLRules(&redis.AddACLRulesRequest{
ClusterID: args.ClusterID,
Zone: scw.Zone(args.Zone),
ACLRules: []*redis.ACLRuleSpec{
{
IPCidr: scwIPNet,
Description: desc,
},
},
})
if err != nil {
return nil, fmt.Errorf("failed to add updated ACL rule: %w", err)
}

_, err = api.WaitForCluster(waitReq)
if err != nil {
return nil, fmt.Errorf("failed to wait for cluster to be ready: %w", err)
}

return addResp.ACLRules, nil
},
}
}

type redisUpdateACLRuleRequest struct {
ClusterID string
ACLID string
IPCidr string
Description string
Zone string
}
Loading