Skip to content

Commit c0d1620

Browse files
committed
fix test
1 parent 12d143f commit c0d1620

6 files changed

+183
-24
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- scaleway-sdk-go/v1.0.0-beta.35.0.20250917154444-1d3cdbf4ce0d (go1.24.6; darwin;
10+
amd64) cli-e2e-test
11+
url: https://api.scaleway.com/iam/v1alpha1/api-keys/SCWXXXXXXXXXXXXXXXXX
12+
method: GET
13+
response:
14+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
15+
headers:
16+
Content-Length:
17+
- "109"
18+
Content-Security-Policy:
19+
- default-src 'none'; frame-ancestors 'none'
20+
Content-Type:
21+
- application/json
22+
Date:
23+
- Mon, 29 Sep 2025 08:31:55 GMT
24+
Server:
25+
- Scaleway API Gateway (fr-par-1;edge01)
26+
Strict-Transport-Security:
27+
- max-age=63072000
28+
X-Content-Type-Options:
29+
- nosniff
30+
X-Frame-Options:
31+
- DENY
32+
X-Request-Id:
33+
- 32b2b5f8-48c2-4aef-b89e-e8da1b64cd32
34+
status: 401 Unauthorized
35+
code: 401
36+
duration: ""

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ 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.
11+
[description] Description of the ACL rule. If multiple IPs are provided, this description will be applied to all rules unless specific descriptions are provided.
12+
[descriptions] Descriptions of the ACL rules
1213
[region=fr-par] Region to target. If none is passed will use default region from the config
1314

1415
FLAGS:

internal/namespaces/rdb/v1/custom_acl.go

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ type rdbACLCustomArgs struct {
2424
ACLRuleIPs []scw.IPNet
2525
}
2626

27+
type rdbACLAddCustomArgs struct {
28+
Region scw.Region
29+
InstanceID string
30+
ACLRuleIPs []scw.IPNet
31+
Description string
32+
Descriptions []string
33+
}
34+
35+
type rdbACLAddPosArgs struct {
36+
Region scw.Region
37+
InstanceID string
38+
ACLRuleIPs scw.IPNet
39+
Description string
40+
}
41+
2742
type CustomACLResult struct {
2843
Rules []*rdb.ACLRule
2944
Success core.SuccessResult
@@ -44,29 +59,30 @@ func rdbACLCustomResultMarshalerFunc(i any, opt *human.MarshalOpt) (string, erro
4459
}
4560

4661
func aclAddBuilder(c *core.Command) *core.Command {
47-
c.ArgsType = reflect.TypeOf(rdb.AddInstanceACLRulesRequest{})
62+
c.ArgsType = reflect.TypeOf(rdbACLAddPosArgs{})
4863
c.ArgSpecs = core.ArgSpecs{
64+
{
65+
Name: "acl-rule-ips",
66+
Short: "IP addresses defined in the ACL rules of the Database Instance",
67+
Required: false,
68+
Positional: true,
69+
},
4970
{
5071
Name: "instance-id",
5172
Short: "ID of the Database Instance",
5273
Required: true,
5374
Positional: false,
5475
},
5576
{
56-
Name: "rules.{index}.ip",
57-
Short: "IP addresses defined in the ACL rules of the Database Instance",
58-
Required: false,
59-
Positional: false,
60-
},
61-
{
62-
Name: "rules.{index}.description",
63-
Short: "Description of the ACL rule. Use rules.0.description, rules.1.description, etc. to specify individual descriptions for each rule.",
77+
Name: "description",
78+
Short: "Description of the ACL rule. Indexes are not yet supported so the description will be applied to all the rules of the command.",
6479
Required: false,
6580
Positional: false,
6681
},
6782
core.RegionArgSpec(),
6883
}
69-
c.AcceptMultiplePositionalArgs = true
84+
// Keep legacy behavior: one positional per run; multiple IPs trigger multiple runs
85+
// Do not enable AcceptMultiplePositionalArgs so cobra will run once per positional
7086

7187
c.Interceptor = func(ctx context.Context, argsI any, runner core.CommandRunner) (any, error) {
7288
respI, err := runner(ctx, argsI)
@@ -78,29 +94,30 @@ func aclAddBuilder(c *core.Command) *core.Command {
7894
}
7995

8096
c.Run = func(ctx context.Context, argsI any) (i any, e error) {
81-
args := argsI.(*rdb.AddInstanceACLRulesRequest)
97+
args := argsI.(*rdbACLAddPosArgs)
8298
client := core.ExtractClient(ctx)
8399
api := rdb.NewAPI(client)
84100

85-
// Set default descriptions for rules that don't have one
86-
for i, rule := range args.Rules {
87-
if rule.Description == "" {
88-
args.Rules[i].Description = "Allow " + rule.IP.String()
89-
}
101+
desc := args.Description
102+
if desc == "" {
103+
desc = "Allow " + args.ACLRuleIPs.String()
90104
}
91105

92-
rule, err := api.AddInstanceACLRules(args, scw.WithContext(ctx))
106+
rule, err := api.AddInstanceACLRules(&rdb.AddInstanceACLRulesRequest{
107+
Region: args.Region,
108+
InstanceID: args.InstanceID,
109+
Rules: []*rdb.ACLRuleRequest{{
110+
IP: args.ACLRuleIPs,
111+
Description: desc,
112+
}},
113+
}, scw.WithContext(ctx))
93114
if err != nil {
94115
return nil, fmt.Errorf("failed to add ACL rule: %w", err)
95116
}
96117

97118
// Create success message
98119
var message string
99-
if len(args.Rules) == 1 {
100-
message = fmt.Sprintf("ACL rule %s successfully added", args.Rules[0].IP.String())
101-
} else {
102-
message = fmt.Sprintf("%d ACL rules successfully added", len(args.Rules))
103-
}
120+
message = fmt.Sprintf("ACL rule %s successfully added", args.ACLRuleIPs.String())
104121

105122
return &CustomACLResult{
106123
Rules: rule.Rules,
@@ -111,7 +128,7 @@ func aclAddBuilder(c *core.Command) *core.Command {
111128
}
112129

113130
c.WaitFunc = func(ctx context.Context, argsI, respI any) (any, error) {
114-
args := argsI.(*rdb.AddInstanceACLRulesRequest)
131+
args := argsI.(*rdbACLAddPosArgs)
115132
api := rdb.NewAPI(core.ExtractClient(ctx))
116133

117134
_, err := api.WaitForInstance(&rdb.WaitForInstanceRequest{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.6; darwin; amd64) cli-e2e-test
10+
url: https://api.scaleway.com/rdb/v1/regions/fr-par/database-engines
11+
method: GET
12+
response:
13+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
14+
headers:
15+
Content-Length:
16+
- "109"
17+
Content-Security-Policy:
18+
- default-src 'none'; frame-ancestors 'none'
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Mon, 29 Sep 2025 08:56:57 GMT
23+
Server:
24+
- Scaleway API Gateway (fr-par-1;edge03)
25+
Strict-Transport-Security:
26+
- max-age=63072000
27+
X-Content-Type-Options:
28+
- nosniff
29+
X-Frame-Options:
30+
- DENY
31+
X-Request-Id:
32+
- 6a07ae8d-8dc9-4a04-acdd-92942462daa8
33+
status: 401 Unauthorized
34+
code: 401
35+
duration: ""
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.6; darwin; amd64) cli-e2e-test
10+
url: https://api.scaleway.com/rdb/v1/regions/fr-par/database-engines
11+
method: GET
12+
response:
13+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
14+
headers:
15+
Content-Length:
16+
- "109"
17+
Content-Security-Policy:
18+
- default-src 'none'; frame-ancestors 'none'
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Mon, 29 Sep 2025 08:56:57 GMT
23+
Server:
24+
- Scaleway API Gateway (fr-par-1;edge03)
25+
Strict-Transport-Security:
26+
- max-age=63072000
27+
X-Content-Type-Options:
28+
- nosniff
29+
X-Frame-Options:
30+
- DENY
31+
X-Request-Id:
32+
- b85e4755-c3fc-427c-a05a-4b953f8b1ad9
33+
status: 401 Unauthorized
34+
code: 401
35+
duration: ""
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.6; darwin; amd64) cli-e2e-test
10+
url: https://api.scaleway.com/rdb/v1/regions/fr-par/database-engines
11+
method: GET
12+
response:
13+
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}'
14+
headers:
15+
Content-Length:
16+
- "109"
17+
Content-Security-Policy:
18+
- default-src 'none'; frame-ancestors 'none'
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Mon, 29 Sep 2025 08:56:57 GMT
23+
Server:
24+
- Scaleway API Gateway (fr-par-1;edge03)
25+
Strict-Transport-Security:
26+
- max-age=63072000
27+
X-Content-Type-Options:
28+
- nosniff
29+
X-Frame-Options:
30+
- DENY
31+
X-Request-Id:
32+
- 608f88c2-b8e7-45ed-905a-c2b45500e92b
33+
status: 401 Unauthorized
34+
code: 401
35+
duration: ""

0 commit comments

Comments
 (0)