@@ -35,23 +35,21 @@ func configSSHCmd() *cobra.Command {
35
35
var (
36
36
configpath string
37
37
remove = false
38
- p2p = false
39
38
)
40
39
41
40
cmd := & cobra.Command {
42
41
Use : "config-ssh" ,
43
42
Short : "Configure SSH to access Coder environments" ,
44
43
Long : "Inject the proper OpenSSH configuration into your local SSH config file." ,
45
- RunE : configSSH (& configpath , & remove , & p2p ),
44
+ RunE : configSSH (& configpath , & remove ),
46
45
}
47
46
cmd .Flags ().StringVar (& configpath , "filepath" , filepath .Join ("~" , ".ssh" , "config" ), "override the default path of your ssh config file" )
48
47
cmd .Flags ().BoolVar (& remove , "remove" , false , "remove the auto-generated Coder ssh config" )
49
- cmd .Flags ().BoolVar (& p2p , "p2p" , false , "(experimental) uses coder tunnel to proxy ssh connection" )
50
48
51
49
return cmd
52
50
}
53
51
54
- func configSSH (configpath * string , remove * bool , p2p * bool ) func (cmd * cobra.Command , _ []string ) error {
52
+ func configSSH (configpath * string , remove * bool ) func (cmd * cobra.Command , _ []string ) error {
55
53
return func (cmd * cobra.Command , _ []string ) error {
56
54
ctx := cmd .Context ()
57
55
usr , err := user .Current ()
@@ -115,7 +113,12 @@ func configSSH(configpath *string, remove *bool, p2p *bool) func(cmd *cobra.Comm
115
113
return xerrors .New ("SSH is disabled or not available for any environments in your Coder deployment." )
116
114
}
117
115
118
- newConfig := makeNewConfigs (user .Username , envsWithProviders , privateKeyFilepath , * p2p )
116
+ wconf , err := client .SiteConfigWorkspaces (ctx )
117
+ if err != nil {
118
+ return xerrors .Errorf ("getting site workspace config: %w" , err )
119
+ }
120
+
121
+ newConfig := makeNewConfigs (user .Username , envsWithProviders , privateKeyFilepath , wconf .EnableP2P )
119
122
120
123
err = os .MkdirAll (filepath .Dir (* configpath ), os .ModePerm )
121
124
if err != nil {
@@ -194,15 +197,17 @@ func makeNewConfigs(userName string, envs []coderutil.EnvWithWorkspaceProvider,
194
197
clog .LogWarn ("invalid access url" , clog .Causef ("malformed url: %q" , env .WorkspaceProvider .EnvproxyAccessURL ))
195
198
continue
196
199
}
197
- newConfig += makeSSHConfig (u .Host , userName , env .Env .Name , privateKeyFilepath , p2p )
200
+
201
+ useTunnel := env .WorkspaceProvider .BuiltIn && p2p
202
+ newConfig += makeSSHConfig (u .Host , userName , env .Env .Name , privateKeyFilepath , useTunnel )
198
203
}
199
204
newConfig += fmt .Sprintf ("\n %s\n " , sshEndToken )
200
205
201
206
return newConfig
202
207
}
203
208
204
- func makeSSHConfig (host , userName , envName , privateKeyFilepath string , p2p bool ) string {
205
- if p2p {
209
+ func makeSSHConfig (host , userName , envName , privateKeyFilepath string , tunnel bool ) string {
210
+ if tunnel {
206
211
return fmt .Sprintf (
207
212
`Host coder.%s
208
213
HostName coder.%s
0 commit comments