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

Commitdcfd501

Browse files
authored
fix: Networking V2 tunnel on Windows (#356)
1 parentd6b2afd commitdcfd501

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

‎cmd/coder/main.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ func main() {
2525
}()
2626
}
2727

28-
stdoutState,err:=xterminal.MakeOutputRaw(os.Stdout.Fd())
29-
iferr!=nil {
30-
clog.Log(clog.Fatal(fmt.Sprintf("set output to raw: %s",err)))
31-
cancel()
32-
os.Exit(1)
33-
}
34-
restoreTerminal:=func() {
35-
// Best effort. Would result in broken terminal on window but nothing we can do about it.
36-
_=xterminal.Restore(os.Stdout.Fd(),stdoutState)
28+
restoreTerminal:=func() {}
29+
30+
// Janky, but SSH on windows sets the output to raw.
31+
// If we set it ourselves, SSH fails because the FD isn't found.
32+
iflen(os.Args)>=2&&os.Args[1]!="tunnel" {
33+
state,err:=xterminal.MakeOutputRaw(os.Stdout.Fd())
34+
iferr!=nil {
35+
clog.Log(clog.Fatal(fmt.Sprintf("set output to raw: %s",err)))
36+
cancel()
37+
os.Exit(1)
38+
}
39+
restoreTerminal=func() {
40+
// Best effort. Would result in broken terminal on window but nothing we can do about it.
41+
_=xterminal.Restore(os.Stdout.Fd(),state)
42+
}
3743
}
3844

3945
app:=cmd.Make()

‎internal/cmd/configssh.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ func configSSH(configpath *string, remove *bool, next *bool) func(cmd *cobra.Com
132132
}
133133
}
134134

135-
newConfig:=makeNewConfigs(user.Username,workspacesWithProviders,privateKeyFilepath,p2p)
135+
binPath,err:=os.Executable()
136+
iferr!=nil {
137+
returnxerrors.Errorf("Failed to get executable path: %w",err)
138+
}
139+
140+
newConfig:=makeNewConfigs(binPath,user.Username,workspacesWithProviders,privateKeyFilepath,p2p)
136141

137142
err=os.MkdirAll(filepath.Dir(*configpath),os.ModePerm)
138143
iferr!=nil {
@@ -193,7 +198,7 @@ func writeSSHKey(ctx context.Context, client coder.Client, privateKeyPath string
193198
returnioutil.WriteFile(privateKeyPath, []byte(key.PrivateKey),0600)
194199
}
195200

196-
funcmakeNewConfigs(userNamestring,workspaces []coderutil.WorkspaceWithWorkspaceProvider,privateKeyFilepathstring,p2pbool)string {
201+
funcmakeNewConfigs(binPath,userNamestring,workspaces []coderutil.WorkspaceWithWorkspaceProvider,privateKeyFilepathstring,p2pbool)string {
197202
newConfig:=fmt.Sprintf("\n%s\n%s\n\n",sshStartToken,sshStartMessage)
198203

199204
sort.Slice(workspaces,func(i,jint)bool {returnworkspaces[i].Workspace.Name<workspaces[j].Workspace.Name })
@@ -213,24 +218,24 @@ func makeNewConfigs(userName string, workspaces []coderutil.WorkspaceWithWorkspa
213218
}
214219

215220
useTunnel:=workspace.WorkspaceProvider.BuiltIn&&p2p
216-
newConfig+=makeSSHConfig(u.Host,userName,workspace.Workspace.Name,privateKeyFilepath,useTunnel)
221+
newConfig+=makeSSHConfig(binPath,u.Host,userName,workspace.Workspace.Name,privateKeyFilepath,useTunnel)
217222
}
218223
newConfig+=fmt.Sprintf("\n%s\n",sshEndToken)
219224

220225
returnnewConfig
221226
}
222227

223-
funcmakeSSHConfig(host,userName,workspaceName,privateKeyFilepathstring,tunnelbool)string {
228+
funcmakeSSHConfig(binPath,host,userName,workspaceName,privateKeyFilepathstring,tunnelbool)string {
224229
iftunnel {
225230
returnfmt.Sprintf(
226231
`Host coder.%s
227232
HostName coder.%s
228-
ProxyCommandcoder tunnel %s 12213 stdio
233+
ProxyCommand%s tunnel %s 12213 stdio
229234
StrictHostKeyChecking no
230235
ConnectTimeout=0
231236
IdentitiesOnly yes
232237
IdentityFile="%s"
233-
`,workspaceName,workspaceName,workspaceName,privateKeyFilepath)
238+
`,workspaceName,workspaceName,binPath,workspaceName,privateKeyFilepath)
234239
}
235240

236241
returnfmt.Sprintf(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp