Skip to content

Commit 22b60dd

Browse files
scaleway-botremyleone
authored andcommitted
feat(vpc): enable acl cli generation (scaleway#4594)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 8538d1f commit 22b60dd

File tree

7 files changed

+256
-6
lines changed

7 files changed

+256
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Retrieve a list of ACL rules for a VPC, specified by its VPC ID.
4+
5+
USAGE:
6+
scw vpc rule get [arg=value ...]
7+
8+
ARGS:
9+
vpc-id ID of the Network ACL's VPC
10+
is-ipv6 Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type.
11+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)
12+
13+
FLAGS:
14+
-h, --help help for get
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Set the list of ACL rules and the default routing policy for a VPC.
4+
5+
USAGE:
6+
scw vpc rule set [arg=value ...]
7+
8+
ARGS:
9+
vpc-id ID of the Network ACL's VPC
10+
rules.{index}.protocol Protocol to which this rule applies (ANY | TCP | UDP | ICMP)
11+
rules.{index}.source Source IP range to which this rule applies (CIDR notation with subnet mask)
12+
rules.{index}.src-port-low Starting port of the source port range to which this rule applies (inclusive)
13+
rules.{index}.src-port-high Ending port of the source port range to which this rule applies (inclusive)
14+
rules.{index}.destination Destination IP range to which this rule applies (CIDR notation with subnet mask)
15+
rules.{index}.dst-port-low Starting port of the destination port range to which this rule applies (inclusive)
16+
rules.{index}.dst-port-high Ending port of the destination port range to which this rule applies (inclusive)
17+
rules.{index}.action Policy to apply to the packet (unknown_action | accept | drop)
18+
rules.{index}.description Rule description
19+
is-ipv6 Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type.
20+
default-policy Action to take for packets which do not match any rules (unknown_action | accept | drop)
21+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)
22+
23+
FLAGS:
24+
-h, --help help for set
25+
26+
GLOBAL FLAGS:
27+
-c, --config string The path to the config file
28+
-D, --debug Enable debug mode
29+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
30+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-vpc-rule-usage.golden

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Acl Rules.
44

55
USAGE:
6-
scw vpc rule
6+
scw vpc rule <command>
7+
8+
AVAILABLE COMMANDS:
9+
get Get Acl Rules for VPC
10+
set Set VPC ACL rules
711

812
FLAGS:
913
-h, --help help for rule
@@ -13,3 +17,5 @@ GLOBAL FLAGS:
1317
-D, --debug Enable debug mode
1418
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
1519
-p, --profile string The config profile to use
20+
21+
Use "scw vpc rule [command] --help" for more information about a command.

docs/commands/vpc.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This API allows you to manage your Virtual Private Clouds (VPCs) and Private Net
1717
- [Return routes with associated next hop data](#return-routes-with-associated-next-hop-data)
1818
- [Update Route](#update-route)
1919
- [Rule management command](#rule-management-command)
20+
- [Get Acl Rules for VPC](#get-acl-rules-for-vpc)
21+
- [Set VPC ACL rules](#set-vpc-acl-rules)
2022
- [Subnet management command](#subnet-management-command)
2123
- [VPC management command](#vpc-management-command)
2224
- [Create a VPC](#create-a-vpc)
@@ -313,15 +315,58 @@ scw vpc route update <route-id ...> [arg=value ...]
313315

314316
Acl Rules.
315317

316-
Acl Rules.
318+
319+
### Get Acl Rules for VPC
320+
321+
Retrieve a list of ACL rules for a VPC, specified by its VPC ID.
322+
323+
**Usage:**
324+
325+
```
326+
scw vpc rule get [arg=value ...]
327+
```
328+
329+
330+
**Args:**
331+
332+
| Name | | Description |
333+
|------|---|-------------|
334+
| vpc-id | Required | ID of the Network ACL's VPC |
335+
| is-ipv6 | Required | Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type. |
336+
| 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 |
337+
338+
339+
340+
### Set VPC ACL rules
341+
342+
Set the list of ACL rules and the default routing policy for a VPC.
317343

318344
**Usage:**
319345

320346
```
321-
scw vpc rule
347+
scw vpc rule set [arg=value ...]
322348
```
323349

324350

351+
**Args:**
352+
353+
| Name | | Description |
354+
|------|---|-------------|
355+
| vpc-id | Required | ID of the Network ACL's VPC |
356+
| rules.{index}.protocol | Required<br />One of: `ANY`, `TCP`, `UDP`, `ICMP` | Protocol to which this rule applies |
357+
| rules.{index}.source | Required | Source IP range to which this rule applies (CIDR notation with subnet mask) |
358+
| rules.{index}.src-port-low | Required | Starting port of the source port range to which this rule applies (inclusive) |
359+
| rules.{index}.src-port-high | Required | Ending port of the source port range to which this rule applies (inclusive) |
360+
| rules.{index}.destination | Required | Destination IP range to which this rule applies (CIDR notation with subnet mask) |
361+
| rules.{index}.dst-port-low | Required | Starting port of the destination port range to which this rule applies (inclusive) |
362+
| rules.{index}.dst-port-high | Required | Ending port of the destination port range to which this rule applies (inclusive) |
363+
| rules.{index}.action | Required<br />One of: `unknown_action`, `accept`, `drop` | Policy to apply to the packet |
364+
| rules.{index}.description | Required | Rule description |
365+
| is-ipv6 | Required | Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type. |
366+
| default-policy | Required<br />One of: `unknown_action`, `accept`, `drop` | Action to take for packets which do not match any rules |
367+
| 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 |
368+
369+
325370

326371
## Subnet management command
327372

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/mattn/go-isatty v0.0.20
2626
github.com/moby/buildkit v0.13.2
2727
github.com/opencontainers/go-digest v1.0.0
28-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250317081556-ba26a9f2b785
28+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250318071030-c9219eeb27a0
2929
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
3030
github.com/spf13/cobra v1.9.1
3131
github.com/spf13/pflag v1.0.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
462462
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
463463
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
464464
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
465-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250317081556-ba26a9f2b785 h1:exmunaUMPq9jpmmQgKuuNUn3akjLodGtBNQLNiVYenI=
466-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250317081556-ba26a9f2b785/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
465+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250318071030-c9219eeb27a0 h1:PETheFa72UbxYylRz9ZNY0oUs1CkY3YHfQwv9o6EpCM=
466+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250318071030-c9219eeb27a0/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
467467
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
468468
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
469469
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=

internal/namespaces/vpc/v2/vpc_cli.go

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func GetGeneratedCommands() *core.Commands {
4141
vpcRouteGet(),
4242
vpcRouteUpdate(),
4343
vpcRouteDelete(),
44+
vpcRuleGet(),
45+
vpcRuleSet(),
4446
vpcRouteList(),
4547
)
4648
}
@@ -848,6 +850,153 @@ func vpcRouteDelete() *core.Command {
848850
}
849851
}
850852

853+
func vpcRuleGet() *core.Command {
854+
return &core.Command{
855+
Short: `Get Acl Rules for VPC`,
856+
Long: `Retrieve a list of ACL rules for a VPC, specified by its VPC ID.`,
857+
Namespace: "vpc",
858+
Resource: "rule",
859+
Verb: "get",
860+
// Deprecated: false,
861+
ArgsType: reflect.TypeOf(vpc.GetACLRequest{}),
862+
ArgSpecs: core.ArgSpecs{
863+
{
864+
Name: "vpc-id",
865+
Short: `ID of the Network ACL's VPC`,
866+
Required: true,
867+
Deprecated: false,
868+
Positional: false,
869+
},
870+
{
871+
Name: "is-ipv6",
872+
Short: `Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type.`,
873+
Required: true,
874+
Deprecated: false,
875+
Positional: false,
876+
},
877+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
878+
},
879+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
880+
request := args.(*vpc.GetACLRequest)
881+
882+
client := core.ExtractClient(ctx)
883+
api := vpc.NewAPI(client)
884+
return api.GetACL(request)
885+
886+
},
887+
}
888+
}
889+
890+
func vpcRuleSet() *core.Command {
891+
return &core.Command{
892+
Short: `Set VPC ACL rules`,
893+
Long: `Set the list of ACL rules and the default routing policy for a VPC.`,
894+
Namespace: "vpc",
895+
Resource: "rule",
896+
Verb: "set",
897+
// Deprecated: false,
898+
ArgsType: reflect.TypeOf(vpc.SetACLRequest{}),
899+
ArgSpecs: core.ArgSpecs{
900+
{
901+
Name: "vpc-id",
902+
Short: `ID of the Network ACL's VPC`,
903+
Required: true,
904+
Deprecated: false,
905+
Positional: false,
906+
},
907+
{
908+
Name: "rules.{index}.protocol",
909+
Short: `Protocol to which this rule applies`,
910+
Required: true,
911+
Deprecated: false,
912+
Positional: false,
913+
EnumValues: []string{"ANY", "TCP", "UDP", "ICMP"},
914+
},
915+
{
916+
Name: "rules.{index}.source",
917+
Short: `Source IP range to which this rule applies (CIDR notation with subnet mask)`,
918+
Required: true,
919+
Deprecated: false,
920+
Positional: false,
921+
},
922+
{
923+
Name: "rules.{index}.src-port-low",
924+
Short: `Starting port of the source port range to which this rule applies (inclusive)`,
925+
Required: true,
926+
Deprecated: false,
927+
Positional: false,
928+
},
929+
{
930+
Name: "rules.{index}.src-port-high",
931+
Short: `Ending port of the source port range to which this rule applies (inclusive)`,
932+
Required: true,
933+
Deprecated: false,
934+
Positional: false,
935+
},
936+
{
937+
Name: "rules.{index}.destination",
938+
Short: `Destination IP range to which this rule applies (CIDR notation with subnet mask)`,
939+
Required: true,
940+
Deprecated: false,
941+
Positional: false,
942+
},
943+
{
944+
Name: "rules.{index}.dst-port-low",
945+
Short: `Starting port of the destination port range to which this rule applies (inclusive)`,
946+
Required: true,
947+
Deprecated: false,
948+
Positional: false,
949+
},
950+
{
951+
Name: "rules.{index}.dst-port-high",
952+
Short: `Ending port of the destination port range to which this rule applies (inclusive)`,
953+
Required: true,
954+
Deprecated: false,
955+
Positional: false,
956+
},
957+
{
958+
Name: "rules.{index}.action",
959+
Short: `Policy to apply to the packet`,
960+
Required: true,
961+
Deprecated: false,
962+
Positional: false,
963+
EnumValues: []string{"unknown_action", "accept", "drop"},
964+
},
965+
{
966+
Name: "rules.{index}.description",
967+
Short: `Rule description`,
968+
Required: true,
969+
Deprecated: false,
970+
Positional: false,
971+
},
972+
{
973+
Name: "is-ipv6",
974+
Short: `Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type.`,
975+
Required: true,
976+
Deprecated: false,
977+
Positional: false,
978+
},
979+
{
980+
Name: "default-policy",
981+
Short: `Action to take for packets which do not match any rules`,
982+
Required: true,
983+
Deprecated: false,
984+
Positional: false,
985+
EnumValues: []string{"unknown_action", "accept", "drop"},
986+
},
987+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
988+
},
989+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
990+
request := args.(*vpc.SetACLRequest)
991+
992+
client := core.ExtractClient(ctx)
993+
api := vpc.NewAPI(client)
994+
return api.SetACL(request)
995+
996+
},
997+
}
998+
}
999+
8511000
func vpcRouteList() *core.Command {
8521001
return &core.Command{
8531002
Short: `Return routes with associated next hop data`,

0 commit comments

Comments
 (0)