44 "context"
55 "fmt"
66 "io/ioutil"
7- "net/url"
87 "os"
98 "os/user"
109 "path/filepath"
@@ -119,7 +118,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
119118 return xerrors .Errorf ("Failed to get executable path: %w" , err )
120119 }
121120
122- newConfig := makeNewConfigs (binPath , user . Username , workspacesWithProviders , privateKeyFilepath )
121+ newConfig := makeNewConfigs (binPath , workspacesWithProviders , privateKeyFilepath )
123122
124123 err = os .MkdirAll (filepath .Dir (* configpath ), os .ModePerm )
125124 if err != nil {
@@ -227,7 +226,7 @@ func writeSSHKey(ctx context.Context, client coder.Client, privateKeyPath string
227226 return ioutil .WriteFile (privateKeyPath , []byte (key .PrivateKey ), 0600 )
228227}
229228
230- func makeNewConfigs (binPath , userName string , workspaces []coderutil.WorkspaceWithWorkspaceProvider , privateKeyFilepath string ) string {
229+ func makeNewConfigs (binPath string , workspaces []coderutil.WorkspaceWithWorkspaceProvider , privateKeyFilepath string ) string {
231230 newConfig := fmt .Sprintf ("\n %s\n %s\n \n " , sshStartToken , sshStartMessage )
232231
233232 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
240239 )
241240 continue
242241 }
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- }
248242
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 )
251244 }
252245 newConfig += fmt .Sprintf ("\n %s\n " , sshEndToken )
253246
254247 return newConfig
255248}
256249
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
261253 HostName coder.%s
262254 ProxyCommand "%s" tunnel %s 12213 stdio
263255 StrictHostKeyChecking no
@@ -266,25 +258,14 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
266258 IdentityFile="%s"
267259` , workspaceName , workspaceName , binPath , workspaceName , privateKeyFilepath )
268260
269- if runtime .GOOS == "linux" || runtime .GOOS == "darwin" {
270- host += ` ControlMaster auto
261+ if runtime .GOOS == "linux" || runtime .GOOS == "darwin" {
262+ entry += ` ControlMaster auto
271263 ControlPath ~/.ssh/.connection-%r@%h:%p
272264 ControlPersist 600
273265`
274- }
275-
276- return host
277266 }
278267
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
288269}
289270
290271func writeStr (filename , data string ) error {
0 commit comments