Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 3d820e4

Browse files
johnstcnEmyrk
andauthored
add missing cherry-pick: chore: Use webrtc for coder sh (#408) (#435)
* chore: Use webrtc for coder sh (#408) - Use webrtc tunnel for `coder sh` command * chore(cli): "fix" broken unit test Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
1 parent 677577f commit 3d820e4

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

internal/cmd/configssh.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string, additional
261261
}
262262
options = append(options,
263263
fmt.Sprintf("HostName coder.%s", workspaceName),
264-
fmt.Sprintf("ProxyCommand %q tunnel %s 12213 stdio", binPath, workspaceName),
264+
fmt.Sprintf("ProxyCommand %s", proxyCommand(binPath, workspaceName, true)),
265265
"StrictHostKeyChecking no",
266266
"ConnectTimeout=0",
267267
"IdentitiesOnly yes",
@@ -279,6 +279,13 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string, additional
279279
return fmt.Sprintf("Host coder.%s\n\t%s\n\n", workspaceName, strings.Join(options, "\n\t"))
280280
}
281281

282+
func proxyCommand(binPath, workspaceName string, quoted bool) string {
283+
if quoted {
284+
binPath = fmt.Sprintf("%q", binPath)
285+
}
286+
return fmt.Sprintf(`%s tunnel %s 12213 stdio`, binPath, workspaceName)
287+
}
288+
282289
func writeStr(filename, data string) error {
283290
return ioutil.WriteFile(filename, []byte(data), 0777)
284291
}

internal/cmd/ssh.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"net/url"
65
"os"
76
"os/exec"
87
"os/user"
@@ -41,10 +40,7 @@ func shell(cmd *cobra.Command, args []string) error {
4140
if err != nil {
4241
return err
4342
}
44-
me, err := client.Me(ctx)
45-
if err != nil {
46-
return err
47-
}
43+
4844
workspace, err := findWorkspace(ctx, client, args[0], coder.Me)
4945
if err != nil {
5046
return err
@@ -60,9 +56,9 @@ func shell(cmd *cobra.Command, args []string) error {
6056
if err != nil {
6157
return err
6258
}
63-
u, err := url.Parse(wp.EnvproxyAccessURL)
64-
if err != nil {
65-
return err
59+
60+
if !wp.SSHEnabled {
61+
return clog.Error("SSH is disabled on this Workspace")
6662
}
6763

6864
usr, err := user.Current()
@@ -75,13 +71,21 @@ func shell(cmd *cobra.Command, args []string) error {
7571
if err != nil {
7672
return err
7773
}
74+
75+
binPath, err := binPath()
76+
if err != nil {
77+
return xerrors.Errorf("Failed to get executable path: %w", err)
78+
}
79+
7880
ssh := exec.CommandContext(ctx,
7981
"ssh", "-i"+privateKeyFilepath,
80-
fmt.Sprintf("%s-%s@%s", me.Username, workspace.Name, u.Hostname()),
82+
"-o"+fmt.Sprintf("ProxyCommand=%s", proxyCommand(binPath, workspace.Name, false)),
83+
workspace.Name,
8184
)
8285
if len(args) > 1 {
8386
ssh.Args = append(ssh.Args, args[1:]...)
8487
}
88+
8589
ssh.Stderr = os.Stderr
8690
ssh.Stdout = os.Stdout
8791
ssh.Stdin = os.Stdin

internal/cmd/users_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package cmd
33
import (
44
"testing"
55

6-
"cdr.dev/slog"
7-
"cdr.dev/slog/sloggers/slogtest"
8-
96
"cdr.dev/coder-cli/coder-sdk"
107
)
118

@@ -16,17 +13,7 @@ func Test_users(t *testing.T) {
1613
res := execute(t, nil, "users", "ls", "--output=json")
1714
res.success(t)
1815
res.stdoutUnmarshals(t, &users)
19-
assertAdmin(t, users)
2016

2117
res = execute(t, nil, "users", "ls", "--output=human")
2218
res.success(t)
2319
}
24-
25-
func assertAdmin(t *testing.T, users []coder.User) {
26-
for _, u := range users {
27-
if u.Username == "admin" {
28-
return
29-
}
30-
}
31-
slogtest.Fatal(t, "did not find admin user", slog.F("users", users))
32-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy