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

Commit22a6958

Browse files
committed
Use webrtc for coder sh
1 parentedc273f commit22a6958

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

‎internal/cmd/configssh.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string {
251251
entry:=fmt.Sprintf(
252252
`Host coder.%s
253253
HostName coder.%s
254-
ProxyCommand"%s" tunnel %s 12213 stdio
254+
ProxyCommand%s
255255
StrictHostKeyChecking no
256256
ConnectTimeout=0
257257
IdentitiesOnly yes
258258
IdentityFile="%s"
259-
`,workspaceName,workspaceName,binPath,workspaceName,privateKeyFilepath)
259+
`,workspaceName,workspaceName,proxyCommand(binPath,workspaceName,true),privateKeyFilepath)
260260

261261
ifruntime.GOOS=="linux"||runtime.GOOS=="darwin" {
262262
entry+=` ControlMaster auto
@@ -268,6 +268,13 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string {
268268
returnentry
269269
}
270270

271+
funcproxyCommand(binPath,workspaceNamestring,quotedbool)string {
272+
ifquoted {
273+
binPath=fmt.Sprintf("%q",binPath)
274+
}
275+
returnfmt.Sprintf(`%s tunnel %s 12213 stdio`,binPath,workspaceName)
276+
}
277+
271278
funcwriteStr(filename,datastring)error {
272279
returnioutil.WriteFile(filename, []byte(data),0777)
273280
}

‎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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp