@@ -223,11 +223,11 @@ class CoderCLIManager(
223
223
* This can take supported features for testing purposes only.
224
224
*/
225
225
fun configSsh (
226
- workspaceNames : Set <String >,
226
+ wsWithAgents : Set <Pair < Workspace , WorkspaceAgent > >,
227
227
feats : Features = features,
228
228
) {
229
229
logger.info(" Configuring SSH config at ${settings.sshConfigPath} " )
230
- writeSSHConfig(modifySSHConfig(readSSHConfig(), workspaceNames , feats))
230
+ writeSSHConfig(modifySSHConfig(readSSHConfig(), wsWithAgents , feats))
231
231
}
232
232
233
233
/* *
@@ -249,13 +249,13 @@ class CoderCLIManager(
249
249
*/
250
250
private fun modifySSHConfig (
251
251
contents : String? ,
252
- workspaceNames : Set <String >,
252
+ wsWithAgents : Set <Pair < Workspace , WorkspaceAgent > >,
253
253
feats : Features ,
254
254
): String? {
255
255
val host = deploymentURL.safeHost()
256
256
val startBlock = " # --- START CODER JETBRAINS TOOLBOX $host "
257
257
val endBlock = " # --- END CODER JETBRAINS TOOLBOX $host "
258
- val isRemoving = workspaceNames .isEmpty()
258
+ val isRemoving = wsWithAgents .isEmpty()
259
259
val baseArgs =
260
260
listOfNotNull(
261
261
escape(localBinaryPath.toString()),
@@ -304,34 +304,39 @@ class CoderCLIManager(
304
304
.plus(" \n\n " )
305
305
.plus(
306
306
"""
307
- Host ${getHostnamePrefix (deploymentURL)} -bg --*
307
+ Host ${getBackgroundHostnamePrefix (deploymentURL)} --*
308
308
ProxyCommand ${backgroundProxyArgs.joinToString(" " )} --ssh-host-prefix ${
309
- getHostnamePrefix (
309
+ getBackgroundHostnamePrefix (
310
310
deploymentURL
311
311
)
312
- } -bg- - %h
312
+ } -- %h
313
313
""" .trimIndent()
314
314
.plus(" \n " + options.prependIndent(" " ))
315
315
.plus(extraConfig),
316
316
).replace(" \n " , System .lineSeparator()) +
317
317
System .lineSeparator() + endBlock
318
318
} else {
319
- workspaceNames .joinToString(
319
+ wsWithAgents .joinToString(
320
320
System .lineSeparator(),
321
321
startBlock + System .lineSeparator(),
322
322
System .lineSeparator() + endBlock,
323
323
transform = {
324
324
"""
325
- Host ${getHostName (deploymentURL, it)}
326
- ProxyCommand ${proxyArgs.joinToString(" " )} $it
325
+ Host ${getHostname (deploymentURL, it.workspace(), it.agent() )}
326
+ ProxyCommand ${proxyArgs.joinToString(" " )} ${getWsByOwner(it.workspace(), it.agent())}
327
327
""" .trimIndent()
328
328
.plus(" \n " + options.prependIndent(" " ))
329
329
.plus(extraConfig)
330
330
.plus(" \n " )
331
331
.plus(
332
332
"""
333
- Host ${getBackgroundHostName(deploymentURL, it)}
334
- ProxyCommand ${backgroundProxyArgs.joinToString(" " )} $it
333
+ Host ${getBackgroundHostname(deploymentURL, it.workspace(), it.agent())}
334
+ ProxyCommand ${backgroundProxyArgs.joinToString(" " )} ${
335
+ getWsByOwner(
336
+ it.workspace(),
337
+ it.agent()
338
+ )
339
+ }
335
340
""" .trimIndent()
336
341
.plus(" \n " + options.prependIndent(" " ))
337
342
.plus(extraConfig),
@@ -511,20 +516,23 @@ class CoderCLIManager(
511
516
512
517
fun getHostnamePrefix (url : URL ): String = " coder-jetbrains-toolbox-${url.safeHost()} "
513
518
514
- fun getWildcardHostname (url : URL , workspace : Workspace , agent : WorkspaceAgent ): String =
515
- " ${getHostnamePrefix(url)} -bg--${workspace.name} .${agent.name} "
519
+ fun getBackgroundHostnamePrefix (url : URL ): String = " coder-jetbrains-toolbox-${url.safeHost()} -bg"
520
+
521
+ fun getWildcardHostname (url : URL , ws : Workspace , agent : WorkspaceAgent ): String =
522
+ " ${getHostnamePrefix(url)} --${ws.ownerName} --${ws.name} .${agent.name} "
523
+
524
+ fun getHostname (url : URL , ws : Workspace , agent : WorkspaceAgent ): String {
525
+ return " coder-jetbrains-toolbox--${ws.ownerName} --${ws.name} .${agent.name} --${url.safeHost()} "
526
+ }
527
+
528
+ fun getBackgroundHostname (url : URL , ws : Workspace , agent : WorkspaceAgent ): String {
529
+ return " ${getHostname(url, ws, agent)} --bg"
530
+ }
516
531
517
- fun getHostname (url : URL , workspace : Workspace , agent : WorkspaceAgent ) =
518
- getHostName(url, " ${workspace.name} .${agent.name} " )
532
+ fun getWsByOwner (ws : Workspace , agent : WorkspaceAgent ): String = " ${ws.ownerName} /${ws.name} .${agent.name} "
519
533
520
- fun getHostName (
521
- url : URL ,
522
- workspaceName : String ,
523
- ): String = " coder-jetbrains-toolbox-$workspaceName --${url.safeHost()} "
534
+ fun Pair <Workspace , WorkspaceAgent >.workspace () = this .first
524
535
525
- fun getBackgroundHostName (
526
- url : URL ,
527
- workspaceName : String ,
528
- ): String = getHostName(url, workspaceName) + " --bg"
536
+ fun Pair <Workspace , WorkspaceAgent >.agent () = this .second
529
537
}
530
538
}
0 commit comments