Skip to content

Commit 620e488

Browse files
committed
Simplify the authentication window
- let the user input the url
1 parent f0f3360 commit 620e488

File tree

5 files changed

+27
-41
lines changed

5 files changed

+27
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package com.coder.gateway.models
22

3-
data class LoginModel(var uriScheme: UriScheme = UriScheme.HTTP, var host: String = "localhost", var port: Int = 7080, var email: String = "example@email.com", var password: String? = "")
3+
data class LoginModel(var url: String = "https://localhost", var email: String = "example@email.com", var password: String? = "")

src/main/kotlin/com/coder/gateway/sdk/CoderRestClientService.kt

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.coder.gateway.sdk
22

3-
import com.coder.gateway.models.UriScheme
43
import com.coder.gateway.sdk.convertors.InstantConverter
54
import com.coder.gateway.sdk.ex.AuthenticationException
65
import com.coder.gateway.sdk.v2.CoderV2RestFacade
@@ -17,6 +16,7 @@ import okhttp3.logging.HttpLoggingInterceptor
1716
import retrofit2.Retrofit
1817
import retrofit2.converter.gson.GsonConverterFactory
1918
import java.net.CookieManager
19+
import java.net.URL
2020
import java.time.Instant
2121

2222
@Service(Service.Level.APP)
@@ -29,9 +29,7 @@ class CoderRestClientService {
2929
* This must be called before anything else. It will authenticate with coder and retrieve a session token
3030
* @throws [AuthenticationException] if authentication failed
3131
*/
32-
fun initClientSession(uriScheme: UriScheme, host: String, port: Int, email: String, password: String) {
33-
val hostPath = host.trimEnd('/')
34-
32+
fun initClientSession(url: URL, email: String, password: String) {
3533
val gson: Gson = GsonBuilder()
3634
.registerTypeAdapter(Instant::class.java, InstantConverter())
3735
.setPrettyPrinting()
@@ -40,7 +38,7 @@ class CoderRestClientService {
4038
val interceptor = HttpLoggingInterceptor()
4139
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
4240
retroRestClient = Retrofit.Builder()
43-
.baseUrl("${uriScheme.scheme}://$hostPath:$port")
41+
.baseUrl(url.toString())
4442
.client(
4543
OkHttpClient.Builder()
4644
.addInterceptor(interceptor)
@@ -84,10 +82,4 @@ class CoderRestClientService {
8482

8583
return sshKeysResponse.body()!!
8684
}
87-
}
88-
89-
fun main() {
90-
val restClient = CoderRestClientService()
91-
restClient.initClientSession(UriScheme.HTTPS, "dev.coder.com", 443, "faur@coder.com", "coder123")
92-
println(restClient.workspaces())
9385
}

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.coder.gateway.views.steps
33
import com.coder.gateway.CoderGatewayBundle
44
import com.coder.gateway.models.CoderWorkspacesWizardModel
55
import com.coder.gateway.models.LoginModel
6-
import com.coder.gateway.models.UriScheme
76
import com.coder.gateway.sdk.CoderCLIManager
87
import com.coder.gateway.sdk.CoderRestClientService
98
import com.coder.gateway.sdk.OS
@@ -22,11 +21,8 @@ import com.intellij.ui.IconManager
2221
import com.intellij.ui.dsl.builder.BottomGap
2322
import com.intellij.ui.dsl.builder.RightGap
2423
import com.intellij.ui.dsl.builder.TopGap
25-
import com.intellij.ui.dsl.builder.bindIntText
26-
import com.intellij.ui.dsl.builder.bindItem
2724
import com.intellij.ui.dsl.builder.bindText
2825
import com.intellij.ui.dsl.builder.panel
29-
import com.intellij.ui.dsl.builder.toNullableProperty
3026
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
3127
import com.intellij.util.ui.JBFont
3228
import kotlinx.coroutines.CoroutineScope
@@ -56,12 +52,8 @@ class CoderAuthStepView : CoderWorkspacesWizardStep, Disposable {
5652
browserLink(CoderGatewayBundle.message("gateway.connector.view.login.documentation.action"), "https://coder.com/docs/coder/latest/workspaces")
5753
}.bottomGap(BottomGap.MEDIUM)
5854
row {
59-
label(CoderGatewayBundle.message("gateway.connector.view.login.scheme.label"))
60-
comboBox(UriScheme.values().toList()).bindItem(model::uriScheme.toNullableProperty())
61-
label(CoderGatewayBundle.message("gateway.connector.view.login.host.label"))
62-
textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(model::host)
63-
label(CoderGatewayBundle.message("gateway.connector.view.login.port.label"))
64-
intTextField(0..65536).bindIntText(model::port)
55+
label(CoderGatewayBundle.message("gateway.connector.view.login.url.label"))
56+
textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(model::url)
6557
cell()
6658
}
6759

@@ -79,9 +71,7 @@ class CoderAuthStepView : CoderWorkspacesWizardStep, Disposable {
7971

8072
override fun onInit(wizardModel: CoderWorkspacesWizardModel) {
8173
model.apply {
82-
uriScheme = wizardModel.loginModel.uriScheme
83-
host = wizardModel.loginModel.host
84-
port = wizardModel.loginModel.port
74+
url = wizardModel.loginModel.url
8575
email = wizardModel.loginModel.email
8676
password = wizardModel.loginModel.password
8777
}
@@ -99,25 +89,35 @@ class CoderAuthStepView : CoderWorkspacesWizardStep, Disposable {
9989
model.password = password
10090
val authTask = object : Task.Modal(null, "Authenticate and setup coder", false) {
10191
override fun run(pi: ProgressIndicator) {
102-
pi.text = "Authenticating ${model.email} on ${model.host}..."
103-
pi.fraction = 0.3
104-
coderClient.initClientSession(model.uriScheme, model.host, model.port, model.email, model.password!!)
92+
93+
pi.apply {
94+
text = "Authenticating ${model.email} on ${model.url}..."
95+
fraction = 0.3
96+
}
97+
98+
val url = URL(model.url)
99+
coderClient.initClientSession(url, model.email, model.password!!)
105100
wizardModel.apply {
106101
loginModel = model.copy()
107102
}
108103

109-
pi.text = "Downloading coder cli..."
110-
pi.fraction = 0.4
111-
val url = URL(wizardModel.loginModel.uriScheme.toString().toLowerCase(), wizardModel.loginModel.host, wizardModel.loginModel.port, "")
104+
pi.apply {
105+
text = "Downloading coder cli..."
106+
fraction = 0.4
107+
}
108+
112109
val cliManager = CoderCLIManager(URL(url.protocol, url.host, url.port, ""))
113110
val cli = cliManager.download() ?: throw IllegalStateException("Could not download coder binary")
114111
if (getOS() != OS.WINDOWS) {
115112
pi.fraction = 0.5
116113
val chmodOutput = ProcessExecutor().command("chmod", "+x", cli.toAbsolutePath().toString()).readOutput(true).execute().outputUTF8()
117114
logger.info("chmod +x ${cli.toAbsolutePath()} $chmodOutput")
118115
}
119-
pi.text = "Configuring coder cli..."
120-
pi.fraction = 0.5
116+
pi.apply {
117+
text = "Configuring coder cli..."
118+
fraction = 0.5
119+
}
120+
121121
val loginOutput = ProcessExecutor().command(cli.toAbsolutePath().toString(), "login", url.toString(), "--token", coderClient.sessionToken).readOutput(true).execute().outputUTF8()
122122
logger.info("coder-cli login output: $loginOutput")
123123
pi.fraction = 0.6

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import kotlinx.coroutines.CoroutineScope
2424
import kotlinx.coroutines.Dispatchers
2525
import kotlinx.coroutines.launch
2626
import kotlinx.coroutines.withContext
27-
import java.net.URL
2827
import java.util.logging.Logger
2928
import javax.swing.DefaultComboBoxModel
3029

@@ -95,7 +94,7 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
9594
GatewayUI.getInstance().connect(
9695
mapOf(
9796
"type" to "coder",
98-
"coder_url" to URL(wizardModel.loginModel.uriScheme.toString().toLowerCase(), wizardModel.loginModel.host, wizardModel.loginModel.port, "").toString(),
97+
"coder_url" to wizardModel.loginModel.url,
9998
"workspace_name" to workspace.name,
10099
"username" to coderClient.me.username,
101100
"password" to wizardModel.loginModel.password!!,
@@ -105,11 +104,9 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
105104
)
106105
}
107106
}
108-
109107
}
110108

111109
override fun dispose() {
112-
113110
}
114111

115112
companion object {

src/main/resources/messages/CoderGatewayBundle.properties

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ gateway.connector.action.text=Connect to Coder Workspaces
44
gateway.connector.view.login.header.text=Coder Workspaces
55
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.
66
gateway.connector.view.login.documentation.action=Explore Coder Workspaces
7-
gateway.connector.view.login.scheme.label=Scheme:
8-
gateway.connector.view.login.host.label=Host:
9-
gateway.connector.view.login.port.label=Port:
7+
gateway.connector.view.login.url.label=Url:
108
gateway.connector.view.login.email.label=Email:
119
gateway.connector.view.login.password.label=Password:
1210
gateway.connector.view.coder.auth.next.text=Connect
1311
gateway.connector.view.login.credentials.dialog.title=Coder Credentials
14-
gateway.connector.view.coder.workspaces.next.text=Next
1512
gateway.connector.view.coder.workspaces.connect.text=Download and Start IDE
1613
gateway.connector.view.coder.workspaces.choose.text=Choose a workspace

0 commit comments

Comments
 (0)