@@ -5,7 +5,6 @@ package com.coder.gateway.views
5
5
import com.coder.gateway.CoderGatewayBundle
6
6
import com.coder.gateway.CoderGatewayConstants
7
7
import com.coder.gateway.CoderRemoteConnectionHandle
8
- import com.coder.gateway.cli.CoderCLIManager
9
8
import com.coder.gateway.cli.ensureCLI
10
9
import com.coder.gateway.icons.CoderIcons
11
10
import com.coder.gateway.models.WorkspaceAgentListModel
@@ -75,8 +74,6 @@ data class DeploymentInfo(
75
74
var items : List <WorkspaceAgentListModel >? = null ,
76
75
// Null if there have not been any errors yet.
77
76
var error : String? = null ,
78
- // Null if unable to ensure the CLI is downloaded.
79
- var cli : CoderCLIManager ? = null ,
80
77
)
81
78
82
79
class CoderGatewayRecentWorkspaceConnectionsView (private val setContentCallback : (Component ) -> Unit ) :
@@ -178,13 +175,18 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
178
175
val me = deployment?.client?.me?.username
179
176
val workspaceWithAgent = deployment?.items?.firstOrNull {
180
177
it.workspace.ownerName + " /" + it.workspace.name == workspaceName ||
181
- (it.workspace.ownerName == me && it.workspace.name == workspaceName)
178
+ (it.workspace.ownerName == me && it.workspace.name == workspaceName)
182
179
}
183
180
val status =
184
181
if (deploymentError != null ) {
185
182
Triple (UIUtil .getErrorForeground(), deploymentError, UIUtil .getBalloonErrorIcon())
186
183
} else if (workspaceWithAgent != null ) {
187
- val inLoadingState = listOf (WorkspaceStatus .STARTING , WorkspaceStatus .CANCELING , WorkspaceStatus .DELETING , WorkspaceStatus .STOPPING ).contains(workspaceWithAgent.workspace.latestBuild.status)
184
+ val inLoadingState = listOf (
185
+ WorkspaceStatus .STARTING ,
186
+ WorkspaceStatus .CANCELING ,
187
+ WorkspaceStatus .DELETING ,
188
+ WorkspaceStatus .STOPPING
189
+ ).contains(workspaceWithAgent.workspace.latestBuild.status)
188
190
189
191
Triple (
190
192
workspaceWithAgent.status.statusColor(),
@@ -196,7 +198,11 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
196
198
},
197
199
)
198
200
} else {
199
- Triple (UIUtil .getContextHelpForeground(), " Querying workspace status..." , AnimatedIcon .Default ())
201
+ Triple (
202
+ UIUtil .getContextHelpForeground(),
203
+ " Querying workspace status..." ,
204
+ AnimatedIcon .Default ()
205
+ )
200
206
}
201
207
val gap =
202
208
if (top) {
@@ -216,7 +222,13 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
216
222
label(" " ).resizableColumn().align(AlignX .FILL )
217
223
}.topGap(gap)
218
224
219
- val enableLinks = listOf (WorkspaceStatus .STOPPED , WorkspaceStatus .CANCELED , WorkspaceStatus .FAILED , WorkspaceStatus .STARTING , WorkspaceStatus .RUNNING ).contains(workspaceWithAgent?.workspace?.latestBuild?.status)
225
+ val enableLinks = listOf (
226
+ WorkspaceStatus .STOPPED ,
227
+ WorkspaceStatus .CANCELED ,
228
+ WorkspaceStatus .FAILED ,
229
+ WorkspaceStatus .STARTING ,
230
+ WorkspaceStatus .RUNNING
231
+ ).contains(workspaceWithAgent?.workspace?.latestBuild?.status)
220
232
221
233
// We only display an API error on the first workspace rather than duplicating it on each workspace.
222
234
if (deploymentError == null || showError) {
@@ -236,9 +248,29 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
236
248
if (enableLinks) {
237
249
cell(
238
250
ActionLink (workspaceProjectIDE.projectPathDisplay) {
239
- withoutNull(deployment?.cli, workspaceWithAgent?.workspace) { cli, workspace ->
251
+ withoutNull(
252
+ deployment?.client,
253
+ workspaceWithAgent?.workspace
254
+ ) { client, workspace ->
240
255
CoderRemoteConnectionHandle ().connect {
241
- if (listOf (WorkspaceStatus .STOPPED , WorkspaceStatus .CANCELED , WorkspaceStatus .FAILED ).contains(workspace.latestBuild.status)) {
256
+ if (listOf (
257
+ WorkspaceStatus .STOPPED ,
258
+ WorkspaceStatus .CANCELED ,
259
+ WorkspaceStatus .FAILED
260
+ ).contains(workspace.latestBuild.status)
261
+ ) {
262
+ val cli = ensureCLI(
263
+ deploymentURL.toURL(),
264
+ client.buildInfo().version,
265
+ settings,
266
+ )
267
+ // We only need to log the cli in if we have token-based auth.
268
+ // Otherwise, we assume it is set up in the same way the plugin
269
+ // is with mTLS.
270
+ if (client.token != null ) {
271
+ cli.login(client.token)
272
+ }
273
+
242
274
cli.startWorkspace(workspace.ownerName, workspace.name)
243
275
}
244
276
workspaceProjectIDE
@@ -289,33 +321,34 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
289
321
* name, or just `workspace`, if the connection predates when we added owner
290
322
* information, in which case it belongs to the current user.
291
323
*/
292
- private fun getConnectionsByDeployment (filter : Boolean ): Map <String , Map <String , List <WorkspaceProjectIDE >>> = recentConnectionsService.getAllRecentConnections()
293
- // Validate and parse connections.
294
- .mapNotNull {
295
- try {
296
- it.toWorkspaceProjectIDE()
297
- } catch (e: Exception ) {
298
- logger.warn(" Removing invalid recent connection $it " , e)
299
- recentConnectionsService.removeConnection(it)
300
- null
324
+ private fun getConnectionsByDeployment (filter : Boolean ): Map <String , Map <String , List <WorkspaceProjectIDE >>> =
325
+ recentConnectionsService.getAllRecentConnections()
326
+ // Validate and parse connections.
327
+ .mapNotNull {
328
+ try {
329
+ it.toWorkspaceProjectIDE()
330
+ } catch (e: Exception ) {
331
+ logger.warn(" Removing invalid recent connection $it " , e)
332
+ recentConnectionsService.removeConnection(it)
333
+ null
334
+ }
335
+ }
336
+ .filter { ! filter || matchesFilter(it) }
337
+ // Group by the deployment.
338
+ .groupBy { it.deploymentURL.toString() }
339
+ // Group the connections in each deployment by workspace.
340
+ .mapValues { (_, connections) ->
341
+ connections
342
+ .groupBy { it.name.split(" ." , limit = 2 ).first() }
301
343
}
302
- }
303
- .filter { ! filter || matchesFilter(it) }
304
- // Group by the deployment.
305
- .groupBy { it.deploymentURL.toString() }
306
- // Group the connections in each deployment by workspace.
307
- .mapValues { (_, connections) ->
308
- connections
309
- .groupBy { it.name.split(" ." , limit = 2 ).first() }
310
- }
311
344
312
345
/* *
313
346
* Return true if the connection matches the current filter.
314
347
*/
315
348
private fun matchesFilter (connection : WorkspaceProjectIDE ): Boolean = filterString.let {
316
349
it.isNullOrBlank() ||
317
- connection.hostname.lowercase(Locale .getDefault()).contains(it) ||
318
- connection.projectPath.lowercase(Locale .getDefault()).contains(it)
350
+ connection.hostname.lowercase(Locale .getDefault()).contains(it) ||
351
+ connection.projectPath.lowercase(Locale .getDefault()).contains(it)
319
352
}
320
353
321
354
/* *
@@ -362,19 +395,6 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
362
395
throw Exception (" Unable to make request; token was not found in CLI config." )
363
396
}
364
397
365
- val cli = ensureCLI(
366
- deploymentURL.toURL(),
367
- client.buildInfo().version,
368
- settings,
369
- )
370
-
371
- // We only need to log the cli in if we have token-based auth.
372
- // Otherwise, we assume it is set up in the same way the plugin
373
- // is with mTLS.
374
- if (client.token != null ) {
375
- cli.login(client.token)
376
- }
377
-
378
398
// This is purely to populate the current user, which is
379
399
// used to match workspaces that were not recorded with owner
380
400
// information.
@@ -386,7 +406,7 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
386
406
connectionsByWorkspace.forEach { (name, connections) ->
387
407
if (items.firstOrNull {
388
408
it.workspace.ownerName + " /" + it.workspace.name == name ||
389
- (it.workspace.ownerName == me && it.workspace.name == name)
409
+ (it.workspace.ownerName == me && it.workspace.name == name)
390
410
} == null
391
411
) {
392
412
logger.info(" Removing recent connections for deleted workspace $name (found ${connections.size} )" )
@@ -395,7 +415,6 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
395
415
}
396
416
397
417
deployment.client = client
398
- deployment.cli = cli
399
418
deployment.items = items
400
419
deployment.error = null
401
420
} catch (e: Exception ) {
0 commit comments