Skip to content

Commit ecd0c70

Browse files
committed
upgrade to go-liveshare 0.16.0
1 parent 3abde5f commit ecd0c70

File tree

3 files changed

+4
-44
lines changed

3 files changed

+4
-44
lines changed

cmd/ghcs/ssh.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func ssh(ctx context.Context, sshProfile, codespaceName string, localSSHServerPo
5959
return fmt.Errorf("error connecting to Live Share: %v", err)
6060
}
6161

62-
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, session, log)
62+
log.Println("Fetching SSH Details...")
63+
remoteSSHServerPort, sshUser, err := session.StartSSHServer(ctx)
6364
if err != nil {
6465
return fmt.Errorf("error getting ssh server details: %v", err)
6566
}

internal/codespaces/ssh.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,11 @@ package codespaces
22

33
import (
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.
5412
func NewRemoteCommand(ctx context.Context, tunnelPort int, destination, command string) *exec.Cmd {

internal/codespaces/states.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func PollPostCreateStates(ctx context.Context, log logger, apiClient *api.API, u
5454
}
5555
localPort := listen.Addr().(*net.TCPAddr).Port
5656

57-
remoteSSHServerPort, sshUser, err := StartSSHServer(ctx, session, log)
57+
log.Println("Fetching SSH Details...")
58+
remoteSSHServerPort, sshUser, err := session.StartSSHServer(ctx)
5859
if err != nil {
5960
return fmt.Errorf("error getting ssh server details: %v", err)
6061
}

0 commit comments

Comments
 (0)