From 5b1f5ad05b00181e8786ab57aa34146394750594 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Mon, 16 Sep 2024 09:41:23 +0200 Subject: [PATCH] feat(vpc): enable route cli generation (#4128) --- ...st-all-usage-vpc-route-create-usage.golden | 24 ++ ...st-all-usage-vpc-route-delete-usage.golden | 19 ++ .../test-all-usage-vpc-route-get-usage.golden | 19 ++ ...test-all-usage-vpc-route-list-usage.golden | 26 +++ ...st-all-usage-vpc-route-update-usage.golden | 24 ++ .../test-all-usage-vpc-route-usage.golden | 5 + .../testdata/test-all-usage-vpc-usage.golden | 1 - docs/commands/vpc.md | 96 +++++++- go.mod | 2 +- go.sum | 4 +- internal/namespaces/vpc/v2/vpc_cli.go | 216 ++++++++++++++++-- 11 files changed, 415 insertions(+), 21 deletions(-) create mode 100644 cmd/scw/testdata/test-all-usage-vpc-route-create-usage.golden create mode 100644 cmd/scw/testdata/test-all-usage-vpc-route-delete-usage.golden create mode 100644 cmd/scw/testdata/test-all-usage-vpc-route-get-usage.golden create mode 100644 cmd/scw/testdata/test-all-usage-vpc-route-list-usage.golden create mode 100644 cmd/scw/testdata/test-all-usage-vpc-route-update-usage.golden diff --git a/cmd/scw/testdata/test-all-usage-vpc-route-create-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-route-create-usage.golden new file mode 100644 index 0000000000..ecbc1b2a17 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-vpc-route-create-usage.golden @@ -0,0 +1,24 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Create a new custom Route. + +USAGE: + scw vpc route create [arg=value ...] + +ARGS: + [description] Route description + [tags.{index}] Tags of the Route + [vpc-id] VPC the Route belongs to + [destination] Destination of the Route + [nexthop-resource-id] ID of the nexthop resource + [nexthop-private-network-id] ID of the nexthop private network + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) + +FLAGS: + -h, --help help for create + +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 diff --git a/cmd/scw/testdata/test-all-usage-vpc-route-delete-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-route-delete-usage.golden new file mode 100644 index 0000000000..1c83ffa10c --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-vpc-route-delete-usage.golden @@ -0,0 +1,19 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Delete a Route specified by its Route ID. + +USAGE: + scw vpc route delete [arg=value ...] + +ARGS: + route-id Route ID + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) + +FLAGS: + -h, --help help for delete + +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 diff --git a/cmd/scw/testdata/test-all-usage-vpc-route-get-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-route-get-usage.golden new file mode 100644 index 0000000000..ba0ab5a309 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-vpc-route-get-usage.golden @@ -0,0 +1,19 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Retrieve details of an existing Route, specified by its Route ID. + +USAGE: + scw vpc route get [arg=value ...] + +ARGS: + route-id Route ID + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) + +FLAGS: + -h, --help help for get + +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 diff --git a/cmd/scw/testdata/test-all-usage-vpc-route-list-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-route-list-usage.golden new file mode 100644 index 0000000000..cfa9122ba9 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-vpc-route-list-usage.golden @@ -0,0 +1,26 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Return routes with associated next hop data. + +USAGE: + scw vpc route list [arg=value ...] + +ARGS: + [order-by] Sort order of the returned routes (created_at_asc | created_at_desc | destination_asc | destination_desc | prefix_len_asc | prefix_len_desc) + [vpc-id] VPC to filter for. Only routes within this VPC will be returned + [nexthop-resource-id] Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned + [nexthop-private-network-id] Next hop private network ID to filter for. Only routes with a matching next hop private network ID will be returned + [nexthop-resource-type] Next hop resource type to filter for. Only Routes with a matching next hop resource type will be returned (unknown_type | vpc_gateway_network | instance_private_nic | baremetal_private_nic) + [contains] Only routes whose destination is contained in this subnet will be returned + [tags.{index}] Tags to filter for, only routes with one or more matching tags will be returned + [is-ipv6] Only routes with an IPv6 destination will be returned + [region=fr-par] Region to target. If none is passed will use default region from the config (all) + +FLAGS: + -h, --help help for list + +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 diff --git a/cmd/scw/testdata/test-all-usage-vpc-route-update-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-route-update-usage.golden new file mode 100644 index 0000000000..18ad529954 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-vpc-route-update-usage.golden @@ -0,0 +1,24 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Update parameters of the specified Route. + +USAGE: + scw vpc route update [arg=value ...] + +ARGS: + route-id Route ID + [description] Route description + [tags.{index}] Tags of the Route + [destination] Destination of the Route + [nexthop-resource-id] ID of the nexthop resource + [nexthop-private-network-id] ID of the nexthop private network + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) + +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 diff --git a/cmd/scw/testdata/test-all-usage-vpc-route-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-route-usage.golden index 96c9e50bbb..24b213b590 100644 --- a/cmd/scw/testdata/test-all-usage-vpc-route-usage.golden +++ b/cmd/scw/testdata/test-all-usage-vpc-route-usage.golden @@ -6,7 +6,12 @@ USAGE: scw vpc route AVAILABLE COMMANDS: + create Create a Route + delete Delete a Route enable-routing Enable routing on a VPC + get Get a Route + list Return routes with associated next hop data + update Update Route FLAGS: -h, --help help for route diff --git a/cmd/scw/testdata/test-all-usage-vpc-usage.golden b/cmd/scw/testdata/test-all-usage-vpc-usage.golden index dbd5ab4fa5..c0a9731183 100644 --- a/cmd/scw/testdata/test-all-usage-vpc-usage.golden +++ b/cmd/scw/testdata/test-all-usage-vpc-usage.golden @@ -8,7 +8,6 @@ USAGE: AVAILABLE COMMANDS: private-network Private network management command route Route management command - routes Routes management command subnet Subnet management command vpc VPC management command diff --git a/docs/commands/vpc.md b/docs/commands/vpc.md index b17663e84f..5141adc9f4 100644 --- a/docs/commands/vpc.md +++ b/docs/commands/vpc.md @@ -11,9 +11,12 @@ This API allows you to manage your Virtual Private Clouds (VPCs) and Private Net - [Migrate Private Networks from zoned to regional](#migrate-private-networks-from-zoned-to-regional) - [Update Private Network](#update-private-network) - [Route management command](#route-management-command) + - [Create a Route](#create-a-route) + - [Delete a Route](#delete-a-route) - [Enable routing on a VPC](#enable-routing-on-a-vpc) -- [Routes management command](#routes-management-command) + - [Get a Route](#get-a-route) - [Return routes with associated next hop data](#return-routes-with-associated-next-hop-data) + - [Update Route](#update-route) - [Subnet management command](#subnet-management-command) - [VPC management command](#vpc-management-command) - [Create a VPC](#create-a-vpc) @@ -191,6 +194,51 @@ scw vpc private-network update [arg=value ...] Custom routes. +### Create a Route + +Create a new custom Route. + +**Usage:** + +``` +scw vpc route create [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| description | | Route description | +| tags.{index} | | Tags of the Route | +| vpc-id | | VPC the Route belongs to | +| destination | | Destination of the Route | +| nexthop-resource-id | | ID of the nexthop resource | +| nexthop-private-network-id | | ID of the nexthop private network | +| region | Default: `fr-par`
One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config | + + + +### Delete a Route + +Delete a Route specified by its Route ID. + +**Usage:** + +``` +scw vpc route delete [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| route-id | Required | Route ID | +| region | Default: `fr-par`
One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config | + + + ### Enable routing on a VPC Enable routing on an existing VPC. Note that you will not be able to deactivate it afterwards. @@ -211,9 +259,24 @@ scw vpc route enable-routing [arg=value ...] -## Routes management command +### Get a Route + +Retrieve details of an existing Route, specified by its Route ID. + +**Usage:** + +``` +scw vpc route get [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| route-id | Required | Route ID | +| region | Default: `fr-par`
One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config | -Routes management command. ### Return routes with associated next hop data @@ -223,7 +286,7 @@ Return routes with associated next hop data. **Usage:** ``` -scw vpc routes list [arg=value ...] +scw vpc route list [arg=value ...] ``` @@ -243,6 +306,31 @@ scw vpc routes list [arg=value ...] +### Update Route + +Update parameters of the specified Route. + +**Usage:** + +``` +scw vpc route update [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| route-id | Required | Route ID | +| description | | Route description | +| tags.{index} | | Tags of the Route | +| destination | | Destination of the Route | +| nexthop-resource-id | | ID of the nexthop resource | +| nexthop-private-network-id | | ID of the nexthop private network | +| region | Default: `fr-par`
One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config | + + + ## Subnet management command CIDR Subnet. diff --git a/go.mod b/go.mod index efd80e93dc..781bdd3ebd 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/mattn/go-isatty v0.0.20 github.com/moby/buildkit v0.13.2 github.com/opencontainers/go-digest v1.0.0 - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240910124414-bec257c2bbc7 + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240912155428-d319ae16fc2a github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 71fe7252ab..b874edb1d0 100644 --- a/go.sum +++ b/go.sum @@ -465,8 +465,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240910124414-bec257c2bbc7 h1:CFtaqYB/yhupu2aNrTo6uU83VgDKQbxyjBAYBvqfJr4= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240910124414-bec257c2bbc7/go.mod h1:o/2twhmcz4HlhtuuubCuwQ/fe+zyzoJR85+02gy04yY= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240912155428-d319ae16fc2a h1:rDcrJhNF+Fh3wkXQD/Bre5XhzO4rVZrCLsMTapWE8p0= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240912155428-d319ae16fc2a/go.mod h1:o/2twhmcz4HlhtuuubCuwQ/fe+zyzoJR85+02gy04yY= github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA= diff --git a/internal/namespaces/vpc/v2/vpc_cli.go b/internal/namespaces/vpc/v2/vpc_cli.go index f504d65a46..a652f806a0 100644 --- a/internal/namespaces/vpc/v2/vpc_cli.go +++ b/internal/namespaces/vpc/v2/vpc_cli.go @@ -24,7 +24,6 @@ func GetGeneratedCommands() *core.Commands { vpcPrivateNetwork(), vpcSubnet(), vpcRoute(), - vpcRoutes(), vpcVpcList(), vpcVpcCreate(), vpcVpcGet(), @@ -38,7 +37,11 @@ func GetGeneratedCommands() *core.Commands { vpcPrivateNetworkMigrateToRegional(), vpcPrivateNetworkEnableDHCP(), vpcRouteEnableRouting(), - vpcRoutesList(), + vpcRouteCreate(), + vpcRouteGet(), + vpcRouteUpdate(), + vpcRouteDelete(), + vpcRouteList(), ) } func vpcRoot() *core.Command { @@ -90,15 +93,6 @@ func vpcRoute() *core.Command { } } -func vpcRoutes() *core.Command { - return &core.Command{ - Short: `Routes management command`, - Long: `Routes management command.`, - Namespace: "vpc", - Resource: "routes", - } -} - func vpcVpcList() *core.Command { return &core.Command{ Short: `List VPCs`, @@ -687,12 +681,208 @@ func vpcRouteEnableRouting() *core.Command { } } -func vpcRoutesList() *core.Command { +func vpcRouteCreate() *core.Command { + return &core.Command{ + Short: `Create a Route`, + Long: `Create a new custom Route.`, + Namespace: "vpc", + Resource: "route", + Verb: "create", + // Deprecated: false, + ArgsType: reflect.TypeOf(vpc.CreateRouteRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "description", + Short: `Route description`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "tags.{index}", + Short: `Tags of the Route`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "vpc-id", + Short: `VPC the Route belongs to`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "destination", + Short: `Destination of the Route`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "nexthop-resource-id", + Short: `ID of the nexthop resource`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "nexthop-private-network-id", + Short: `ID of the nexthop private network`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*vpc.CreateRouteRequest) + + client := core.ExtractClient(ctx) + api := vpc.NewAPI(client) + return api.CreateRoute(request) + + }, + } +} + +func vpcRouteGet() *core.Command { + return &core.Command{ + Short: `Get a Route`, + Long: `Retrieve details of an existing Route, specified by its Route ID.`, + Namespace: "vpc", + Resource: "route", + Verb: "get", + // Deprecated: false, + ArgsType: reflect.TypeOf(vpc.GetRouteRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "route-id", + Short: `Route ID`, + Required: true, + Deprecated: false, + Positional: true, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*vpc.GetRouteRequest) + + client := core.ExtractClient(ctx) + api := vpc.NewAPI(client) + return api.GetRoute(request) + + }, + } +} + +func vpcRouteUpdate() *core.Command { + return &core.Command{ + Short: `Update Route`, + Long: `Update parameters of the specified Route.`, + Namespace: "vpc", + Resource: "route", + Verb: "update", + // Deprecated: false, + ArgsType: reflect.TypeOf(vpc.UpdateRouteRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "route-id", + Short: `Route ID`, + Required: true, + Deprecated: false, + Positional: true, + }, + { + Name: "description", + Short: `Route description`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "tags.{index}", + Short: `Tags of the Route`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "destination", + Short: `Destination of the Route`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "nexthop-resource-id", + Short: `ID of the nexthop resource`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "nexthop-private-network-id", + Short: `ID of the nexthop private network`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*vpc.UpdateRouteRequest) + + client := core.ExtractClient(ctx) + api := vpc.NewAPI(client) + return api.UpdateRoute(request) + + }, + } +} + +func vpcRouteDelete() *core.Command { + return &core.Command{ + Short: `Delete a Route`, + Long: `Delete a Route specified by its Route ID.`, + Namespace: "vpc", + Resource: "route", + Verb: "delete", + // Deprecated: false, + ArgsType: reflect.TypeOf(vpc.DeleteRouteRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "route-id", + Short: `Route ID`, + Required: true, + Deprecated: false, + Positional: true, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*vpc.DeleteRouteRequest) + + client := core.ExtractClient(ctx) + api := vpc.NewAPI(client) + e = api.DeleteRoute(request) + if e != nil { + return nil, e + } + return &core.SuccessResult{ + Resource: "route", + Verb: "delete", + }, nil + }, + } +} + +func vpcRouteList() *core.Command { return &core.Command{ Short: `Return routes with associated next hop data`, Long: `Return routes with associated next hop data.`, Namespace: "vpc", - Resource: "routes", + Resource: "route", Verb: "list", // Deprecated: false, ArgsType: reflect.TypeOf(vpc.RoutesWithNexthopAPIListRoutesWithNexthopRequest{}),