1
1
package com.coder.gateway
2
2
3
+ import com.coder.gateway.models.RecentWorkspaceConnection
4
+ import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
3
5
import com.coder.gateway.views.CoderGatewayConnectionComponent
6
+ import com.intellij.openapi.components.service
4
7
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
5
8
import com.intellij.remote.AuthType
6
9
import com.intellij.remote.RemoteCredentialsHolder
@@ -15,61 +18,80 @@ import com.jetbrains.gateway.ssh.SshDeployFlowUtil
15
18
import com.jetbrains.gateway.ssh.SshDownloadMethod
16
19
import com.jetbrains.gateway.ssh.SshMultistagePanelContext
17
20
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
18
- import kotlinx.coroutines.async
21
+ import kotlinx.coroutines.launch
19
22
import java.time.Duration
23
+ import java.time.LocalDateTime
24
+ import java.time.format.DateTimeFormatter
20
25
import java.util.logging.Logger
21
26
import javax.swing.JComponent
22
27
23
28
class CoderGatewayConnectionProvider : GatewayConnectionProvider {
29
+ private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService >()
24
30
private val connections = mutableSetOf<CoderConnectionMetadata >()
31
+ private val localTimeFormatter = DateTimeFormatter .ofPattern(" yyyy-MMM-dd HH:mm" )
32
+
25
33
override suspend fun connect (parameters : Map <String , String >, requestor : ConnectionRequestor ): GatewayConnectionHandle ? {
26
34
val coderWorkspaceHostname = parameters[" coder_workspace_hostname" ]
27
35
val projectPath = parameters[" project_path" ]
28
36
val ideProductCode = parameters[" ide_product_code" ]!!
29
37
val ideBuildNumber = parameters[" ide_build_number" ]!!
30
- val ideDownloadLink = parameters[" ide_download_link" ]
38
+ val ideDownloadLink = parameters[" ide_download_link" ]!!
31
39
32
- if (coderWorkspaceHostname != null ) {
40
+ if (coderWorkspaceHostname != null && projectPath != null ) {
33
41
val connection = CoderConnectionMetadata (coderWorkspaceHostname)
34
42
if (connection in connections) {
35
43
logger.warning(" There is already a connection started on ${connection.workspaceHostname} " )
36
44
return null
37
45
}
38
46
val clientLifetime = LifetimeDefinition ()
47
+
39
48
val credentials = RemoteCredentialsHolder ().apply {
40
49
setHost(coderWorkspaceHostname)
41
50
userName = " coder"
42
51
authType = AuthType .OPEN_SSH
43
52
}
44
53
54
+ val sshConfiguration = SshConfig (true ).apply {
55
+ setHost(coderWorkspaceHostname)
56
+ setUsername(" coder" )
57
+ authType = AuthType .OPEN_SSH
58
+ }
59
+
60
+ val ideConfig = IdeInfo (
61
+ product = IntelliJPlatformProduct .fromProductCode(ideProductCode)!! ,
62
+ buildNumber = ideBuildNumber
63
+ )
64
+
45
65
clientLifetime.launchUnderBackgroundProgress(" Coder Gateway Deploy" , true , true , null ) {
46
66
val context = SshMultistagePanelContext ().apply {
47
67
deploy = true
48
- sshConfig = SshConfig (true ).apply {
49
- setHost(coderWorkspaceHostname)
50
- setUsername(" coder" )
51
- authType = AuthType .OPEN_SSH
52
- }
68
+ sshConfig = sshConfiguration
53
69
remoteProjectPath = projectPath
54
70
remoteCommandsExecutor = SshCommandsExecutor .Companion .create(credentials)
55
71
downloadMethod = SshDownloadMethod .CustomizedLink
56
72
customDownloadLink = ideDownloadLink
57
- ide = IdeInfo (
58
- product = IntelliJPlatformProduct .fromProductCode(ideProductCode)!! ,
59
- buildNumber = ideBuildNumber
60
- )
73
+ ide = ideConfig
61
74
}
62
- val deployPair = async {
75
+ launch {
63
76
SshDeployFlowUtil .fullDeployCycle(
64
77
clientLifetime,
65
78
context,
66
79
Duration .ofMinutes(10 )
67
80
)
68
- }.await()
69
-
70
- logger.info(" >>>$deployPair " )
81
+ }
71
82
}
72
83
84
+ recentConnectionsService.addRecentConnection(
85
+ RecentWorkspaceConnection (
86
+ coderWorkspaceHostname,
87
+ projectPath,
88
+ localTimeFormatter.format(LocalDateTime .now()),
89
+ ideProductCode,
90
+ ideBuildNumber,
91
+ ideDownloadLink,
92
+ )
93
+ )
94
+
73
95
return object : GatewayConnectionHandle (clientLifetime) {
74
96
override fun createComponent (): JComponent {
75
97
return CoderGatewayConnectionComponent (clientLifetime, coderWorkspaceHostname)
0 commit comments