@@ -2,53 +2,11 @@ package codespaces
22
33import (
44 "context"
5- "errors"
6- "fmt"
75 "os"
86 "os/exec"
97 "strconv"
10- "strings"
11-
12- "github.com/github/go-liveshare"
138)
149
15- // StartSSHServer installs (if necessary) and starts the SSH in the codespace.
16- // It returns the remote port where it is running, the user to log in with, or an error if something failed.
17- func StartSSHServer (ctx context.Context , session * liveshare.Session , log logger ) (serverPort int , user string , err error ) {
18- log .Println ("Fetching SSH details..." )
19-
20- sshServer := session .SSHServer ()
21-
22- sshServerStartResult , err := sshServer .StartRemoteServer (ctx )
23- if err != nil {
24- return 0 , "" , fmt .Errorf ("error starting live share: %v" , err )
25- }
26-
27- if ! sshServerStartResult .Result {
28- return 0 , "" , errors .New (sshServerStartResult .Message )
29- }
30-
31- portInt , err := strconv .Atoi (sshServerStartResult .ServerPort )
32- if err != nil {
33- return 0 , "" , fmt .Errorf ("error parsing port: %v" , err )
34- }
35-
36- return portInt , sshServerStartResult .User , nil
37- }
38-
39- // Shell runs an interactive secure shell over an existing
40- // port-forwarding session. It runs until the shell is terminated
41- // (including by cancellation of the context).
42- func Shell (ctx context.Context , log logger , port int , destination string , usingCustomPort bool ) error {
43- cmd , connArgs := newSSHCommand (ctx , port , destination , "" )
44-
45- if usingCustomPort {
46- log .Println ("Connection Details: ssh " + destination + " " + strings .Join (connArgs , " " ))
47- }
48-
49- return cmd .Run ()
50- }
51-
5210// NewRemoteCommand returns an exec.Cmd that will securely run a shell
5311// command on the remote machine.
5412func NewRemoteCommand (ctx context.Context , tunnelPort int , destination , command string ) * exec.Cmd {
0 commit comments