@@ -4,31 +4,34 @@ package com.coder.gateway
4
4
5
5
import com.coder.gateway.models.RecentWorkspaceConnection
6
6
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
7
- import com.coder.gateway.views.CoderGatewayConnectionComponent
8
7
import com.intellij.openapi.components.service
9
8
import com.intellij.openapi.diagnostic.Logger
10
9
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
11
10
import com.intellij.remote.AuthType
12
11
import com.intellij.remote.RemoteCredentialsHolder
13
12
import com.intellij.ssh.config.unified.SshConfig
13
+ import com.intellij.ssh.config.unified.SshConfigManager
14
14
import com.jetbrains.gateway.api.ConnectionRequestor
15
15
import com.jetbrains.gateway.api.GatewayConnectionHandle
16
16
import com.jetbrains.gateway.api.GatewayConnectionProvider
17
+ import com.jetbrains.gateway.ssh.HighLevelHostAccessor
18
+ import com.jetbrains.gateway.ssh.HostDeployInputs
17
19
import com.jetbrains.gateway.ssh.IdeInfo
18
20
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
19
- import com.jetbrains.gateway.ssh.SshCommandsExecutor
20
21
import com.jetbrains.gateway.ssh.SshDeployFlowUtil
21
- import com.jetbrains.gateway.ssh.SshDownloadMethod
22
22
import com.jetbrains.gateway.ssh.SshMultistagePanelContext
23
+ import com.jetbrains.gateway.ssh.deploy.DeployTargetInfo.DeployWithDownload
23
24
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
24
25
import kotlinx.coroutines.launch
26
+ import java.net.URI
25
27
import java.time.Duration
26
28
import java.time.LocalDateTime
27
29
import java.time.format.DateTimeFormatter
28
- import javax.swing.JComponent
29
30
30
31
class CoderGatewayConnectionProvider : GatewayConnectionProvider {
31
32
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService >()
33
+ private val sshConfigService = service<SshConfigManager >()
34
+
32
35
private val connections = mutableSetOf<CoderConnectionMetadata >()
33
36
private val localTimeFormatter = DateTimeFormatter .ofPattern(" yyyy-MMM-dd HH:mm" )
34
37
@@ -46,62 +49,54 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
46
49
logger.warn(" There is already a connection started on ${connection.workspaceHostname} " )
47
50
return null
48
51
}
49
- val clientLifetime = LifetimeDefinition ()
50
-
51
- val credentials = RemoteCredentialsHolder ().apply {
52
- setHost(coderWorkspaceHostname)
53
- userName = " coder"
54
- authType = AuthType .OPEN_SSH
55
- }
56
-
57
52
val sshConfiguration = SshConfig (true ).apply {
58
53
setHost(coderWorkspaceHostname)
59
54
setUsername(" coder" )
55
+ port = 22
60
56
authType = AuthType .OPEN_SSH
61
57
}
62
58
63
- val ideConfig = IdeInfo (
64
- product = IntelliJPlatformProduct .fromProductCode(ideProductCode)!! ,
65
- buildNumber = ideBuildNumber
66
- )
67
-
59
+ val clientLifetime = LifetimeDefinition ()
68
60
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
+ )
78
86
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 )
84
89
)
85
90
}
86
91
}
87
92
88
93
recentConnectionsService.addRecentConnection(
89
94
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
97
96
)
98
97
)
99
98
100
99
return object : GatewayConnectionHandle (clientLifetime) {
101
- override fun createComponent (): JComponent {
102
- return CoderGatewayConnectionComponent (clientLifetime, coderWorkspaceHostname)
103
- }
104
-
105
100
override fun getTitle (): String {
106
101
return " Connection to Coder Workspaces"
107
102
}
0 commit comments