@@ -4,31 +4,34 @@ package com.coder.gateway
44
55import com.coder.gateway.models.RecentWorkspaceConnection
66import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
7- import com.coder.gateway.views.CoderGatewayConnectionComponent
87import com.intellij.openapi.components.service
98import com.intellij.openapi.diagnostic.Logger
109import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
1110import com.intellij.remote.AuthType
1211import com.intellij.remote.RemoteCredentialsHolder
1312import com.intellij.ssh.config.unified.SshConfig
13+ import com.intellij.ssh.config.unified.SshConfigManager
1414import com.jetbrains.gateway.api.ConnectionRequestor
1515import com.jetbrains.gateway.api.GatewayConnectionHandle
1616import com.jetbrains.gateway.api.GatewayConnectionProvider
17+ import com.jetbrains.gateway.ssh.HighLevelHostAccessor
18+ import com.jetbrains.gateway.ssh.HostDeployInputs
1719import com.jetbrains.gateway.ssh.IdeInfo
1820import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
19- import com.jetbrains.gateway.ssh.SshCommandsExecutor
2021import com.jetbrains.gateway.ssh.SshDeployFlowUtil
21- import com.jetbrains.gateway.ssh.SshDownloadMethod
2222import com.jetbrains.gateway.ssh.SshMultistagePanelContext
23+ import com.jetbrains.gateway.ssh.deploy.DeployTargetInfo.DeployWithDownload
2324import com.jetbrains.rd.util.lifetime.LifetimeDefinition
2425import kotlinx.coroutines.launch
26+ import java.net.URI
2527import java.time.Duration
2628import java.time.LocalDateTime
2729import java.time.format.DateTimeFormatter
28- import javax.swing.JComponent
2930
3031class 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- downloadMethod = SshDownloadMethod .CustomizedLink
75- customDownloadLink = ideDownloadLink
76- ide = ideConfig
77- }
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+ )
7886 launch {
79- @Suppress(" UnstableApiUsage" )
80- SshDeployFlowUtil .fullDeployCycle(
81- clientLifetime,
82- context,
83- Duration .ofMinutes(10 )
87+ @Suppress(" UnstableApiUsage" ) SshDeployFlowUtil .fullDeployCycle(
88+ clientLifetime, context, Duration .ofMinutes(10 )
8489 )
8590 }
8691 }
8792
8893 recentConnectionsService.addRecentConnection(
8994 RecentWorkspaceConnection (
90- coderWorkspaceHostname,
91- projectPath,
92- localTimeFormatter.format(LocalDateTime .now()),
93- ideProductCode,
94- ideBuildNumber,
95- ideDownloadLink,
96- webTerminalLink,
95+ coderWorkspaceHostname, projectPath, localTimeFormatter.format(LocalDateTime .now()), ideProductCode, ideBuildNumber, ideDownloadLink, webTerminalLink
9796 )
9897 )
9998
10099 return object : GatewayConnectionHandle (clientLifetime) {
101- override fun createComponent (): JComponent {
102- return CoderGatewayConnectionComponent (clientLifetime, coderWorkspaceHostname)
103- }
104-
105100 override fun getTitle (): String {
106101 return " Connection to Coder Workspaces"
107102 }
0 commit comments