@@ -4,13 +4,11 @@ import (
4
4
"context"
5
5
"fmt"
6
6
"io/ioutil"
7
- "net"
8
7
"net/url"
9
8
"os"
10
9
"os/user"
11
10
"path/filepath"
12
11
"strings"
13
- "time"
14
12
15
13
"cdr.dev/coder-cli/pkg/clog"
16
14
@@ -93,10 +91,6 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
93
91
return err
94
92
}
95
93
96
- if ! isSSHAvailable (ctx ) {
97
- return xerrors .New ("SSH is disabled or not available for your Coder Enterprise deployment." )
98
- }
99
-
100
94
user , err := client .Me (ctx )
101
95
if err != nil {
102
96
return xerrors .Errorf ("fetch username: %w" , err )
@@ -109,6 +103,18 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
109
103
if len (envs ) < 1 {
110
104
return xerrors .New ("no environments found" )
111
105
}
106
+
107
+ sshAvailable := false
108
+ for _ , env := range envs {
109
+ if env .SSHAvailable {
110
+ sshAvailable = true
111
+ break
112
+ }
113
+ }
114
+ if ! sshAvailable {
115
+ return xerrors .New ("SSH is disabled or not available any environments in your Coder Enterprise deployment." )
116
+ }
117
+
112
118
newConfig , err := makeNewConfigs (user .Username , envs , startToken , startMessage , endToken , privateKeyFilepath )
113
119
if err != nil {
114
120
return xerrors .Errorf ("make new ssh configurations: %w" , err )
@@ -161,6 +167,10 @@ func makeNewConfigs(userName string, envs []coder.Environment, startToken, start
161
167
162
168
newConfig := fmt .Sprintf ("\n %s\n %s\n \n " , startToken , startMsg )
163
169
for _ , env := range envs {
170
+ if ! env .SSHAvailable {
171
+ continue
172
+ }
173
+
164
174
newConfig += makeSSHConfig (hostname , userName , env .Name , privateKeyFilepath )
165
175
}
166
176
newConfig += fmt .Sprintf ("\n %s\n " , endToken )
@@ -181,20 +191,6 @@ func makeSSHConfig(host, userName, envName, privateKeyFilepath string) string {
181
191
` , envName , host , userName , envName , privateKeyFilepath )
182
192
}
183
193
184
- func isSSHAvailable (ctx context.Context ) bool {
185
- ctx , cancel := context .WithTimeout (ctx , 3 * time .Second )
186
- defer cancel ()
187
-
188
- host , err := configuredHostname ()
189
- if err != nil {
190
- return false
191
- }
192
-
193
- var dialer net.Dialer
194
- _ , err = dialer .DialContext (ctx , "tcp" , net .JoinHostPort (host , "22" ))
195
- return err == nil
196
- }
197
-
198
194
func configuredHostname () (string , error ) {
199
195
u , err := config .URL .Read ()
200
196
if err != nil {
0 commit comments