Skip to content

Commit 01ae518

Browse files
feat(instance): add support for projects in ip (#1150)
1 parent 785ba29 commit 01ae518

28 files changed

+242
-140
lines changed

cmd/scw/testdata/test-all-usage-config-get-usage.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ EXAMPLES:
1313
scw -p prod config get default_region
1414

1515
ARGS:
16-
key the key to get from the configt (access-key | secret-key | api-url | insecure | default-organization-id | default-region | default-zone | send-telemetry)
16+
key the key to get from the configt (access-key | secret-key | api-url | insecure | default-organization-id | default-project-id | default-region | default-zone | send-telemetry)
1717

1818
FLAGS:
1919
-h, --help help for get

cmd/scw/testdata/test-all-usage-config-unset-usage.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
scw config unset <key ...> [arg=value ...]
77

88
ARGS:
9-
key the config config key name to unset (access-key | secret-key | api-url | insecure | default-organization-id | default-region | default-zone | send-telemetry)
9+
key the config config key name to unset (access-key | secret-key | api-url | insecure | default-organization-id | default-project-id | default-region | default-zone | send-telemetry)
1010

1111
FLAGS:
1212
-h, --help help for unset

cmd/scw/testdata/test-all-usage-instance-ip-create-usage.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ EXAMPLES:
1616
scw instance ip create server=11111111-1111-1111-1111-111111111111
1717

1818
ARGS:
19-
[project] The project ID the IP is reserved in
19+
[project-id] The project ID the IP is reserved in
2020
[server] UUID of the server you want to attach the IP to
2121
[tags.{index}] An array of keywords you want to tag this IP with
2222
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/mattn/go-colorable v0.1.4
2222
github.com/mattn/go-isatty v0.0.11
2323
github.com/pkg/errors v0.9.1 // indirect
24-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65
24+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200707130522-abc4aeb2a4e6
2525
github.com/sergi/go-diff v1.0.0 // indirect
2626
github.com/spf13/cobra v0.0.5
2727
github.com/spf13/pflag v1.0.5

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622145638-4884584cccc2
7171
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622145638-4884584cccc2/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
7272
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65 h1:QhG9tN5aUb20f6W8ecoH9XZwa4+0sg6ovBZrYKkp7C0=
7373
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
74+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200624111939-0a4e128e532e h1:Ef+KTOg0kjZe14rHHoC7VOjiZBrxvuViVGaga7/BLM8=
75+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200624111939-0a4e128e532e/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
76+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200707130522-abc4aeb2a4e6 h1:mCYMQVdy3ciDx7jtDnRuxTk9IUB525PhZYkCTjMWQUI=
77+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200707130522-abc4aeb2a4e6/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
7478
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
7579
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
7680
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=

internal/core/validate.go

-13
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,6 @@ func ValidateOrganizationID() ArgSpecValidateFunc {
173173
if value == "" && !argSpec.Required {
174174
return nil
175175
}
176-
return ValidateOrganizationIDRequired()(argSpec, valueI)
177-
}
178-
}
179-
180-
// ValidateOrganizationIDRequired validates a required organization ID.
181-
// We do not allow empty-string value "".
182-
func ValidateOrganizationIDRequired() ArgSpecValidateFunc {
183-
return func(argSpec *ArgSpec, valueI interface{}) error {
184-
value := valueI.(string)
185-
err := DefaultArgSpecValidateFunc()(argSpec, value)
186-
if err != nil {
187-
return err
188-
}
189176
if !validation.IsOrganizationID(value) {
190177
return InvalidOrganizationIDError(value)
191178
}

internal/e2e/testdata/test-human-create-simple.golden

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IsHappy false
1414
EyesColor unknown
1515
Status stopped
1616
Name -
17+
ProjectID 11111111-1111-1111-1111-111111111111
1718
Region fr-par
1819
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1920
{
@@ -31,5 +32,6 @@ Region fr-par
3132
"eyes_color": "unknown",
3233
"status": "stopped",
3334
"name": "",
35+
"project_id": "11111111-1111-1111-1111-111111111111",
3436
"region": "fr-par"
3537
}

internal/e2e/testdata/test-human-create-with-args.golden

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IsHappy true
1414
EyesColor amber
1515
Status stopped
1616
Name -
17+
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
1718
Region fr-par
1819
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1920
{
@@ -31,5 +32,6 @@ Region fr-par
3132
"eyes_color": "amber",
3233
"status": "stopped",
3334
"name": "",
35+
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
3436
"region": "fr-par"
3537
}

internal/e2e/testdata/test-human-delete-simple.golden

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IsHappy true
1414
EyesColor blue
1515
Status stopped
1616
Name -
17+
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
1718
Region fr-par
1819
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1920
{
@@ -31,5 +32,6 @@ Region fr-par
3132
"eyes_color": "blue",
3233
"status": "stopped",
3334
"name": "",
35+
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
3436
"region": "fr-par"
3537
}

internal/e2e/testdata/test-human-get-simple.golden

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IsHappy true
1414
EyesColor blue
1515
Status stopped
1616
Name -
17+
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
1718
Region fr-par
1819
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1920
{
@@ -31,5 +32,6 @@ Region fr-par
3132
"eyes_color": "blue",
3233
"status": "stopped",
3334
"name": "",
35+
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
3436
"region": "fr-par"
3537
}

internal/e2e/testdata/test-human-list-simple.golden

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3-
ID ORGANIZATION ID CREATED AT UPDATED AT HEIGHT SHOE SIZE ALTITUDE IN METER ALTITUDE IN MILLIMETER FINGERS COUNT HAIR COUNT IS HAPPY EYES COLOR STATUS NAME REGION
4-
0194fdc2-fa2f-fcc0-41d3-ff12045b73c8 11111111-1111-1111-1111-111111111111 few seconds ago few seconds ago 0 0 0 0 0 0 false unknown stopped - fr-par
5-
62a5eee8-2abd-f44a-2d0b-75fb180daf48 11111111-1111-1111-1111-111111111111 few seconds ago few seconds ago 0 0 0 0 0 0 false unknown stopped - fr-par
6-
39465185-0fd4-a178-892e-e285ece15114 11111111-1111-1111-1111-111111111111 few seconds ago few seconds ago 0 0 0 0 0 0 false unknown stopped - fr-par
3+
ID ORGANIZATION ID CREATED AT UPDATED AT HEIGHT SHOE SIZE ALTITUDE IN METER ALTITUDE IN MILLIMETER FINGERS COUNT HAIR COUNT IS HAPPY EYES COLOR STATUS NAME PROJECT ID REGION
4+
0194fdc2-fa2f-fcc0-41d3-ff12045b73c8 11111111-1111-1111-1111-111111111111 few seconds ago few seconds ago 0 0 0 0 0 0 false unknown stopped - 11111111-1111-1111-1111-111111111111 fr-par
5+
62a5eee8-2abd-f44a-2d0b-75fb180daf48 11111111-1111-1111-1111-111111111111 few seconds ago few seconds ago 0 0 0 0 0 0 false unknown stopped - 11111111-1111-1111-1111-111111111111 fr-par
6+
39465185-0fd4-a178-892e-e285ece15114 11111111-1111-1111-1111-111111111111 few seconds ago few seconds ago 0 0 0 0 0 0 false unknown stopped - 11111111-1111-1111-1111-111111111111 fr-par
77
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
88
[
99
{
@@ -21,6 +21,7 @@ ID ORGANIZATION ID CREA
2121
"eyes_color": "unknown",
2222
"status": "stopped",
2323
"name": "",
24+
"project_id": "11111111-1111-1111-1111-111111111111",
2425
"region": "fr-par"
2526
},
2627
{
@@ -38,6 +39,7 @@ ID ORGANIZATION ID CREA
3839
"eyes_color": "unknown",
3940
"status": "stopped",
4041
"name": "",
42+
"project_id": "11111111-1111-1111-1111-111111111111",
4143
"region": "fr-par"
4244
},
4345
{
@@ -55,6 +57,7 @@ ID ORGANIZATION ID CREA
5557
"eyes_color": "unknown",
5658
"status": "stopped",
5759
"name": "",
60+
"project_id": "11111111-1111-1111-1111-111111111111",
5861
"region": "fr-par"
5962
}
6063
]

internal/e2e/testdata/test-human-update-multiple-args.golden

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IsHappy true
1414
EyesColor blue
1515
Status stopped
1616
Name -
17+
ProjectID 11111111-1111-1111-1111-111111111111
1718
Region fr-par
1819
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1920
{
@@ -31,5 +32,6 @@ Region fr-par
3132
"eyes_color": "blue",
3233
"status": "stopped",
3334
"name": "",
35+
"project_id": "11111111-1111-1111-1111-111111111111",
3436
"region": "fr-par"
3537
}

internal/e2e/testdata/test-human-update-single-arg.golden

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IsHappy false
1414
EyesColor amber
1515
Status stopped
1616
Name -
17+
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
1718
Region fr-par
1819
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
1920
{
@@ -31,5 +32,6 @@ Region fr-par
3132
"eyes_color": "amber",
3233
"status": "stopped",
3334
"name": "",
35+
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
3436
"region": "fr-par"
3537
}

internal/namespaces/config/testdata/test-config-dump-command-simple.golden

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ profiles:
3232
"APIURL": null,
3333
"Insecure": true,
3434
"DefaultOrganizationID": "11111111-1111-1111-1111-111111111111",
35+
"DefaultProjectID": null,
3536
"DefaultRegion": "fr-par",
3637
"DefaultZone": "fr-par-1",
3738
"SendTelemetry": true,
@@ -43,6 +44,7 @@ profiles:
4344
"APIURL": "https://p1-mock-api-url.com",
4445
"Insecure": true,
4546
"DefaultOrganizationID": "11111111-1111-1111-1111-111111111111",
47+
"DefaultProjectID": null,
4648
"DefaultRegion": "fr-par",
4749
"DefaultZone": "fr-par-1",
4850
"SendTelemetry": null
@@ -53,6 +55,7 @@ profiles:
5355
"APIURL": "https://p2-mock-api-url.com",
5456
"Insecure": true,
5557
"DefaultOrganizationID": "11111111-1111-1111-1111-111111111111",
58+
"DefaultProjectID": null,
5659
"DefaultRegion": "fr-par",
5760
"DefaultZone": "fr-par-1",
5861
"SendTelemetry": null

internal/namespaces/instance/v1/custom.go

+6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ import (
1212
var (
1313
oldOrganizationFieldName = "organization"
1414
newOrganizationFieldName = "organization-id"
15+
oldProjectFieldName = "project"
16+
newProjectFieldName = "project-id"
1517
)
1618

1719
// helpers
1820
func renameOrganizationIDArgSpec(argSpecs core.ArgSpecs) {
1921
argSpecs.GetByName(oldOrganizationFieldName).Name = newOrganizationFieldName
2022
}
2123

24+
func renameProjectIDArgSpec(argSpecs core.ArgSpecs) {
25+
argSpecs.GetByName(oldProjectFieldName).Name = newProjectFieldName
26+
}
27+
2228
// GetCommands returns instance commands.
2329
//
2430
// This function:

internal/namespaces/instance/v1/custom_ip.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313
func ipCreateBuilder(c *core.Command) *core.Command {
1414
type customCreateIPRequest struct {
1515
*instance.CreateIPRequest
16-
OrganizationID string
16+
OrganizationID *string
17+
ProjectID *string
1718
}
1819

1920
renameOrganizationIDArgSpec(c.ArgSpecs)
21+
renameProjectIDArgSpec(c.ArgSpecs)
2022

2123
c.ArgsType = reflect.TypeOf(customCreateIPRequest{})
2224

@@ -28,6 +30,7 @@ func ipCreateBuilder(c *core.Command) *core.Command {
2830
}
2931
request := args.CreateIPRequest
3032
request.Organization = args.OrganizationID
33+
request.Project = args.ProjectID
3134

3235
return runner(ctx, request)
3336
})

internal/namespaces/instance/v1/custom_server_create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
330330
logger.Debugf("creating IP")
331331
res, err := apiInstance.CreateIP(&instance.CreateIPRequest{
332332
Zone: args.Zone,
333-
Organization: args.OrganizationID,
333+
Organization: scw.StringPtr(args.OrganizationID),
334334
})
335335
if err != nil {
336336
return nil, fmt.Errorf("error while creating your public IP: %s", err)

internal/namespaces/instance/v1/testdata/test-ip-create-simple.cassette.yaml

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,37 @@ interactions:
88
Content-Type:
99
- application/json
1010
User-Agent:
11-
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14; darwin; amd64) cli-e2e-test
11+
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test
1212
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/ips
1313
method: POST
1414
response:
15-
body: '{"ip": {"id": "10d0c80b-25a4-4cfd-b71f-9e6c196ada1b", "address": "51.15.248.118",
15+
body: '{"ip": {"id": "dc78c1dd-4436-4193-b82f-94bd5881ea35", "address": "51.15.215.79",
1616
"reverse": null, "server": null, "organization": "951df375-e094-4d26-97c1-ba548eeb9c42",
17-
"zone": "fr-par-1", "tags": []}}'
17+
"project": "951df375-e094-4d26-97c1-ba548eeb9c42", "zone": "fr-par-1", "tags":
18+
[]}}'
1819
headers:
1920
Cache-Control:
2021
- no-cache
2122
Content-Length:
22-
- "203"
23+
- "253"
2324
Content-Security-Policy:
2425
- default-src 'none'; frame-ancestors 'none'
2526
Content-Type:
2627
- application/json
2728
Date:
28-
- Wed, 18 Mar 2020 10:17:37 GMT
29+
- Tue, 07 Jul 2020 13:53:15 GMT
2930
Location:
30-
- https://cp-par1.scaleway.com/ips/10d0c80b-25a4-4cfd-b71f-9e6c196ada1b
31+
- https://cp-par1.scaleway.com/ips/dc78c1dd-4436-4193-b82f-94bd5881ea35
3132
Server:
32-
- scaleway_api
33+
- agw_listener_public_vip
3334
Strict-Transport-Security:
3435
- max-age=63072000
3536
X-Content-Type-Options:
3637
- nosniff
3738
X-Frame-Options:
3839
- DENY
40+
X-Request-Id:
41+
- 165e7498-ab80-42ff-a56f-e3fb82e851ca
3942
status: 201 Created
4043
code: 201
4144
duration: ""
@@ -44,8 +47,8 @@ interactions:
4447
form: {}
4548
headers:
4649
User-Agent:
47-
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14; darwin; amd64) cli-e2e-test
48-
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/ips/10d0c80b-25a4-4cfd-b71f-9e6c196ada1b
50+
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test
51+
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/ips/dc78c1dd-4436-4193-b82f-94bd5881ea35
4952
method: DELETE
5053
response:
5154
body: ""
@@ -57,15 +60,17 @@ interactions:
5760
Content-Type:
5861
- application/json
5962
Date:
60-
- Wed, 18 Mar 2020 10:17:37 GMT
63+
- Tue, 07 Jul 2020 13:53:15 GMT
6164
Server:
62-
- scaleway_api
65+
- agw_listener_public_vip
6366
Strict-Transport-Security:
6467
- max-age=63072000
6568
X-Content-Type-Options:
6669
- nosniff
6770
X-Frame-Options:
6871
- DENY
72+
X-Request-Id:
73+
- 1e8c91f2-eacf-41e9-8200-df57898ee4be
6974
status: 204 No Content
7075
code: 204
7176
duration: ""

internal/namespaces/instance/v1/testdata/test-ip-create-simple.golden

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3-
ID 10d0c80b-25a4-4cfd-b71f-9e6c196ada1b
4-
Address 51.15.248.118
3+
ID dc78c1dd-4436-4193-b82f-94bd5881ea35
4+
Address 51.15.215.79
55
Organization 951df375-e094-4d26-97c1-ba548eeb9c42
6+
Project 951df375-e094-4d26-97c1-ba548eeb9c42
67
Zone fr-par-1
78
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
89
{
910
"ip": {
10-
"id": "10d0c80b-25a4-4cfd-b71f-9e6c196ada1b",
11-
"address": "51.15.248.118",
11+
"id": "dc78c1dd-4436-4193-b82f-94bd5881ea35",
12+
"address": "51.15.215.79",
1213
"reverse": null,
1314
"server": null,
1415
"organization": "951df375-e094-4d26-97c1-ba548eeb9c42",
1516
"tags": [],
17+
"project": "951df375-e094-4d26-97c1-ba548eeb9c42",
1618
"zone": "fr-par-1"
1719
},
1820
"Location": ""

0 commit comments

Comments
 (0)