4
4
"context"
5
5
"fmt"
6
6
"io/ioutil"
7
- "net/url"
8
7
"os"
9
8
"os/user"
10
9
"path/filepath"
@@ -119,7 +118,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
119
118
return xerrors .Errorf ("Failed to get executable path: %w" ,err )
120
119
}
121
120
122
- newConfig := makeNewConfigs (binPath ,user . Username , workspacesWithProviders ,privateKeyFilepath )
121
+ newConfig := makeNewConfigs (binPath ,workspacesWithProviders ,privateKeyFilepath )
123
122
124
123
err = os .MkdirAll (filepath .Dir (* configpath ),os .ModePerm )
125
124
if err != nil {
@@ -227,7 +226,7 @@ func writeSSHKey(ctx context.Context, client coder.Client, privateKeyPath string
227
226
return ioutil .WriteFile (privateKeyPath , []byte (key .PrivateKey ),0600 )
228
227
}
229
228
230
- func makeNewConfigs (binPath , userName string ,workspaces []coderutil.WorkspaceWithWorkspaceProvider ,privateKeyFilepath string )string {
229
+ func makeNewConfigs (binPath string ,workspaces []coderutil.WorkspaceWithWorkspaceProvider ,privateKeyFilepath string )string {
231
230
newConfig := fmt .Sprintf ("\n %s\n %s\n \n " ,sshStartToken ,sshStartMessage )
232
231
233
232
sort .Slice (workspaces ,func (i ,j int )bool {return workspaces [i ].Workspace .Name < workspaces [j ].Workspace .Name })
@@ -240,24 +239,17 @@ func makeNewConfigs(binPath, userName string, workspaces []coderutil.WorkspaceWi
240
239
)
241
240
continue
242
241
}
243
- u ,err := url .Parse (workspace .WorkspaceProvider .EnvproxyAccessURL )
244
- if err != nil {
245
- clog .LogWarn ("invalid access url" ,clog .Causef ("malformed url: %q" ,workspace .WorkspaceProvider .EnvproxyAccessURL ))
246
- continue
247
- }
248
242
249
- useTunnel := workspace .WorkspaceProvider .SSHEnabled && workspace .WorkspaceProvider .EnableNetV2
250
- newConfig += makeSSHConfig (binPath ,u .Host ,userName ,workspace .Workspace .Name ,privateKeyFilepath ,useTunnel )
243
+ newConfig += makeSSHConfig (binPath ,workspace .Workspace .Name ,privateKeyFilepath )
251
244
}
252
245
newConfig += fmt .Sprintf ("\n %s\n " ,sshEndToken )
253
246
254
247
return newConfig
255
248
}
256
249
257
- func makeSSHConfig (binPath ,host ,userName ,workspaceName ,privateKeyFilepath string ,tunnel bool )string {
258
- if tunnel {
259
- host := fmt .Sprintf (
260
- `Host coder.%s
250
+ func makeSSHConfig (binPath ,workspaceName ,privateKeyFilepath string )string {
251
+ entry := fmt .Sprintf (
252
+ `Host coder.%s
261
253
HostName coder.%s
262
254
ProxyCommand "%s" tunnel %s 12213 stdio
263
255
StrictHostKeyChecking no
@@ -266,25 +258,14 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
266
258
IdentityFile="%s"
267
259
` ,workspaceName ,workspaceName ,binPath ,workspaceName ,privateKeyFilepath )
268
260
269
- if runtime .GOOS == "linux" || runtime .GOOS == "darwin" {
270
- host += ` ControlMaster auto
261
+ if runtime .GOOS == "linux" || runtime .GOOS == "darwin" {
262
+ entry += ` ControlMaster auto
271
263
ControlPath ~/.ssh/.connection-%r@%h:%p
272
264
ControlPersist 600
273
265
`
274
- }
275
-
276
- return host
277
266
}
278
267
279
- return fmt .Sprintf (
280
- `Host coder.%s
281
- HostName %s
282
- User %s-%s
283
- StrictHostKeyChecking no
284
- ConnectTimeout=0
285
- IdentitiesOnly yes
286
- IdentityFile="%s"
287
- ` ,workspaceName ,host ,userName ,workspaceName ,privateKeyFilepath )
268
+ return entry
288
269
}
289
270
290
271
func writeStr (filename ,data string )error {