Skip to content

Commit 903b7be

Browse files
authored
Comments from pr.
1 parent 954d46d commit 903b7be

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

cmd/ghcs/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func logs(tail bool, codespaceName string) error {
5757
return fmt.Errorf("connecting to liveshare: %v", err)
5858
}
5959

60-
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, lsclient)
60+
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, lsclient, log)
6161
if err != nil {
6262
return fmt.Errorf("error getting ssh server details: %v", err)
6363
}

cmd/ghcs/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func ssh(sshProfile, codespaceName string, sshServerPort int) error {
5959
return fmt.Errorf("error connecting to liveshare: %v", err)
6060
}
6161

62-
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, lsclient)
62+
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, lsclient, log)
6363
if err != nil {
6464
return fmt.Errorf("error getting ssh server details: %v", err)
6565
}

internal/codespaces/ssh.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func MakeSSHTunnel(ctx context.Context, lsclient *liveshare.Client, localSSHPort
4747

4848
// StartSSHServer installs (if necessary) and starts the SSH in the codespace.
4949
// It returns the remote port where it is running, the user to log in with, or an error if something failed.
50-
func StartSSHServer(ctx context.Context, client *liveshare.Client) (serverPort int, user string, err error) {
50+
func StartSSHServer(ctx context.Context, client *liveshare.Client, log logger) (serverPort int, user string, err error) {
51+
log.Println("Fetching SSH details...")
52+
5153
sshServer, err := liveshare.NewSSHServer(client)
5254
if err != nil {
5355
return 0, "", fmt.Errorf("error creating live share: %v", err)

internal/codespaces/states.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func PollPostCreateStates(ctx context.Context, log logger, apiClient *api.API, u
4545
return fmt.Errorf("connect to liveshare: %v", err)
4646
}
4747

48-
remoteSSHServerPort, _, err := StartSSHServer(ctx, lsclient)
48+
remoteSSHServerPort, sshUser, err := StartSSHServer(ctx, lsclient, log)
4949
if err != nil {
5050
return fmt.Errorf("error getting ssh server details: %v", err)
5151
}
@@ -65,7 +65,7 @@ func PollPostCreateStates(ctx context.Context, log logger, apiClient *api.API, u
6565
case err := <-connClosed:
6666
return fmt.Errorf("connection closed: %v", err)
6767
case <-t.C:
68-
states, err := getPostCreateOutput(ctx, tunnelPort, codespace)
68+
states, err := getPostCreateOutput(ctx, tunnelPort, codespace, sshUser)
6969
if err != nil {
7070
return fmt.Errorf("get post create output: %v", err)
7171
}
@@ -75,9 +75,9 @@ func PollPostCreateStates(ctx context.Context, log logger, apiClient *api.API, u
7575
}
7676
}
7777

78-
func getPostCreateOutput(ctx context.Context, tunnelPort int, codespace *api.Codespace) ([]PostCreateState, error) {
78+
func getPostCreateOutput(ctx context.Context, tunnelPort int, codespace *api.Codespace, user string) ([]PostCreateState, error) {
7979
stdout, err := RunCommand(
80-
ctx, tunnelPort, sshDestination(codespace),
80+
ctx, tunnelPort, sshDestination(codespace, user),
8181
"cat /workspaces/.codespaces/shared/postCreateOutput.json",
8282
)
8383
if err != nil {
@@ -101,10 +101,6 @@ func getPostCreateOutput(ctx context.Context, tunnelPort int, codespace *api.Cod
101101
}
102102

103103
// TODO(josebalius): this won't be needed soon
104-
func sshDestination(codespace *api.Codespace) string {
105-
user := "codespace"
106-
if codespace.RepositoryNWO == "github/github" {
107-
user = "root"
108-
}
104+
func sshDestination(codespace *api.Codespace, user string) string {
109105
return user + "@localhost"
110106
}

0 commit comments

Comments
 (0)