From e82d8f76e5ce8cc5b1faf57b19fc943d57027e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Wed, 3 Feb 2021 16:46:57 +0100 Subject: [PATCH 1/5] feat(as): add ssh verb on the server resource to connect to a server --- ...sage-apple-silicon-server-ssh-usage.golden | 22 +++++ ...ll-usage-apple-silicon-server-usage.golden | 1 + .../applesilicon/v1alpha1/custom.go | 9 +- .../v1alpha1/custom_server_ssh.go | 98 +++++++++++++++++++ 4 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 cmd/scw/testdata/test-all-usage-apple-silicon-server-ssh-usage.golden create mode 100644 internal/namespaces/applesilicon/v1alpha1/custom_server_ssh.go diff --git a/cmd/scw/testdata/test-all-usage-apple-silicon-server-ssh-usage.golden b/cmd/scw/testdata/test-all-usage-apple-silicon-server-ssh-usage.golden new file mode 100644 index 0000000000..cb381deb1c --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-apple-silicon-server-ssh-usage.golden @@ -0,0 +1,22 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Connect to distant server via the SSH protocol. + +USAGE: + scw apple-silicon server ssh [arg=value ...] + +ARGS: + server-id Server ID to SSH into + [username=m1] Username used for the SSH connection + [port=22] Port used for the SSH connection + [command] Command to execute on the remote server + [zone=fr-par-1] Zone to target. If none is passed will use default zone from the config + +FLAGS: + -h, --help help for ssh + +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-apple-silicon-server-usage.golden b/cmd/scw/testdata/test-all-usage-apple-silicon-server-usage.golden index ab16fb5e2b..4c11831730 100644 --- a/cmd/scw/testdata/test-all-usage-apple-silicon-server-usage.golden +++ b/cmd/scw/testdata/test-all-usage-apple-silicon-server-usage.golden @@ -12,6 +12,7 @@ AVAILABLE COMMANDS: list List all servers reboot Reboot a server reinstall Reinstall a server + ssh SSH into a server update Update a server wait Wait for a server to reach a stable state diff --git a/internal/namespaces/applesilicon/v1alpha1/custom.go b/internal/namespaces/applesilicon/v1alpha1/custom.go index 6a220f95bc..08770db8b9 100644 --- a/internal/namespaces/applesilicon/v1alpha1/custom.go +++ b/internal/namespaces/applesilicon/v1alpha1/custom.go @@ -9,11 +9,10 @@ import ( func GetCommands() *core.Commands { cmds := GetGeneratedCommands() - cmds.Merge( - core.NewCommands( - serverWaitCommand(), - ), - ) + cmds.Merge(core.NewCommands( + serverSSHCommand(), + serverWaitCommand(), + )) human.RegisterMarshalerFunc(applesilicon.ServerStatus(""), human.EnumMarshalFunc(serverStatusMarshalSpecs)) diff --git a/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh.go b/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh.go new file mode 100644 index 0000000000..db0264fca2 --- /dev/null +++ b/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh.go @@ -0,0 +1,98 @@ +package applesilicon + +import ( + "context" + "fmt" + "os/exec" + "reflect" + + "github.com/scaleway/scaleway-cli/internal/core" + applesilicon "github.com/scaleway/scaleway-sdk-go/api/applesilicon/v1alpha1" + "github.com/scaleway/scaleway-sdk-go/scw" +) + +type serverSSHConnectRequest struct { + Zone scw.Zone + ServerID string + Username string + Port uint + Command string +} + +func serverSSHCommand() *core.Command { + return &core.Command{ + Short: `SSH into a server`, + Long: `Connect to distant server via the SSH protocol.`, + Namespace: "apple-silicon", + Verb: "ssh", + Resource: "server", + ArgsType: reflect.TypeOf(serverSSHConnectRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "server-id", + Short: "Server ID to SSH into", + Required: true, + Positional: true, + }, + { + Name: "username", + Short: "Username used for the SSH connection", + Default: core.DefaultValueSetter("m1"), + }, + { + Name: "port", + Short: "Port used for the SSH connection", + Default: core.DefaultValueSetter("22"), + }, + { + Name: "command", + Short: "Command to execute on the remote server", + }, + core.ZoneArgSpec(), + }, + Run: serverSSHRun, + } +} + +func serverSSHRun(ctx context.Context, argsI interface{}) (i interface{}, e error) { + args := argsI.(*serverSSHConnectRequest) + + client := core.ExtractClient(ctx) + asAPI := applesilicon.NewAPI(client) + serverResp, err := asAPI.GetServer(&applesilicon.GetServerRequest{ + Zone: args.Zone, + ServerID: args.ServerID, + }) + if err != nil { + return nil, err + } + + if serverResp.Status != applesilicon.ServerStatusReady { + return nil, &core.CliError{ + Err: fmt.Errorf("server is not ready"), + Details: fmt.Sprintf("Server %s currently in %s", serverResp.Name, serverResp.Status), + } + } + + sshArgs := []string{ + serverResp.IP.String(), + "-p", fmt.Sprintf("%d", args.Port), + "-l", args.Username, + "-t", + } + if args.Command != "" { + sshArgs = append(sshArgs, args.Command) + } + + sshCmd := exec.Command("ssh", sshArgs...) + + exitCode, err := core.ExecCmd(ctx, sshCmd) + if err != nil { + return nil, err + } + if exitCode != 0 { + return nil, &core.CliError{Empty: true, Code: exitCode} + } + + return &core.SuccessResult{Empty: true}, nil +} From 88e1a85daef0acae673b9e5c75846f50f200e349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Thu, 4 Feb 2021 12:10:36 +0100 Subject: [PATCH 2/5] Fix --- .../v1alpha1/custom_server_ssh_test.go | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go diff --git a/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go b/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go new file mode 100644 index 0000000000..087997a0be --- /dev/null +++ b/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go @@ -0,0 +1,49 @@ +package applesilicon + +import ( + "testing" + + "github.com/scaleway/scaleway-cli/internal/core" +) + +func Test_ServerSSH(t *testing.T) { + t.Run("Simple", core.Test(&core.TestConfig{ + Commands: GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + core.ExecStoreBeforeCmd("Server", "scw apple-silicon server create"), + ), + Cmd: "scw apple-silicon server ssh {{ .Server.ID }}", + OverrideExec: core.OverrideExecSimple( + "ssh {{ .Server.IP }} -p 22 -l m1 -t", + 0, + ), + Check: core.TestCheckCombine( + core.TestCheckGolden(), + core.TestCheckExitCode(0), + ), + AfterFunc: core.AfterFuncCombine( + core.ExecAfterCmd("scw apple-silicon server delete {{ .Server.ID }}"), + ), + DisableParallel: true, + })) + + t.Run("With-Exit-Code", core.Test(&core.TestConfig{ + Commands: GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + core.ExecStoreBeforeCmd("Server", "scw apple-silicon server create"), + ), + Cmd: "scw apple-silicon server ssh {{ .Server.ID }}", + OverrideExec: core.OverrideExecSimple( + "ssh {{ .Server.IP }} -p 22 -l m1 -t", + 130, + ), + Check: core.TestCheckCombine( + core.TestCheckGolden(), + core.TestCheckExitCode(130), + ), + AfterFunc: core.AfterFuncCombine( + core.ExecAfterCmd("scw apple-silicon server delete {{ .Server.ID }}"), + ), + DisableParallel: true, + })) +} From 62e0c194ef52c372e2a576351a0361e1b7267da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Fri, 5 Feb 2021 00:04:25 +0100 Subject: [PATCH 3/5] feat(as): add ssh verb on the server resource to connect to a server --- .../v1alpha1/custom_server_ssh_test.go | 4 +- .../test-server-ssh-simple.cassette.yaml | 37 +++++++++++++++++++ ...st-server-ssh-with-exit-code.cassette.yaml | 37 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml create mode 100644 internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml diff --git a/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go b/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go index 087997a0be..64234cadd5 100644 --- a/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go +++ b/internal/namespaces/applesilicon/v1alpha1/custom_server_ssh_test.go @@ -10,7 +10,7 @@ func Test_ServerSSH(t *testing.T) { t.Run("Simple", core.Test(&core.TestConfig{ Commands: GetCommands(), BeforeFunc: core.BeforeFuncCombine( - core.ExecStoreBeforeCmd("Server", "scw apple-silicon server create"), + core.ExecStoreBeforeCmd("Server", "scw apple-silicon server create --wait"), ), Cmd: "scw apple-silicon server ssh {{ .Server.ID }}", OverrideExec: core.OverrideExecSimple( @@ -30,7 +30,7 @@ func Test_ServerSSH(t *testing.T) { t.Run("With-Exit-Code", core.Test(&core.TestConfig{ Commands: GetCommands(), BeforeFunc: core.BeforeFuncCombine( - core.ExecStoreBeforeCmd("Server", "scw apple-silicon server create"), + core.ExecStoreBeforeCmd("Server", "scw apple-silicon server create --wait"), ), Cmd: "scw apple-silicon server ssh {{ .Server.ID }}", OverrideExec: core.OverrideExecSimple( diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml new file mode 100644 index 0000000000..dbc2ab8999 --- /dev/null +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml @@ -0,0 +1,37 @@ +--- +version: 1 +interactions: +- request: + body: '{"name":"","project_id":"11111111-1111-1111-1111-111111111111","type":""}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers + method: POST + response: + body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}' + headers: + Content-Length: + - "109" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 04 Feb 2021 23:01:24 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - e6364ba0-50e4-473f-b823-e3523f965a7a + status: 401 Unauthorized + code: 401 + duration: "" diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml new file mode 100644 index 0000000000..afa05700aa --- /dev/null +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml @@ -0,0 +1,37 @@ +--- +version: 1 +interactions: +- request: + body: '{"name":"","project_id":"11111111-1111-1111-1111-111111111111","type":""}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers + method: POST + response: + body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}' + headers: + Content-Length: + - "109" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 04 Feb 2021 23:01:24 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - ba9734bb-fbd4-408b-92f4-caab3fd01b38 + status: 401 Unauthorized + code: 401 + duration: "" From 3d836ce273259df9db625b727fc76a87d88a5076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Fri, 5 Feb 2021 00:07:04 +0100 Subject: [PATCH 4/5] Fix --- .../testdata/test-server-ssh-simple.cassette.yaml | 14 +++++++------- .../test-server-ssh-with-exit-code.cassette.yaml | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml index dbc2ab8999..15d367b5ad 100644 --- a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml @@ -2,7 +2,7 @@ version: 1 interactions: - request: - body: '{"name":"","project_id":"11111111-1111-1111-1111-111111111111","type":""}' + body: '{"name":"cli-as-charming-knuth","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","type":"M1-M"}' form: {} headers: Content-Type: @@ -12,16 +12,16 @@ interactions: url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers method: POST response: - body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}' + body: '{"message":"resource is out of stock","resource":"server","type":"out_of_stock"}' headers: Content-Length: - - "109" + - "80" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Thu, 04 Feb 2021 23:01:24 GMT + - Thu, 04 Feb 2021 23:05:55 GMT Server: - Scaleway API-Gateway Strict-Transport-Security: @@ -31,7 +31,7 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - e6364ba0-50e4-473f-b823-e3523f965a7a - status: 401 Unauthorized - code: 401 + - 49277a30-1e57-4aad-af1a-9c099be103ba + status: 503 Service Unavailable + code: 503 duration: "" diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml index afa05700aa..8d374fda22 100644 --- a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml @@ -2,7 +2,7 @@ version: 1 interactions: - request: - body: '{"name":"","project_id":"11111111-1111-1111-1111-111111111111","type":""}' + body: '{"name":"cli-as-ecstatic-edison","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","type":"M1-M"}' form: {} headers: Content-Type: @@ -12,16 +12,16 @@ interactions: url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers method: POST response: - body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}' + body: '{"message":"resource is out of stock","resource":"server","type":"out_of_stock"}' headers: Content-Length: - - "109" + - "80" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Thu, 04 Feb 2021 23:01:24 GMT + - Thu, 04 Feb 2021 23:06:46 GMT Server: - Scaleway API-Gateway Strict-Transport-Security: @@ -31,7 +31,7 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - ba9734bb-fbd4-408b-92f4-caab3fd01b38 - status: 401 Unauthorized - code: 401 + - a3a9dd03-bf0f-4444-a052-71e2f8dcdef5 + status: 503 Service Unavailable + code: 503 duration: "" From 738af8b6634d09b3c3ca6607a9727099e6ae2a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Fri, 5 Feb 2021 17:44:07 +0100 Subject: [PATCH 5/5] Fix --- internal/core/testing.go | 6 +- .../test-server-ssh-simple.cassette.yaml | 172 +++++++++++++++++- .../testdata/test-server-ssh-simple.golden | 3 + ...st-server-ssh-with-exit-code.cassette.yaml | 172 +++++++++++++++++- .../test-server-ssh-with-exit-code.golden | 3 + 5 files changed, 340 insertions(+), 16 deletions(-) create mode 100644 internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.golden create mode 100644 internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.golden diff --git a/internal/core/testing.go b/internal/core/testing.go index e9ee9a6ac9..0901d0a1ec 100644 --- a/internal/core/testing.go +++ b/internal/core/testing.go @@ -234,9 +234,11 @@ func createTestClient(t *testing.T, testConfig *TestConfig, httpClient *http.Cli clientOpts = append(clientOpts, scw.WithEnv()) config, err := scw.LoadConfig() if err == nil { - p, err := config.GetActiveProfile() + activeProfile, err := config.GetActiveProfile() require.NoError(t, err) - clientOpts = append(clientOpts, scw.WithProfile(p)) + envProfile := scw.LoadEnvProfile() + profile := scw.MergeProfiles(activeProfile, envProfile) + clientOpts = append(clientOpts, scw.WithProfile(profile)) } } } diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml index 15d367b5ad..a99974f53f 100644 --- a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.cassette.yaml @@ -2,7 +2,7 @@ version: 1 interactions: - request: - body: '{"name":"cli-as-charming-knuth","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","type":"M1-M"}' + body: '{"name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","type":"M1-M"}' form: {} headers: Content-Type: @@ -12,16 +12,16 @@ interactions: url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers method: POST response: - body: '{"message":"resource is out of stock","resource":"server","type":"out_of_stock"}' + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"starting","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:09.572209Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' headers: Content-Length: - - "80" + - "445" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Thu, 04 Feb 2021 23:05:55 GMT + - Fri, 05 Feb 2021 15:23:09 GMT Server: - Scaleway API-Gateway Strict-Transport-Security: @@ -31,7 +31,165 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - 49277a30-1e57-4aad-af1a-9c099be103ba - status: 503 Service Unavailable - code: 503 + - 24143fec-0a7a-4d15-9c07-021078483de2 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"starting","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:09.572209Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "445" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:09 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 14b6c904-1da2-46a2-9fa0-ccaa815f70e4 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"starting","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:09.572209Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "445" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:24 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - f04792db-1dd0-47fc-b9a7-675798f68124 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"ready","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:37.738360Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "442" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:39 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 3474754d-8a51-4ec0-8a27-ad9ebd09023d + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"ready","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:37.738360Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "442" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:39 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 691f98bf-7efe-4f30-9945-f98ce8c14b7b + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:40 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 37816da5-37d1-4e68-8d25-1cf0863d28c1 + status: 204 No Content + code: 204 duration: "" diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.golden b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.golden new file mode 100644 index 0000000000..995ad766aa --- /dev/null +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-simple.golden @@ -0,0 +1,3 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟩🟩🟩 JSON STDOUT 🟩🟩🟩 +{} diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml index 8d374fda22..a99974f53f 100644 --- a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.cassette.yaml @@ -2,7 +2,7 @@ version: 1 interactions: - request: - body: '{"name":"cli-as-ecstatic-edison","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","type":"M1-M"}' + body: '{"name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","type":"M1-M"}' form: {} headers: Content-Type: @@ -12,16 +12,16 @@ interactions: url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers method: POST response: - body: '{"message":"resource is out of stock","resource":"server","type":"out_of_stock"}' + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"starting","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:09.572209Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' headers: Content-Length: - - "80" + - "445" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Thu, 04 Feb 2021 23:06:46 GMT + - Fri, 05 Feb 2021 15:23:09 GMT Server: - Scaleway API-Gateway Strict-Transport-Security: @@ -31,7 +31,165 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - a3a9dd03-bf0f-4444-a052-71e2f8dcdef5 - status: 503 Service Unavailable - code: 503 + - 24143fec-0a7a-4d15-9c07-021078483de2 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"starting","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:09.572209Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "445" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:09 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 14b6c904-1da2-46a2-9fa0-ccaa815f70e4 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"starting","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:09.572209Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "445" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:24 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - f04792db-1dd0-47fc-b9a7-675798f68124 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"ready","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:37.738360Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "442" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:39 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 3474754d-8a51-4ec0-8a27-ad9ebd09023d + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: GET + response: + body: '{"id":"8675c43b-7767-46dd-ac15-bcb7682d6b81","type":"M1-M","name":"cli-as-romantic-boyd","project_id":"951df375-e094-4d26-97c1-ba548eeb9c42","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","ip":"195.154.249.131","vnc_url":"vnc://m1:eU8IjS8vdO6P@195.154.249.131:5900","status":"ready","created_at":"2021-02-05T15:23:09.572209Z","updated_at":"2021-02-05T15:23:37.738360Z","deletable_at":"2021-02-05T15:23:09.572209Z","zone":"fr-par-1"}' + headers: + Content-Length: + - "442" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:39 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 691f98bf-7efe-4f30-9945-f98ce8c14b7b + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/apple-silicon/v1alpha1/zones/fr-par-1/servers/8675c43b-7767-46dd-ac15-bcb7682d6b81 + method: DELETE + response: + body: "" + headers: + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 05 Feb 2021 15:23:40 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 37816da5-37d1-4e68-8d25-1cf0863d28c1 + status: 204 No Content + code: 204 duration: "" diff --git a/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.golden b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.golden new file mode 100644 index 0000000000..dae437b811 --- /dev/null +++ b/internal/namespaces/applesilicon/v1alpha1/testdata/test-server-ssh-with-exit-code.golden @@ -0,0 +1,3 @@ +🎲🎲🎲 EXIT CODE: 130 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯ +{}