Skip to content

Commit 9651a17

Browse files
committed
Fix: migrate to new API
- the host executor and it's utilities like `guessOs` are now under a `host accessor` - ssh context is also changed - all params are now grouped under a `host deploy inputs` wrapper.
1 parent f7b37f1 commit 9651a17

File tree

2 files changed

+50
-51
lines changed

2 files changed

+50
-51
lines changed

src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@ package com.coder.gateway
44

55
import com.coder.gateway.models.RecentWorkspaceConnection
66
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
7-
import com.coder.gateway.views.CoderGatewayConnectionComponent
87
import com.intellij.openapi.components.service
98
import com.intellij.openapi.diagnostic.Logger
109
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
1110
import com.intellij.remote.AuthType
1211
import com.intellij.remote.RemoteCredentialsHolder
1312
import com.intellij.ssh.config.unified.SshConfig
13+
import com.intellij.ssh.config.unified.SshConfigManager
1414
import com.jetbrains.gateway.api.ConnectionRequestor
1515
import com.jetbrains.gateway.api.GatewayConnectionHandle
1616
import com.jetbrains.gateway.api.GatewayConnectionProvider
17-
import com.jetbrains.gateway.ssh.Download
17+
import com.jetbrains.gateway.ssh.HighLevelHostAccessor
18+
import com.jetbrains.gateway.ssh.HostDeployInputs
1819
import com.jetbrains.gateway.ssh.IdeInfo
1920
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
20-
import com.jetbrains.gateway.ssh.SshCommandsExecutor
2121
import com.jetbrains.gateway.ssh.SshDeployFlowUtil
2222
import com.jetbrains.gateway.ssh.SshMultistagePanelContext
23+
import com.jetbrains.gateway.ssh.deploy.DeployTargetInfo.DeployWithDownload
2324
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
2425
import kotlinx.coroutines.launch
26+
import java.net.URI
2527
import java.time.Duration
2628
import java.time.LocalDateTime
2729
import java.time.format.DateTimeFormatter
28-
import javax.swing.JComponent
2930

3031
class CoderGatewayConnectionProvider : GatewayConnectionProvider {
3132
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
33+
private val sshConfigService = service<SshConfigManager>()
34+
3235
private val connections = mutableSetOf<CoderConnectionMetadata>()
3336
private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")
3437

@@ -46,62 +49,54 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
4649
logger.warn("There is already a connection started on ${connection.workspaceHostname}")
4750
return null
4851
}
49-
val clientLifetime = LifetimeDefinition()
50-
51-
val credentials = RemoteCredentialsHolder().apply {
52-
setHost(coderWorkspaceHostname)
53-
userName = "coder"
54-
authType = AuthType.OPEN_SSH
55-
}
56-
5752
val sshConfiguration = SshConfig(true).apply {
5853
setHost(coderWorkspaceHostname)
5954
setUsername("coder")
55+
port = 22
6056
authType = AuthType.OPEN_SSH
6157
}
6258

63-
val ideConfig = IdeInfo(
64-
product = IntelliJPlatformProduct.fromProductCode(ideProductCode)!!,
65-
buildNumber = ideBuildNumber
66-
)
67-
59+
val clientLifetime = LifetimeDefinition()
6860
clientLifetime.launchUnderBackgroundProgress("Coder Gateway Deploy", canBeCancelled = true, isIndeterminate = true, project = null) {
69-
val context = SshMultistagePanelContext().apply {
70-
deploy = true
71-
sshConfig = sshConfiguration
72-
remoteProjectPath = projectPath
73-
remoteCommandsExecutor = SshCommandsExecutor.Companion.create(credentials)
74-
download = Download.fromJson(ideDownloadLink)
75-
ide = ideConfig
76-
}
61+
val context = SshMultistagePanelContext(
62+
HostDeployInputs.FullySpecified(
63+
remoteProjectPath = projectPath,
64+
deployTarget = DeployWithDownload(
65+
URI(ideDownloadLink),
66+
null,
67+
IdeInfo(
68+
product = IntelliJPlatformProduct.fromProductCode(ideProductCode)!!,
69+
buildNumber = ideBuildNumber
70+
)
71+
),
72+
remoteInfo = HostDeployInputs.WithDeployedWorker(
73+
HighLevelHostAccessor.create(
74+
RemoteCredentialsHolder().apply {
75+
setHost(coderWorkspaceHostname)
76+
userName = "coder"
77+
port = 22
78+
authType = AuthType.OPEN_SSH
79+
},
80+
true
81+
),
82+
HostDeployInputs.WithHostInfo(sshConfiguration)
83+
)
84+
)
85+
)
7786
launch {
78-
@Suppress("UnstableApiUsage")
79-
SshDeployFlowUtil.fullDeployCycle(
80-
clientLifetime,
81-
context,
82-
Duration.ofMinutes(10)
87+
@Suppress("UnstableApiUsage") SshDeployFlowUtil.fullDeployCycle(
88+
clientLifetime, context, Duration.ofMinutes(10)
8389
)
8490
}
8591
}
8692

8793
recentConnectionsService.addRecentConnection(
8894
RecentWorkspaceConnection(
89-
coderWorkspaceHostname,
90-
projectPath,
91-
localTimeFormatter.format(LocalDateTime.now()),
92-
ideProductCode,
93-
ideBuildNumber,
94-
ideDownloadLink,
95-
webTerminalLink,
95+
coderWorkspaceHostname, projectPath, localTimeFormatter.format(LocalDateTime.now()), ideProductCode, ideBuildNumber, ideDownloadLink, webTerminalLink
9696
)
9797
)
9898

9999
return object : GatewayConnectionHandle(clientLifetime) {
100-
@Deprecated("Implement customComponentProvider instead to provide better UI/UX without default controls")
101-
override fun createComponent(): JComponent {
102-
return CoderGatewayConnectionComponent(clientLifetime, coderWorkspaceHostname)
103-
}
104-
105100
override fun getTitle(): String {
106101
return "Connection to Coder Workspaces"
107102
}

src/main/kotlin/com/coder/gateway/views/steps/CoderLocateRemoteProjectStepView.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import com.jetbrains.gateway.ssh.CachingProductsJsonWrapper
3030
import com.jetbrains.gateway.ssh.DeployTargetOS
3131
import com.jetbrains.gateway.ssh.DeployTargetOS.OSArch
3232
import com.jetbrains.gateway.ssh.DeployTargetOS.OSKind
33+
import com.jetbrains.gateway.ssh.HighLevelHostAccessor
3334
import com.jetbrains.gateway.ssh.IdeStatus
3435
import com.jetbrains.gateway.ssh.IdeWithStatus
3536
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
36-
import com.jetbrains.gateway.ssh.SshCommandsExecutor
37+
import com.jetbrains.gateway.ssh.deploy.guessOs
3738
import kotlinx.coroutines.CoroutineScope
3839
import kotlinx.coroutines.Dispatchers
3940
import kotlinx.coroutines.cancel
@@ -121,7 +122,10 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
121122
userName = "coder"
122123
authType = AuthType.OPEN_SSH
123124
}
124-
SshCommandsExecutor.Companion.create(credentialsHolder).guessOs()
125+
HighLevelHostAccessor.create(
126+
credentialsHolder,
127+
true
128+
).hostCommandExecutor.guessOs()
125129
} catch (e: Exception) {
126130
logger.error("Could not resolve any IDE for workspace ${selectedWorkspace.name}. Reason: $e")
127131
null
@@ -159,20 +163,20 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
159163
return when (os) {
160164
OS.LINUX -> when (arch) {
161165
Arch.AMD64 -> DeployTargetOS(OSKind.Linux, OSArch.X86_64)
162-
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.Aarch64)
163-
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.Unknown)
166+
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.ARM_64)
167+
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.UNKNOWN)
164168
}
165169

166170
OS.WINDOWS -> when (arch) {
167171
Arch.AMD64 -> DeployTargetOS(OSKind.Windows, OSArch.X86_64)
168-
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.Aarch64)
169-
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.Unknown)
172+
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.ARM_64)
173+
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.UNKNOWN)
170174
}
171175

172176
OS.MAC -> when (arch) {
173177
Arch.AMD64 -> DeployTargetOS(OSKind.MacOs, OSArch.X86_64)
174-
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.Aarch64)
175-
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.Unknown)
178+
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.ARM_64)
179+
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.UNKNOWN)
176180
}
177181
}
178182
}
@@ -188,7 +192,7 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
188192
"project_path" to tfProject.text,
189193
"ide_product_code" to selectedIDE.product.productCode,
190194
"ide_build_number" to selectedIDE.buildNumber,
191-
"ide_download_link" to selectedIDE.download!!.toJson(),
195+
"ide_download_link" to selectedIDE.download!!.link,
192196
"web_terminal_link" to "${terminalLink.url}"
193197
)
194198
)

0 commit comments

Comments
 (0)