Skip to content

Commit 7c30386

Browse files
committed
feat(rdb): acl: set with generated args + lint
1 parent 4a41108 commit 7c30386

File tree

9 files changed

+2781
-42
lines changed

9 files changed

+2781
-42
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Replace all the ACL rules of a Database Instance.
44

55
USAGE:
6-
scw rdb acl set <acl-rule-ips ...> [arg=value ...]
6+
scw rdb acl set [arg=value ...]
77

88
ARGS:
9-
acl-rule-ips IP addresses defined in the ACL rules of the Database Instance
10-
instance-id ID of the Database Instance
11-
[region=fr-par] Region to target. If none is passed will use default region from the config
9+
instance-id UUID of the Database Instance where the ACL rules must be set
10+
[rules.{index}.ip]
11+
[rules.{index}.description]
12+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)
1213

1314
FLAGS:
1415
-h, --help help for set

docs/commands/rdb.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,18 @@ Replace all the ACL rules of a Database Instance.
175175
**Usage:**
176176

177177
```
178-
scw rdb acl set <acl-rule-ips ...> [arg=value ...]
178+
scw rdb acl set [arg=value ...]
179179
```
180180

181181

182182
**Args:**
183183

184184
| Name | | Description |
185185
|------|---|-------------|
186-
| acl-rule-ips | Required | IP addresses defined in the ACL rules of the Database Instance |
187-
| instance-id | Required | ID of the Database Instance |
188-
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
186+
| instance-id | Required | UUID of the Database Instance where the ACL rules must be set |
187+
| rules.{index}.ip | | |
188+
| rules.{index}.description | | |
189+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |
189190

190191

191192

internal/namespaces/rdb/v1/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func GetCommands() *core.Commands {
3232
))
3333
cmds.MustFind("rdb", "acl", "add").Override(aclAddBuilder)
3434
cmds.MustFind("rdb", "acl", "delete").Override(aclDeleteBuilder)
35+
cmds.MustFind("rdb", "acl", "set").Override(aclSetBuilder)
3536

3637
cmds.MustFind("rdb", "backup", "create").Override(backupCreateBuilder)
3738
cmds.MustFind("rdb", "backup", "export").Override(backupExportBuilder)

internal/namespaces/rdb/v1/custom_acl.go

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func rdbACLCustomMultiResultMarshalerFunc(i interface{}, opt *human.MarshalOpt)
5050
case *rdbACLCustomResult:
5151
finalMessage := ""
5252
for _, result := range results {
53-
5453
aclResult := result.(*rdbACLCustomResult)
5554
messageStr, err := aclResult.Success.MarshalHuman()
5655
if err != nil {
@@ -224,7 +223,6 @@ func aclDeleteBuilder(c *core.Command) *core.Command {
224223
Message: message,
225224
},
226225
}, nil
227-
228226
}
229227

230228
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
@@ -248,52 +246,26 @@ func aclDeleteBuilder(c *core.Command) *core.Command {
248246
}
249247

250248
func aclSetBuilder(c *core.Command) *core.Command {
251-
c.ArgsType = reflect.TypeOf(rdbACLCustomArgs{})
252-
c.ArgSpecs = core.ArgSpecs{
253-
{
254-
Name: "acl-rule-ips",
255-
Short: "IP addresses defined in the ACL rules of the Database Instance",
256-
Required: true,
257-
Positional: true,
258-
},
259-
{
260-
Name: "instance-id",
261-
Short: "ID of the Database Instance",
262-
Required: true,
263-
Positional: false,
264-
},
265-
core.RegionArgSpec(),
266-
}
267-
268249
c.Run = func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
269-
args := argsI.(*rdbACLCustomArgs)
250+
args := argsI.(*rdb.SetInstanceACLRulesRequest)
270251
client := core.ExtractClient(ctx)
271252
api := rdb.NewAPI(client)
272253

273-
rule, err := api.SetInstanceACLRules(&rdb.SetInstanceACLRulesRequest{
274-
Region: args.Region,
275-
InstanceID: args.InstanceID,
276-
Rules: []*rdb.ACLRuleRequest{
277-
{
278-
IP: args.ACLRuleIPs,
279-
Description: fmt.Sprintf("Allow %s", args.ACLRuleIPs.String()),
280-
},
281-
},
282-
}, scw.WithContext(ctx))
254+
rule, err := api.SetInstanceACLRules(args, scw.WithContext(ctx))
283255
if err != nil {
284256
return nil, fmt.Errorf("failed to set ACL rule: %w", err)
285257
}
286258

287259
return &rdbACLCustomResult{
288260
Rules: rule.Rules,
289261
Success: core.SuccessResult{
290-
Message: fmt.Sprintf("ACL rules successfully set"),
262+
Message: "ACL rules successfully set",
291263
},
292264
}, nil
293265
}
294266

295267
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
296-
args := argsI.(*rdbACLCustomArgs)
268+
args := argsI.(*rdb.SetInstanceACLRulesRequest)
297269
api := rdb.NewAPI(core.ExtractClient(ctx))
298270

299271
_, err := api.WaitForInstance(&rdb.WaitForInstanceRequest{

internal/namespaces/rdb/v1/custom_acl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Test_SetACL(t *testing.T) {
8585
t.Run("Simple", core.Test(&core.TestConfig{
8686
Commands: GetCommands(),
8787
BeforeFunc: createInstance("PostgreSQL-12"),
88-
Cmd: "scw rdb acl set 1.2.3.4 instance-id={{ .Instance.ID }} --wait",
88+
Cmd: "scw rdb acl set rules.0.ip=1.2.3.4 instance-id={{ .Instance.ID }} --wait",
8989
Check: core.TestCheckCombine(
9090
core.TestCheckGolden(),
9191
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -101,7 +101,7 @@ func Test_SetACL(t *testing.T) {
101101
createInstance("PostgreSQL-12"),
102102
core.ExecBeforeCmd("scw rdb acl add 1.2.3.4 192.168.1.0/32 10.10.10.10 instance-id={{ .Instance.ID }} --wait"),
103103
),
104-
Cmd: "scw rdb acl set 1.2.3.4 192.168.1.0/31 11.11.11.11 instance-id={{ .Instance.ID }} --wait",
104+
Cmd: "scw rdb acl set rules.0.ip=1.2.3.4 rules.1.ip=192.168.1.0/31 rules.2.ip=11.11.11.11 instance-id={{ .Instance.ID }} --wait",
105105
Check: core.TestCheckCombine(
106106
core.TestCheckGolden(),
107107
func(t *testing.T, ctx *core.CheckFuncCtx) {

0 commit comments

Comments
 (0)