Skip to content

Commit 47965e4

Browse files
authored
fix(rdb): acl: add description field (#3683)
1 parent bd839f0 commit 47965e4

26 files changed

+5750
-6112
lines changed

cmd/scw/testdata/test-all-usage-rdb-acl-add-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ USAGE:
88
ARGS:
99
acl-rule-ips IP addresses defined in the ACL rules of the Database Instance
1010
instance-id ID of the Database Instance
11+
[description] Description of the ACL rule. Indexes are not yet supported so the description will be applied to all the rules of the command.
1112
[region=fr-par] Region to target. If none is passed will use default region from the config
1213

1314
FLAGS:

docs/commands/rdb.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ scw rdb acl add <acl-rule-ips ...> [arg=value ...]
104104
|------|---|-------------|
105105
| acl-rule-ips | Required | IP addresses defined in the ACL rules of the Database Instance |
106106
| instance-id | Required | ID of the Database Instance |
107+
| description | | Description of the ACL rule. Indexes are not yet supported so the description will be applied to all the rules of the command. |
107108
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
108109

109110

internal/namespaces/rdb/v1/custom_acl.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ var (
2121
)
2222

2323
type rdbACLCustomArgs struct {
24-
Region scw.Region
25-
InstanceID string
26-
ACLRuleIPs scw.IPNet
24+
Region scw.Region
25+
InstanceID string
26+
ACLRuleIPs scw.IPNet
27+
Description string
2728
}
2829

2930
type rdbACLCustomResult struct {
@@ -59,6 +60,12 @@ func aclAddBuilder(c *core.Command) *core.Command {
5960
Required: true,
6061
Positional: false,
6162
},
63+
{
64+
Name: "description",
65+
Short: "Description of the ACL rule. Indexes are not yet supported so the description will be applied to all the rules of the command.",
66+
Required: false,
67+
Positional: false,
68+
},
6269
core.RegionArgSpec(),
6370
}
6471

@@ -75,13 +82,18 @@ func aclAddBuilder(c *core.Command) *core.Command {
7582
client := core.ExtractClient(ctx)
7683
api := rdb.NewAPI(client)
7784

85+
description := args.Description
86+
if description == "" {
87+
description = fmt.Sprintf("Allow %s", args.ACLRuleIPs.String())
88+
}
89+
7890
rule, err := api.AddInstanceACLRules(&rdb.AddInstanceACLRulesRequest{
7991
Region: args.Region,
8092
InstanceID: args.InstanceID,
8193
Rules: []*rdb.ACLRuleRequest{
8294
{
8395
IP: args.ACLRuleIPs,
84-
Description: fmt.Sprintf("Allow %s", args.ACLRuleIPs.String()),
96+
Description: description,
8597
},
8698
},
8799
}, scw.WithContext(ctx))

internal/namespaces/rdb/v1/custom_acl_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ func Test_AddACL(t *testing.T) {
2020
AfterFunc: deleteInstance(),
2121
}))
2222

23+
t.Run("Simple with description", core.Test(&core.TestConfig{
24+
Commands: GetCommands(),
25+
BeforeFunc: createInstance("PostgreSQL-12"),
26+
Cmd: "scw rdb acl add 1.2.3.4 instance-id={{ .Instance.ID }} description=some-unique-description --wait",
27+
Check: core.TestCheckCombine(
28+
core.TestCheckGolden(),
29+
func(t *testing.T, ctx *core.CheckFuncCtx) {
30+
verifyACL(ctx, t, []string{"0.0.0.0/0", "1.2.3.4/32"})
31+
},
32+
),
33+
AfterFunc: deleteInstance(),
34+
}))
35+
2336
t.Run("Multiple", core.Test(&core.TestConfig{
2437
Commands: GetCommands(),
2538
BeforeFunc: createInstance("PostgreSQL-12"),
@@ -32,6 +45,19 @@ func Test_AddACL(t *testing.T) {
3245
),
3346
AfterFunc: deleteInstance(),
3447
}))
48+
49+
t.Run("Multiple with description", core.Test(&core.TestConfig{
50+
Commands: GetCommands(),
51+
BeforeFunc: createInstance("PostgreSQL-12"),
52+
Cmd: "scw rdb acl add 1.2.3.4 192.168.1.0/30 10.10.10.10 instance-id={{ .Instance.ID }} description=some-unique-description --wait",
53+
Check: core.TestCheckCombine(
54+
core.TestCheckGolden(),
55+
func(t *testing.T, ctx *core.CheckFuncCtx) {
56+
verifyACL(ctx, t, []string{"0.0.0.0/0", "1.2.3.4/32", "192.168.1.0/30", "10.10.10.10/32"})
57+
},
58+
),
59+
AfterFunc: deleteInstance(),
60+
}))
3561
}
3662

3763
func Test_DeleteACL(t *testing.T) {

internal/namespaces/rdb/v1/testdata/test-add-acl-allow.cassette.yaml

Lines changed: 0 additions & 1003 deletions
This file was deleted.

internal/namespaces/rdb/v1/testdata/test-add-acl-allow.golden

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)