@@ -17,6 +17,7 @@ import { ITelemetryService } from '../common/telemetry';
17
17
import { IRemoteService } from '../services/remoteService' ;
18
18
import { WrapError } from '../common/utils' ;
19
19
import { getOpenSSHVersion } from '../ssh/sshVersion' ;
20
+ import { IExperimentsService } from '../experiments' ;
20
21
21
22
function getCommandName ( command : string ) {
22
23
return command . replace ( 'gitpod.workspaces.' , '' ) . replace ( / (?: _ i n l i n e | _ c o n t e x t ) (?: @ \d ) ? $ / , '' ) ;
@@ -56,6 +57,7 @@ export class ConnectInNewWindowCommand implements Command {
56
57
private readonly remoteService : IRemoteService ,
57
58
private readonly sessionService : ISessionService ,
58
59
private readonly hostService : IHostService ,
60
+ private readonly experimentsService : IExperimentsService ,
59
61
private readonly telemetryService : ITelemetryService ,
60
62
private readonly logService : ILogService ,
61
63
) { }
@@ -92,13 +94,6 @@ export class ConnectInNewWindowCommand implements Command {
92
94
location : getCommandLocation ( this . id , treeItem )
93
95
} ) ;
94
96
95
- const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
96
- const sshHostname = `${ wsData . id } .${ domain } ` ;
97
- const sshDest = new SSHDestination ( sshHostname , wsData . id ) ;
98
-
99
- // TODO: remove this, should not be needed
100
- await this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDest . toRemoteSSHString ( ) } ` , { workspaceId : wsData . id , gitpodHost : this . hostService . gitpodHost , instanceId : '' } as SSHConnectionParams ) ;
101
-
102
97
let wsState = new WorkspaceState ( wsData ! . id , this . sessionService , this . logService ) ;
103
98
try {
104
99
await wsState . initialize ( ) ;
@@ -113,6 +108,8 @@ export class ConnectInNewWindowCommand implements Command {
113
108
cancellable : true
114
109
} ,
115
110
async ( _ , cancelToken ) => {
111
+ await this . initializeLocalSSH ( wsData ! . id ) ;
112
+
116
113
if ( wsState . isWorkspaceStopped ) {
117
114
// Start workspace automatically
118
115
await this . sessionService . getAPI ( ) . startWorkspace ( wsData ! . id ) ;
@@ -123,18 +120,42 @@ export class ConnectInNewWindowCommand implements Command {
123
120
return ;
124
121
}
125
122
126
- await this . initializeLocalSSH ( wsData ! . id ) ;
127
-
128
123
await raceCancellationError ( eventToPromise ( wsState . onWorkspaceRunning ) , cancelToken ) ;
124
+ wsData = wsState . workspaceData ; // Update wsData with latest info after workspace is running
125
+ }
126
+
127
+ let sshDest : SSHDestination ;
128
+ let password : string | undefined ;
129
+ if ( await this . experimentsService . getUseLocalSSHProxy ( ) ) {
130
+ const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
131
+ const sshHostname = `${ wsData ! . id } .${ domain } ` ;
132
+ sshDest = new SSHDestination ( sshHostname , wsData ! . id ) ;
133
+ } else {
134
+ ( { destination : sshDest , password } = await this . remoteService . getWorkspaceSSHDestination ( wsData ! ) ) ;
129
135
}
130
136
137
+ if ( password ) {
138
+ try {
139
+ await this . remoteService . showSSHPasswordModal ( wsData ! , password ) ;
140
+ } catch {
141
+ return ;
142
+ }
143
+ }
144
+
145
+ // TODO: remove this, should not be needed
146
+ await this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDest . toRemoteSSHString ( ) } ` , { workspaceId : wsData ! . id , gitpodHost : this . hostService . gitpodHost , instanceId : '' } as SSHConnectionParams ) ;
147
+
131
148
await vscode . commands . executeCommand (
132
149
'vscode.openFolder' ,
133
150
vscode . Uri . parse ( `vscode-remote://ssh-remote+${ sshDest . toRemoteSSHString ( ) } ${ wsData ! . recentFolders [ 0 ] || `/workspace/${ wsData ! . repo } ` } ` ) ,
134
151
{ forceNewWindow : true }
135
152
) ;
136
153
}
137
154
) ;
155
+ } catch ( e ) {
156
+ this . logService . error ( e ) ;
157
+ this . telemetryService . sendTelemetryException ( new WrapError ( 'Error runnning connectInNewWindow command' , e ) ) ;
158
+ throw e ;
138
159
} finally {
139
160
wsState . dispose ( ) ;
140
161
}
@@ -154,7 +175,7 @@ export class ConnectInNewWindowCommand implements Command {
154
175
}
155
176
} catch ( e ) {
156
177
const openSSHVersion = await getOpenSSHVersion ( ) ;
157
- this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e , 'Unknown' ) , {
178
+ this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e ) , {
158
179
gitpodHost : this . hostService . gitpodHost ,
159
180
openSSHVersion,
160
181
workspaceId
@@ -173,10 +194,11 @@ export class ConnectInNewWindowCommandContext extends ConnectInNewWindowCommand
173
194
remoteService : IRemoteService ,
174
195
sessionService : ISessionService ,
175
196
hostService : IHostService ,
197
+ experimentsService : IExperimentsService ,
176
198
telemetryService : ITelemetryService ,
177
199
logService : ILogService ,
178
200
) {
179
- super ( context , remoteService , sessionService , hostService , telemetryService , logService ) ;
201
+ super ( context , remoteService , sessionService , hostService , experimentsService , telemetryService , logService ) ;
180
202
}
181
203
}
182
204
@@ -190,6 +212,7 @@ export class ConnectInCurrentWindowCommand implements Command {
190
212
private readonly remoteService : IRemoteService ,
191
213
private readonly sessionService : ISessionService ,
192
214
private readonly hostService : IHostService ,
215
+ private readonly experimentsService : IExperimentsService ,
193
216
private readonly telemetryService : ITelemetryService ,
194
217
private readonly logService : ILogService ,
195
218
) { }
@@ -226,13 +249,6 @@ export class ConnectInCurrentWindowCommand implements Command {
226
249
location : getCommandLocation ( this . id , treeItem )
227
250
} ) ;
228
251
229
- const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
230
- const sshHostname = `${ wsData . id } .${ domain } ` ;
231
- const sshDest = new SSHDestination ( sshHostname , wsData . id ) ;
232
-
233
- // TODO: remove this, should not be needed
234
- await this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDest . toRemoteSSHString ( ) } ` , { workspaceId : wsData . id , gitpodHost : this . hostService . gitpodHost , instanceId : '' } as SSHConnectionParams ) ;
235
-
236
252
let wsState = new WorkspaceState ( wsData ! . id , this . sessionService , this . logService ) ;
237
253
try {
238
254
await wsState . initialize ( ) ;
@@ -247,6 +263,8 @@ export class ConnectInCurrentWindowCommand implements Command {
247
263
cancellable : true
248
264
} ,
249
265
async ( _ , cancelToken ) => {
266
+ await this . initializeLocalSSH ( wsData ! . id ) ;
267
+
250
268
if ( wsState . isWorkspaceStopped ) {
251
269
// Start workspace automatically
252
270
await this . sessionService . getAPI ( ) . startWorkspace ( wsData ! . id ) ;
@@ -257,18 +275,42 @@ export class ConnectInCurrentWindowCommand implements Command {
257
275
return ;
258
276
}
259
277
260
- await this . initializeLocalSSH ( wsData ! . id ) ;
261
-
262
278
await raceCancellationError ( eventToPromise ( wsState . onWorkspaceRunning ) , cancelToken ) ;
279
+ wsData = wsState . workspaceData ; // Update wsData with latest info after workspace is running
280
+ }
281
+
282
+ let sshDest : SSHDestination ;
283
+ let password : string | undefined ;
284
+ if ( await this . experimentsService . getUseLocalSSHProxy ( ) ) {
285
+ const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
286
+ const sshHostname = `${ wsData ! . id } .${ domain } ` ;
287
+ sshDest = new SSHDestination ( sshHostname , wsData ! . id ) ;
288
+ } else {
289
+ ( { destination : sshDest , password } = await this . remoteService . getWorkspaceSSHDestination ( wsData ! ) ) ;
263
290
}
264
291
292
+ if ( password ) {
293
+ try {
294
+ await this . remoteService . showSSHPasswordModal ( wsData ! , password ) ;
295
+ } catch {
296
+ return ;
297
+ }
298
+ }
299
+
300
+ // TODO: remove this, should not be needed
301
+ await this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDest . toRemoteSSHString ( ) } ` , { workspaceId : wsData ! . id , gitpodHost : this . hostService . gitpodHost , instanceId : '' } as SSHConnectionParams ) ;
302
+
265
303
await vscode . commands . executeCommand (
266
304
'vscode.openFolder' ,
267
305
vscode . Uri . parse ( `vscode-remote://ssh-remote+${ sshDest . toRemoteSSHString ( ) } ${ wsData ! . recentFolders [ 0 ] || `/workspace/${ wsData ! . repo } ` } ` ) ,
268
306
{ forceNewWindow : false }
269
307
) ;
270
308
}
271
309
) ;
310
+ } catch ( e ) {
311
+ this . logService . error ( e ) ;
312
+ this . telemetryService . sendTelemetryException ( new WrapError ( 'Error runnning connectInCurrentWindow command' , e ) ) ;
313
+ throw e ;
272
314
} finally {
273
315
wsState . dispose ( ) ;
274
316
}
@@ -288,7 +330,7 @@ export class ConnectInCurrentWindowCommand implements Command {
288
330
}
289
331
} catch ( e ) {
290
332
const openSSHVersion = await getOpenSSHVersion ( ) ;
291
- this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e , 'Unknown' ) , {
333
+ this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e ) , {
292
334
gitpodHost : this . hostService . gitpodHost ,
293
335
openSSHVersion,
294
336
workspaceId
@@ -307,10 +349,11 @@ export class ConnectInCurrentWindowCommandContext extends ConnectInCurrentWindow
307
349
remoteService : IRemoteService ,
308
350
sessionService : ISessionService ,
309
351
hostService : IHostService ,
352
+ experimentsService : IExperimentsService ,
310
353
telemetryService : ITelemetryService ,
311
354
logService : ILogService ,
312
355
) {
313
- super ( context , remoteService , sessionService , hostService , telemetryService , logService ) ;
356
+ super ( context , remoteService , sessionService , hostService , experimentsService , telemetryService , logService ) ;
314
357
}
315
358
}
316
359
@@ -322,10 +365,11 @@ export class ConnectInCurrentWindowCommandContext_1 extends ConnectInCurrentWind
322
365
remoteService : IRemoteService ,
323
366
sessionService : ISessionService ,
324
367
hostService : IHostService ,
368
+ experimentsService : IExperimentsService ,
325
369
telemetryService : ITelemetryService ,
326
370
logService : ILogService ,
327
371
) {
328
- super ( context , remoteService , sessionService , hostService , telemetryService , logService ) ;
372
+ super ( context , remoteService , sessionService , hostService , experimentsService , telemetryService , logService ) ;
329
373
}
330
374
}
331
375
@@ -337,10 +381,11 @@ export class ConnectInCurrentWindowCommandInline extends ConnectInCurrentWindowC
337
381
remoteService : IRemoteService ,
338
382
sessionService : ISessionService ,
339
383
hostService : IHostService ,
384
+ experimentsService : IExperimentsService ,
340
385
telemetryService : ITelemetryService ,
341
386
logService : ILogService ,
342
387
) {
343
- super ( context , remoteService , sessionService , hostService , telemetryService , logService ) ;
388
+ super ( context , remoteService , sessionService , hostService , experimentsService , telemetryService , logService ) ;
344
389
}
345
390
}
346
391
@@ -352,10 +397,11 @@ export class ConnectInCurrentWindowCommandInline_1 extends ConnectInCurrentWindo
352
397
remoteService : IRemoteService ,
353
398
sessionService : ISessionService ,
354
399
hostService : IHostService ,
400
+ experimentsService : IExperimentsService ,
355
401
telemetryService : ITelemetryService ,
356
402
logService : ILogService ,
357
403
) {
358
- super ( context , remoteService , sessionService , hostService , telemetryService , logService ) ;
404
+ super ( context , remoteService , sessionService , hostService , experimentsService , telemetryService , logService ) ;
359
405
}
360
406
}
361
407
0 commit comments