Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit3d820e4

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 testCo-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
1 parent677577f commit3d820e4

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
returnfmt.Sprintf("Host coder.%s\n\t%s\n\n",workspaceName,strings.Join(options,"\n\t"))
280280
}
281281

282+
funcproxyCommand(binPath,workspaceNamestring,quotedbool)string {
283+
ifquoted {
284+
binPath=fmt.Sprintf("%q",binPath)
285+
}
286+
returnfmt.Sprintf(`%s tunnel %s 12213 stdio`,binPath,workspaceName)
287+
}
288+
282289
funcwriteStr(filename,datastring)error {
283290
returnioutil.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
iferr!=nil {
4241
returnerr
4342
}
44-
me,err:=client.Me(ctx)
45-
iferr!=nil {
46-
returnerr
47-
}
43+
4844
workspace,err:=findWorkspace(ctx,client,args[0],coder.Me)
4945
iferr!=nil {
5046
returnerr
@@ -60,9 +56,9 @@ func shell(cmd *cobra.Command, args []string) error {
6056
iferr!=nil {
6157
returnerr
6258
}
63-
u,err:=url.Parse(wp.EnvproxyAccessURL)
64-
iferr!=nil {
65-
returnerr
59+
60+
if!wp.SSHEnabled {
61+
returnclog.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
iferr!=nil {
7672
returnerr
7773
}
74+
75+
binPath,err:=binPath()
76+
iferr!=nil {
77+
returnxerrors.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
iflen(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-
funcassertAdmin(t*testing.T,users []coder.User) {
26-
for_,u:=rangeusers {
27-
ifu.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)

[8]ページ先頭

©2009-2025 Movatter.jp