Skip to content

Commit 7233210

Browse files
committed
Make pluginVersion an constructor option
PluginManagerCore is throwing a null pointer exception when used in the tests.
1 parent eef5bb3 commit 7233210

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
140140
if (token == null) { // User aborted.
141141
throw IllegalArgumentException("Unable to connect to $deploymentURL, $TOKEN is missing")
142142
}
143-
val client = CoderRestClient(deploymentURL, token.first, settings.headerCommand)
143+
val client = CoderRestClient(deploymentURL, token.first, settings.headerCommand, null)
144144
return try {
145145
Pair(client, client.me().username)
146146
} catch (ex: AuthenticationResponseException) {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,30 @@ class CoderRestClientService {
4545
* @throws [AuthenticationResponseException] if authentication failed.
4646
*/
4747
fun initClientSession(url: URL, token: String, headerCommand: String?): User {
48-
client = CoderRestClient(url, token, headerCommand)
48+
client = CoderRestClient(url, token, headerCommand, null)
4949
me = client.me()
5050
buildVersion = client.buildInfo().version
5151
isReady = true
5252
return me
5353
}
5454
}
5555

56-
class CoderRestClient(var url: URL, var token: String, var headerCommand: String?) {
56+
class CoderRestClient(var url: URL, var token: String,
57+
private var headerCommand: String?,
58+
private var pluginVersion: String?,
59+
) {
5760
private var httpClient: OkHttpClient
5861
private var retroRestClient: CoderV2RestFacade
5962

6063
init {
6164
val gson: Gson = GsonBuilder().registerTypeAdapter(Instant::class.java, InstantConverter()).setPrettyPrinting().create()
62-
val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!! // this is the id from the plugin.xml
65+
if (pluginVersion.isNullOrBlank()) {
66+
pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version // this is the id from the plugin.xml
67+
}
6368

6469
httpClient = OkHttpClient.Builder()
6570
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }
66-
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("User-Agent", "Coder Gateway/${pluginVersion.version} (${SystemInfo.getOsNameAndVersion()}; ${SystemInfo.OS_ARCH})").build()) }
71+
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("User-Agent", "Coder Gateway/${pluginVersion} (${SystemInfo.getOsNameAndVersion()}; ${SystemInfo.OS_ARCH})").build()) }
6772
.addInterceptor {
6873
var request = it.request()
6974
val headers = getHeaders(url, headerCommand)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
256256
deployments[dir] ?: try {
257257
val url = Path.of(dir).resolve("url").readText()
258258
val token = Path.of(dir).resolve("session").readText()
259-
DeploymentInfo(CoderRestClient(url.toURL(), token, settings.headerCommand))
259+
DeploymentInfo(CoderRestClient(url.toURL(), token, settings.headerCommand, null))
260260
} catch (e: Exception) {
261261
logger.error("Unable to create client from $dir", e)
262262
DeploymentInfo(error = "Error trying to read $dir: ${e.message}")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy