Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle projects #1150

Merged
merged 8 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-all-usage-config-get-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ EXAMPLES:
scw -p prod config get default_region

ARGS:
key the key to get from the configt (access-key | secret-key | api-url | insecure | default-organization-id | default-region | default-zone | send-telemetry)
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)

FLAGS:
-h, --help help for get
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-all-usage-config-unset-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ USAGE:
scw config unset <key ...> [arg=value ...]

ARGS:
key the config config key name to unset (access-key | secret-key | api-url | insecure | default-organization-id | default-region | default-zone | send-telemetry)
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)

FLAGS:
-h, --help help for unset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EXAMPLES:
scw instance ip create server=11111111-1111-1111-1111-111111111111

ARGS:
[project] The project ID the IP is reserved in
[project-id] The project ID the IP is reserved in
[server] UUID of the server you want to attach the IP to
[tags.{index}] An array of keywords you want to tag this IP with
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/mattn/go-colorable v0.1.4
github.com/mattn/go-isatty v0.0.11
github.com/pkg/errors v0.9.1 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200707130522-abc4aeb2a4e6
github.com/sergi/go-diff v1.0.0 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622145638-4884584cccc2
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622145638-4884584cccc2/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65 h1:QhG9tN5aUb20f6W8ecoH9XZwa4+0sg6ovBZrYKkp7C0=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200624111939-0a4e128e532e h1:Ef+KTOg0kjZe14rHHoC7VOjiZBrxvuViVGaga7/BLM8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200624111939-0a4e128e532e/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200707130522-abc4aeb2a4e6 h1:mCYMQVdy3ciDx7jtDnRuxTk9IUB525PhZYkCTjMWQUI=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200707130522-abc4aeb2a4e6/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
13 changes: 0 additions & 13 deletions internal/core/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,6 @@ func ValidateOrganizationID() ArgSpecValidateFunc {
if value == "" && !argSpec.Required {
return nil
}
return ValidateOrganizationIDRequired()(argSpec, valueI)
}
}

// ValidateOrganizationIDRequired validates a required organization ID.
// We do not allow empty-string value "".
func ValidateOrganizationIDRequired() ArgSpecValidateFunc {
return func(argSpec *ArgSpec, valueI interface{}) error {
value := valueI.(string)
err := DefaultArgSpecValidateFunc()(argSpec, value)
if err != nil {
return err
}
if !validation.IsOrganizationID(value) {
return InvalidOrganizationIDError(value)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/e2e/testdata/test-human-create-simple.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IsHappy false
EyesColor unknown
Status stopped
Name -
ProjectID 11111111-1111-1111-1111-111111111111
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
Expand All @@ -31,5 +32,6 @@ Region fr-par
"eyes_color": "unknown",
"status": "stopped",
"name": "",
"project_id": "11111111-1111-1111-1111-111111111111",
"region": "fr-par"
}
2 changes: 2 additions & 0 deletions internal/e2e/testdata/test-human-create-with-args.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IsHappy true
EyesColor amber
Status stopped
Name -
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
Expand All @@ -31,5 +32,6 @@ Region fr-par
"eyes_color": "amber",
"status": "stopped",
"name": "",
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
"region": "fr-par"
}
2 changes: 2 additions & 0 deletions internal/e2e/testdata/test-human-delete-simple.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IsHappy true
EyesColor blue
Status stopped
Name -
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
Expand All @@ -31,5 +32,6 @@ Region fr-par
"eyes_color": "blue",
"status": "stopped",
"name": "",
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
"region": "fr-par"
}
2 changes: 2 additions & 0 deletions internal/e2e/testdata/test-human-get-simple.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IsHappy true
EyesColor blue
Status stopped
Name -
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
Expand All @@ -31,5 +32,6 @@ Region fr-par
"eyes_color": "blue",
"status": "stopped",
"name": "",
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
"region": "fr-par"
}
11 changes: 7 additions & 4 deletions internal/e2e/testdata/test-human-list-simple.golden
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
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
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
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
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
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
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
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
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
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
[
{
Expand All @@ -21,6 +21,7 @@ ID ORGANIZATION ID CREA
"eyes_color": "unknown",
"status": "stopped",
"name": "",
"project_id": "11111111-1111-1111-1111-111111111111",
"region": "fr-par"
},
{
Expand All @@ -38,6 +39,7 @@ ID ORGANIZATION ID CREA
"eyes_color": "unknown",
"status": "stopped",
"name": "",
"project_id": "11111111-1111-1111-1111-111111111111",
"region": "fr-par"
},
{
Expand All @@ -55,6 +57,7 @@ ID ORGANIZATION ID CREA
"eyes_color": "unknown",
"status": "stopped",
"name": "",
"project_id": "11111111-1111-1111-1111-111111111111",
"region": "fr-par"
}
]
2 changes: 2 additions & 0 deletions internal/e2e/testdata/test-human-update-multiple-args.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IsHappy true
EyesColor blue
Status stopped
Name -
ProjectID 11111111-1111-1111-1111-111111111111
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
Expand All @@ -31,5 +32,6 @@ Region fr-par
"eyes_color": "blue",
"status": "stopped",
"name": "",
"project_id": "11111111-1111-1111-1111-111111111111",
"region": "fr-par"
}
2 changes: 2 additions & 0 deletions internal/e2e/testdata/test-human-update-single-arg.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IsHappy false
EyesColor amber
Status stopped
Name -
ProjectID b3ba839a-dcf2-4b0a-ac81-fc32370052a0
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
Expand All @@ -31,5 +32,6 @@ Region fr-par
"eyes_color": "amber",
"status": "stopped",
"name": "",
"project_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0",
"region": "fr-par"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ profiles:
"APIURL": null,
"Insecure": true,
"DefaultOrganizationID": "11111111-1111-1111-1111-111111111111",
"DefaultProjectID": null,
"DefaultRegion": "fr-par",
"DefaultZone": "fr-par-1",
"SendTelemetry": true,
Expand All @@ -43,6 +44,7 @@ profiles:
"APIURL": "https://p1-mock-api-url.com",
"Insecure": true,
"DefaultOrganizationID": "11111111-1111-1111-1111-111111111111",
"DefaultProjectID": null,
"DefaultRegion": "fr-par",
"DefaultZone": "fr-par-1",
"SendTelemetry": null
Expand All @@ -53,6 +55,7 @@ profiles:
"APIURL": "https://p2-mock-api-url.com",
"Insecure": true,
"DefaultOrganizationID": "11111111-1111-1111-1111-111111111111",
"DefaultProjectID": null,
"DefaultRegion": "fr-par",
"DefaultZone": "fr-par-1",
"SendTelemetry": null
Expand Down
6 changes: 6 additions & 0 deletions internal/namespaces/instance/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ import (
var (
oldOrganizationFieldName = "organization"
newOrganizationFieldName = "organization-id"
oldProjectFieldName = "project"
newProjectFieldName = "project-id"
)

// helpers
func renameOrganizationIDArgSpec(argSpecs core.ArgSpecs) {
argSpecs.GetByName(oldOrganizationFieldName).Name = newOrganizationFieldName
}

func renameProjectIDArgSpec(argSpecs core.ArgSpecs) {
argSpecs.GetByName(oldProjectFieldName).Name = newProjectFieldName
}

// GetCommands returns instance commands.
//
// This function:
Expand Down
5 changes: 4 additions & 1 deletion internal/namespaces/instance/v1/custom_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
func ipCreateBuilder(c *core.Command) *core.Command {
type customCreateIPRequest struct {
*instance.CreateIPRequest
OrganizationID string
OrganizationID *string
ProjectID *string
}

renameOrganizationIDArgSpec(c.ArgSpecs)
renameProjectIDArgSpec(c.ArgSpecs)

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

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

return runner(ctx, request)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/namespaces/instance/v1/custom_server_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
logger.Debugf("creating IP")
res, err := apiInstance.CreateIP(&instance.CreateIPRequest{
Zone: args.Zone,
Organization: args.OrganizationID,
Organization: scw.StringPtr(args.OrganizationID),
})
if err != nil {
return nil, fmt.Errorf("error while creating your public IP: %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,37 @@ interactions:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14; darwin; amd64) cli-e2e-test
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/ips
method: POST
response:
body: '{"ip": {"id": "10d0c80b-25a4-4cfd-b71f-9e6c196ada1b", "address": "51.15.248.118",
body: '{"ip": {"id": "dc78c1dd-4436-4193-b82f-94bd5881ea35", "address": "51.15.215.79",
"reverse": null, "server": null, "organization": "951df375-e094-4d26-97c1-ba548eeb9c42",
"zone": "fr-par-1", "tags": []}}'
"project": "951df375-e094-4d26-97c1-ba548eeb9c42", "zone": "fr-par-1", "tags":
[]}}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "203"
- "253"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Wed, 18 Mar 2020 10:17:37 GMT
- Tue, 07 Jul 2020 13:53:15 GMT
Location:
- https://cp-par1.scaleway.com/ips/10d0c80b-25a4-4cfd-b71f-9e6c196ada1b
- https://cp-par1.scaleway.com/ips/dc78c1dd-4436-4193-b82f-94bd5881ea35
Server:
- scaleway_api
- agw_listener_public_vip
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 165e7498-ab80-42ff-a56f-e3fb82e851ca
status: 201 Created
code: 201
duration: ""
Expand All @@ -44,8 +47,8 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14; darwin; amd64) cli-e2e-test
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/ips/10d0c80b-25a4-4cfd-b71f-9e6c196ada1b
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/ips/dc78c1dd-4436-4193-b82f-94bd5881ea35
method: DELETE
response:
body: ""
Expand All @@ -57,15 +60,17 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 18 Mar 2020 10:17:37 GMT
- Tue, 07 Jul 2020 13:53:15 GMT
Server:
- scaleway_api
- agw_listener_public_vip
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 1e8c91f2-eacf-41e9-8200-df57898ee4be
status: 204 No Content
code: 204
duration: ""
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
ID 10d0c80b-25a4-4cfd-b71f-9e6c196ada1b
Address 51.15.248.118
ID dc78c1dd-4436-4193-b82f-94bd5881ea35
Address 51.15.215.79
Organization 951df375-e094-4d26-97c1-ba548eeb9c42
Project 951df375-e094-4d26-97c1-ba548eeb9c42
Zone fr-par-1
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
"ip": {
"id": "10d0c80b-25a4-4cfd-b71f-9e6c196ada1b",
"address": "51.15.248.118",
"id": "dc78c1dd-4436-4193-b82f-94bd5881ea35",
"address": "51.15.215.79",
"reverse": null,
"server": null,
"organization": "951df375-e094-4d26-97c1-ba548eeb9c42",
"tags": [],
"project": "951df375-e094-4d26-97c1-ba548eeb9c42",
"zone": "fr-par-1"
},
"Location": ""
Expand Down
Loading