Skip to content

Commit b945bf1

Browse files
committed
Update connection view to ask for email and password
- needed to authenticate on coder and retrieve a session token - password is saved in intellij credential's store - refactored the url text field into a hostname and port
1 parent 4b284b4 commit b945bf1

File tree

4 files changed

+66
-18
lines changed

4 files changed

+66
-18
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
### Added
88

99
* welcome screen
10-
* basuc connector view triggered by the Coder's welcome view.
10+
* basic connector view triggered by the Coder's welcome view. It asks the user a Coder hostname, port, email and password.
1111
* back button to return to the main welcome view
12-
* basic Coder http client
12+
* basic Coder http client which authenticates and retrieves a session token
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.coder.gateway.models
2+
3+
internal data class LoginModel(var host: String = "localhost", var port: Int = 7080, var email: String = "example@email.com", var password: String? = "")

src/main/kotlin/com/coder/gateway/views/CoderGatewayLoginView.kt

+49-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
package com.coder.gateway.views
22

33
import com.coder.gateway.CoderGatewayBundle
4+
import com.coder.gateway.models.LoginModel
5+
import com.coder.gateway.sdk.CoderClientService
6+
import com.intellij.credentialStore.CredentialAttributes
7+
import com.intellij.credentialStore.askPassword
48
import com.intellij.ide.IdeBundle
9+
import com.intellij.openapi.Disposable
10+
import com.intellij.openapi.application.ApplicationManager
11+
import com.intellij.openapi.diagnostic.Logger
512
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
613
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
714
import com.intellij.ui.IconManager
815
import com.intellij.ui.SeparatorComponent
916
import com.intellij.ui.components.panels.VerticalLayout
1017
import com.intellij.ui.dsl.builder.BottomGap
18+
import com.intellij.ui.dsl.builder.RightGap
1119
import com.intellij.ui.dsl.builder.TopGap
20+
import com.intellij.ui.dsl.builder.bindIntText
21+
import com.intellij.ui.dsl.builder.bindText
1222
import com.intellij.ui.dsl.builder.panel
1323
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
1424
import com.intellij.util.ui.JBFont
1525
import com.intellij.util.ui.JBUI
1626
import com.intellij.util.ui.components.BorderLayoutPanel
1727
import com.jetbrains.gateway.api.GatewayUI
28+
import kotlinx.coroutines.CoroutineScope
29+
import kotlinx.coroutines.Dispatchers
30+
import kotlinx.coroutines.cancel
31+
import kotlinx.coroutines.launch
32+
import kotlinx.coroutines.withContext
1833
import java.awt.Component
1934
import javax.swing.JButton
2035
import javax.swing.JPanel
2136

22-
class CoderGatewayLoginView : BorderLayoutPanel() {
37+
class CoderGatewayLoginView : BorderLayoutPanel(), Disposable {
38+
private val logger = Logger.getInstance(CoderClientService::class.java)
39+
private val cs = CoroutineScope(Dispatchers.Main)
40+
private val model = LoginModel()
41+
private val coderClient: CoderClientService = ApplicationManager.getApplication().getService(CoderClientService::class.java)
42+
2343
init {
2444
initView()
2545
}
@@ -45,17 +65,35 @@ class CoderGatewayLoginView : BorderLayoutPanel() {
4565
row {
4666
browserLink(CoderGatewayBundle.message("gateway.connector.view.login.documentation.action"), "https://coder.com/docs/coder/latest/workspaces")
4767
}.bottomGap(BottomGap.MEDIUM)
48-
row {
49-
label(CoderGatewayBundle.message("gateway.connector.view.login.url.label"))
50-
textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).applyToComponent {
51-
text = "https://dev.coder.com"
52-
}
53-
button(CoderGatewayBundle.message("gateway.connector.view.login.connect.action"), {}).applyToComponent {
68+
row(CoderGatewayBundle.message("gateway.connector.view.login.host.label")) {
69+
textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(model::host)
70+
intTextField(0..65536).bindIntText(model::port).label(CoderGatewayBundle.message("gateway.connector.view.login.port.label"))
71+
button(CoderGatewayBundle.message("gateway.connector.view.login.connect.action")) {
72+
model.password = askPassword(
73+
null,
74+
CoderGatewayBundle.message("gateway.connector.view.login.credentials.dialog.title"),
75+
CoderGatewayBundle.message("gateway.connector.view.login.password.label"),
76+
CredentialAttributes("Coder"),
77+
false
78+
)
79+
cs.launch {
80+
withContext(Dispatchers.IO) {
81+
coderClient.initClientSession(model.host, model.port, model.email, model.password!!)
82+
}
83+
logger.info("Session token:${coderClient.sessionToken}")
84+
}
85+
86+
}.applyToComponent {
5487
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
5588
border = JBUI.Borders.empty(3, 3, 3, 3)
5689
}
5790
cell()
5891
}
92+
93+
row(CoderGatewayBundle.message("gateway.connector.view.login.email.label")) {
94+
textField().resizableColumn().bindText(model::email)
95+
cell()
96+
}
5997
}
6098
}.apply {
6199
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
@@ -80,5 +118,8 @@ class CoderGatewayLoginView : BorderLayoutPanel() {
80118
}
81119
}
82120

121+
override fun dispose() {
122+
cs.cancel()
123+
}
124+
}
83125

84-
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
gateway.connector.title = Coder
2-
gateway.connector.description = Connects to a dev environment running in Coder Workspaces
3-
gateway.connector.action.text = Connect to Coder Workspaces
4-
gateway.connector.view.login.header.text = Coder Workspaces
5-
gateway.connector.view.login.comment.text = Self-hosted developer workspaces in the cloud or on premise. Coder Workspaces empower developers with secure, consistent, and fast developer workspaces.
6-
gateway.connector.view.login.documentation.action = Explore Coder Workspaces
7-
gateway.connector.view.login.url.label = Url:
8-
gateway.connector.view.login.connect.action = Connect
1+
gateway.connector.title=Coder
2+
gateway.connector.description=Connects to a dev environment running in Coder Workspaces
3+
gateway.connector.action.text=Connect to Coder Workspaces
4+
gateway.connector.view.login.header.text=Coder Workspaces
5+
gateway.connector.view.login.comment.text=Self-hosted developer workspaces in the cloud or on premise. Coder Workspaces empower developers with secure, consistent, and fast developer workspaces.
6+
gateway.connector.view.login.documentation.action=Explore Coder Workspaces
7+
gateway.connector.view.login.host.label=Host:
8+
gateway.connector.view.login.port.label=Port:
9+
gateway.connector.view.login.email.label=Email:
10+
gateway.connector.view.login.password.label=Password:
11+
gateway.connector.view.login.connect.action=Connect
12+
gateway.connector.view.login.credentials.dialog.title = Coder Credentials

0 commit comments

Comments
 (0)