-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnvironmentView.kt
47 lines (41 loc) · 1.55 KB
/
EnvironmentView.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.coder.toolbox.views
import com.coder.toolbox.cli.CoderCLIManager
import com.coder.toolbox.sdk.v2.models.Workspace
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
import com.coder.toolbox.settings.ReadOnlyCoderSettings
import com.jetbrains.toolbox.api.remoteDev.environments.SshEnvironmentContentsView
import com.jetbrains.toolbox.api.remoteDev.ssh.SshConnectionInfo
import java.net.URL
/**
* A view for a single environment. It displays the projects and IDEs.
*
* This just delegates to the SSH view provided by Toolbox, all we have to do is
* provide the host name.
*
* SSH must be configured before this will work.
*/
class EnvironmentView(
private val settings: ReadOnlyCoderSettings,
private val url: URL,
private val workspace: Workspace,
private val agent: WorkspaceAgent,
) : SshEnvironmentContentsView {
override suspend fun getConnectionInfo(): SshConnectionInfo = object : SshConnectionInfo {
/**
* The host name generated by the cli manager for this workspace.
*/
override val host: String = resolveHost()
/**
* The port is ignored by the Coder proxy command.
*/
override val port: Int = 22
/**
* The username is ignored by the Coder proxy command.
*/
override val userName: String? = null
}
private fun resolveHost(): String =
if (settings.isSshWildcardConfigEnabled)
CoderCLIManager.getWildcardHostname(url, workspace, agent)
else CoderCLIManager.getHostname(url, workspace, agent)
}