Skip to content

Commit abe0d2f

Browse files
committed
Make token optional to client
Still need UI work to not ask for the token when it is not needed, but the client and cli will now work without one.
1 parent 14fddc1 commit abe0d2f

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
146146
indicator,
147147
)
148148

149-
indicator.text = "Authenticating Coder CLI..."
150-
cli.login(client.token)
149+
// We only need to log in if we are using token-based auth.
150+
if (client.token !== null) {
151+
indicator.text = "Authenticating Coder CLI..."
152+
cli.login(client.token)
153+
}
151154

152155
indicator.text = "Configuring Coder CLI..."
153156
cli.configSsh(client.agentNames(workspaces))

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ data class ProxyValues(
5656

5757
/**
5858
* An HTTP client that can make requests to the Coder API.
59+
*
60+
* The token can be omitted if some other authentication mechanism is in use.
5961
*/
6062
open class CoderRestClient(
61-
var url: URL, var token: String,
63+
val url: URL, val token: String?,
6264
private val settings: CoderSettings = CoderSettings(CoderSettingsState()),
6365
private val proxyValues: ProxyValues? = null,
6466
private val pluginVersion: String = "development",
@@ -95,10 +97,13 @@ open class CoderRestClient(
9597
}
9698
}
9799

100+
if (token != null) {
101+
builder = builder.addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }
102+
}
103+
98104
httpClient = builder
99105
.sslSocketFactory(socketFactory, trustManagers[0] as X509TrustManager)
100106
.hostnameVerifier(CoderHostnameVerifier(settings.tls.altHostname))
101-
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }
102107
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("User-Agent", "Coder Gateway/${pluginVersion} (${getOS()}; ${getArch()})").build()) }
103108
.addInterceptor {
104109
var request = it.request()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import java.net.URL
1313
* A client instance that hooks into global JetBrains services for default
1414
* settings.
1515
*/
16-
class CoderRestClientService(url: URL, token: String, httpClient:OkHttpClient? = null) : CoderRestClient(url, token,
16+
class CoderRestClientService(url: URL, token: String?, httpClient:OkHttpClient? = null) : CoderRestClient(url, token,
1717
service<CoderSettingsService>(),
1818
ProxyValues(HttpConfigurable.getInstance().proxyLogin,
1919
HttpConfigurable.getInstance().plainProxyPassword,

src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ open class CoderSettings(
182182
return try {
183183
Files.readString(dir.resolve("url")) to Files.readString(dir.resolve("session"))
184184
} catch (e: Exception) {
185-
// SSH has not been configured yet.
185+
// SSH has not been configured yet, or using some other authorization mechanism.
186186
null to null
187187
}
188188
}

0 commit comments

Comments
 (0)