@@ -223,11 +223,11 @@ class CoderCLIManager(
223223 * This can take supported features for testing purposes only.
224224 */
225225 fun configSsh (
226- workspaceNames : Set <String >,
226+ wsWithAgents : Set <Pair < Workspace , WorkspaceAgent > >,
227227 feats : Features = features,
228228 ) {
229229 logger.info(" Configuring SSH config at ${settings.sshConfigPath} " )
230- writeSSHConfig(modifySSHConfig(readSSHConfig(), workspaceNames , feats))
230+ writeSSHConfig(modifySSHConfig(readSSHConfig(), wsWithAgents , feats))
231231 }
232232
233233 /* *
@@ -249,13 +249,13 @@ class CoderCLIManager(
249249 */
250250 private fun modifySSHConfig (
251251 contents : String? ,
252- workspaceNames : Set <String >,
252+ wsWithAgents : Set <Pair < Workspace , WorkspaceAgent > >,
253253 feats : Features ,
254254 ): String? {
255255 val host = deploymentURL.safeHost()
256256 val startBlock = " # --- START CODER JETBRAINS TOOLBOX $host "
257257 val endBlock = " # --- END CODER JETBRAINS TOOLBOX $host "
258- val isRemoving = workspaceNames .isEmpty()
258+ val isRemoving = wsWithAgents .isEmpty()
259259 val baseArgs =
260260 listOfNotNull(
261261 escape(localBinaryPath.toString()),
@@ -304,34 +304,39 @@ class CoderCLIManager(
304304 .plus(" \n\n " )
305305 .plus(
306306 """
307- Host ${getHostnamePrefix (deploymentURL)} -bg --*
307+ Host ${getBackgroundHostnamePrefix (deploymentURL)} --*
308308 ProxyCommand ${backgroundProxyArgs.joinToString(" " )} --ssh-host-prefix ${
309- getHostnamePrefix (
309+ getBackgroundHostnamePrefix (
310310 deploymentURL
311311 )
312- } -bg- - %h
312+ } -- %h
313313 """ .trimIndent()
314314 .plus(" \n " + options.prependIndent(" " ))
315315 .plus(extraConfig),
316316 ).replace(" \n " , System .lineSeparator()) +
317317 System .lineSeparator() + endBlock
318318 } else {
319- workspaceNames .joinToString(
319+ wsWithAgents .joinToString(
320320 System .lineSeparator(),
321321 startBlock + System .lineSeparator(),
322322 System .lineSeparator() + endBlock,
323323 transform = {
324324 """
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())}
327327 """ .trimIndent()
328328 .plus(" \n " + options.prependIndent(" " ))
329329 .plus(extraConfig)
330330 .plus(" \n " )
331331 .plus(
332332 """
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+ }
335340 """ .trimIndent()
336341 .plus(" \n " + options.prependIndent(" " ))
337342 .plus(extraConfig),
@@ -511,20 +516,23 @@ class CoderCLIManager(
511516
512517 fun getHostnamePrefix (url : URL ): String = " coder-jetbrains-toolbox-${url.safeHost()} "
513518
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+ }
516531
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} "
519533
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
524535
525- fun getBackgroundHostName (
526- url : URL ,
527- workspaceName : String ,
528- ): String = getHostName(url, workspaceName) + " --bg"
536+ fun Pair <Workspace , WorkspaceAgent >.agent () = this .second
529537 }
530538}
0 commit comments