Skip to content

Commit 1cdbdf7

Browse files
committed
TODO
1 parent 3a76c6b commit 1cdbdf7

12 files changed

+87
-182
lines changed

components/ide/jetbrains/toolbox/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ tasks.shadowJar {
8383
"com.jetbrains.toolbox.gateway",
8484
"com.jetbrains",
8585
"org.jetbrains",
86-
"com.squareup.okhttp3",
87-
"org.slf4j",
86+
// "com.squareup.okhttp3",
87+
// "org.slf4j",
8888
"org.jetbrains.intellij",
89-
"com.squareup.okio",
89+
// "com.squareup.okio",
9090
"kotlin."
9191
)
9292

components/ide/jetbrains/toolbox/gradle/libs.versions.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
toolbox-plugin-api = "0.2"
2+
toolbox-plugin-api = "0.4"
33
kotlin = "2.0.10"
4-
coroutines = "1.7.3"
5-
serialization = "1.5.0"
4+
coroutines = "1.9.0"
5+
serialization = "1.7.3"
66
okhttp = "4.10.0"
7-
slf4j = "2.0.3"
7+
slf4j = "2.0.9"
88
dependency-license-report = "2.5"
99
marketplace-client = "2.0.38"
1010
gradle-wrapper = "0.14.0"

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt

+17-24
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import com.jetbrains.toolbox.api.core.auth.*
1010
import io.gitpod.publicapi.experimental.v1.UserServiceClient
1111
import io.gitpod.toolbox.service.GitpodPublicApiManager
1212
import io.gitpod.toolbox.service.Utils
13-
import io.gitpod.toolbox.utils.GitpodLogger
1413
import kotlinx.coroutines.future.future
1514
import kotlinx.serialization.Serializable
16-
import kotlinx.serialization.decodeFromString
1715
import kotlinx.serialization.encodeToString
1816
import kotlinx.serialization.json.Json
1917
import kotlinx.serialization.json.jsonObject
@@ -48,22 +46,22 @@ class GitpodAuthManager {
4846
GitpodAccount::class.java,
4947
{ it.encode() },
5048
{ GitpodAccount.decode(it) },
51-
{ oauthToken, authCfg -> getAuthenticatedUser(authCfg.baseUrl, oauthToken) },
49+
{ oauthToken, authCfg -> getAuthenticatedUser(URI.create(authCfg.baseUrl).host, oauthToken) },
5250
{ oauthToken, gpAccount -> getAuthenticatedUser(gpAccount.getHost(), oauthToken) },
5351
{ gpLoginCfg ->
5452
val authParams = mapOf(
5553
"response_type" to "code",
5654
"client_id" to "toolbox-gateway-gitpod-plugin",
57-
"scope" to authScopesJetBrainsToolbox.joinToString(" "),
55+
"scope" to authScopesJetBrainsToolbox.joinToString("%20"),
5856
)
5957
val tokenParams =
6058
mapOf("grant_type" to "authorization_code", "client_id" to "toolbox-gateway-gitpod-plugin")
6159
AuthConfiguration(
6260
authParams,
6361
tokenParams,
64-
gpLoginCfg.host,
65-
gpLoginCfg.host + "/api/oauth/authorize",
66-
gpLoginCfg.host + "/api/oauth/token",
62+
gpLoginCfg.hostUrl,
63+
gpLoginCfg.hostUrl + "/api/oauth/authorize",
64+
gpLoginCfg.hostUrl + "/api/oauth/token",
6765
"code_challenge",
6866
"S256",
6967
"code_verifier",
@@ -76,13 +74,13 @@ class GitpodAuthManager {
7674
manager.addEventListener {
7775
when (it.type) {
7876
AuthEvent.Type.LOGIN -> {
79-
GitpodLogger.info(" user logged in ${it.accountId}")
77+
Utils.logger.info(" user logged in ${it.accountId}")
8078
resetCurrentAccount(it.accountId)
8179
loginListeners.forEach { it() }
8280
}
8381

8482
AuthEvent.Type.LOGOUT -> {
85-
GitpodLogger.info("user logged out ${it.accountId}")
83+
Utils.logger.info("user logged out ${it.accountId}")
8684
resetCurrentAccount(it.accountId)
8785
logoutListeners.forEach { it() }
8886
}
@@ -92,7 +90,7 @@ class GitpodAuthManager {
9290

9391
private fun resetCurrentAccount(accountId: String) {
9492
val account = manager.accountsWithStatus.find { it.account.id == accountId }?.account ?: return
95-
GitpodLogger.debug("reset settings for ${account.getHost()}")
93+
Utils.logger.debug("reset settings for ${account.getHost()}")
9694
Utils.gitpodSettings.resetSettings(account.getHost())
9795
}
9896

@@ -132,8 +130,8 @@ class GitpodAuthManager {
132130
}
133131

134132
fun getOAuthLoginUrl(gitpodHost: String): String {
135-
GitpodLogger.info("get oauth url of $gitpodHost")
136-
return manager.initiateLogin(GitpodLoginConfiguration(gitpodHost))
133+
Utils.logger.info("get oauth url of https://$gitpodHost")
134+
return manager.initiateLogin(GitpodLoginConfiguration("https://$gitpodHost"))
137135
}
138136

139137
fun tryHandle(uri: URI): Boolean {
@@ -156,7 +154,7 @@ class GitpodAuthManager {
156154
private fun getAuthenticatedUser(gitpodHost: String, oAuthToken: OAuthToken): Future<GitpodAccount> {
157155
return Utils.coroutineScope.future {
158156
val bearerToken = getBearerToken(oAuthToken)
159-
val client = GitpodPublicApiManager.createClient(URI(gitpodHost).host, bearerToken)
157+
val client = GitpodPublicApiManager.createClient(gitpodHost, bearerToken)
160158
val user = GitpodPublicApiManager.tryGetAuthenticatedUser(UserServiceClient(client))
161159
GitpodAccount(bearerToken, user.id, user.name, gitpodHost, authScopesJetBrainsToolbox)
162160
}
@@ -178,7 +176,7 @@ class GitpodAuthManager {
178176

179177
}
180178

181-
class GitpodLoginConfiguration(val host: String)
179+
class GitpodLoginConfiguration(val hostUrl: String)
182180

183181
@Serializable
184182
class GitpodAccount : Account {
@@ -192,7 +190,7 @@ class GitpodAccount : Account {
192190
this.credentials = credentials
193191
this.id = id
194192
this.name = name
195-
this.host = URI(host).host
193+
this.host = host
196194
this.scopes = scopes
197195
}
198196

@@ -207,14 +205,9 @@ class GitpodAccount : Account {
207205
}
208206

209207
suspend fun isValidate(): Boolean {
210-
// TODO(hw): Align host formatting everywhere
211-
val host = if (host.startsWith("http")) {
212-
host
213-
} else {
214-
"https://$host"
215-
}
216-
val client = GitpodPublicApiManager.createClient(URI(host).host, credentials)
217-
GitpodLogger.debug("validating account $host")
208+
val hostUrl = "https://$host"
209+
val client = GitpodPublicApiManager.createClient(URI(hostUrl).host, credentials)
210+
Utils.logger.debug("validating account $hostUrl")
218211
try {
219212
GitpodPublicApiManager.tryGetAuthenticatedUser(UserServiceClient(client))
220213
// TODO: Verify scopes
@@ -225,7 +218,7 @@ class GitpodAccount : Account {
225218
"jsonrpc2: connection is closed"
226219
))
227220
) {
228-
GitpodLogger.error("account $host is not valid")
221+
Utils.logger.error("account $hostUrl is not valid")
229222
return false
230223
}
231224
return true

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodLoginPage.kt

+27-9
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ import io.gitpod.toolbox.components.AbstractUiPage
1414
import io.gitpod.toolbox.components.GitpodIcon
1515
import io.gitpod.toolbox.components.SimpleButton
1616
import io.gitpod.toolbox.service.Utils
17+
import java.net.URI
18+
import java.net.URL
1719

1820
class GitpodLoginPage(private val authManager: GitpodAuthManager) : AbstractUiPage() {
19-
private val hostField = TextField("Host", "https://exp-migration.preview.gitpod-dev.com", null) {
20-
if (it.isBlank()) {
21-
ValidationResult.Invalid("Host should not be empty")
22-
}
23-
if (!it.startsWith("https://")) {
24-
ValidationResult.Invalid("Host should start with https://")
25-
}
26-
ValidationResult.Valid
21+
private val hostField = TextField("Host", "exp-migration.preview.gitpod-dev.com", null) {
22+
val (result) = isValidHost(it)
23+
result
2724
}
2825

2926
override fun getFields(): MutableList<UiField> {
@@ -33,7 +30,12 @@ class GitpodLoginPage(private val authManager: GitpodAuthManager) : AbstractUiPa
3330

3431
override fun getActionButtons(): List<ActionDescription> {
3532
return listOf(SimpleButton("Login") action@{
36-
val host = getFieldValue<String>(hostField) ?: return@action
33+
val hostString = getFieldValue<String>(hostField) ?: return@action
34+
val (result, host) = isValidHost(hostString)
35+
if (result != ValidationResult.Valid) {
36+
Utils.toolboxUi.showErrorInfoPopup(IllegalArgumentException(result.errorMessage ?: "Invalid host value"))
37+
return@action
38+
}
3739
val url = authManager.getOAuthLoginUrl(host)
3840
Utils.openUrl(url)
3941
})
@@ -46,4 +48,20 @@ class GitpodLoginPage(private val authManager: GitpodAuthManager) : AbstractUiPa
4648
override fun getSvgIcon(): SvgIcon {
4749
return GitpodIcon()
4850
}
51+
52+
private fun isValidHost(it: String): Pair<ValidationResult, String> {
53+
if (it.isBlank()) {
54+
return ValidationResult.Invalid("Host cannot be empty") to ""
55+
}
56+
val host = try {
57+
if (!it.startsWith("https://")) {
58+
URI.create("https://$it").host
59+
} else {
60+
URI.create(it).host
61+
}
62+
} catch (e: Exception) {
63+
return ValidationResult.Invalid("Invalid host value $e") to it
64+
}
65+
return ValidationResult.Valid to host
66+
}
4967
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteEnvironment.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import io.gitpod.toolbox.auth.GitpodAuthManager
1919
import io.gitpod.toolbox.service.ConnectParams
2020
import io.gitpod.toolbox.service.GitpodPublicApiManager
2121
import io.gitpod.toolbox.service.Utils
22-
import io.gitpod.toolbox.utils.GitpodLogger
2322
import kotlinx.coroutines.DisposableHandle
2423
import kotlinx.coroutines.Job
2524
import kotlinx.coroutines.channels.BufferOverflow
@@ -28,7 +27,6 @@ import kotlinx.coroutines.launch
2827
import java.util.concurrent.CompletableFuture
2928

3029
class GitpodRemoteEnvironment(
31-
private val authManager: GitpodAuthManager,
3230
private val connectParams: ConnectParams,
3331
private val publicApi: GitpodPublicApiManager, observablePropertiesFactory: ObservablePropertiesFactory?,
3432
) : AbstractRemoteProviderEnvironment(observablePropertiesFactory), DisposableHandle {
@@ -53,10 +51,10 @@ class GitpodRemoteEnvironment(
5351
}
5452

5553
Utils.coroutineScope.launch {
56-
GitpodLogger.debug("watching workspace ${connectParams.workspaceId}")
54+
Utils.logger.debug("watching workspace ${connectParams.workspaceId}")
5755
watchWorkspaceJob = publicApi.watchWorkspaceStatus(connectParams.workspaceId) { _, status ->
5856
lastPhase = status.phase
59-
GitpodLogger.debug("${connectParams.workspaceId} status updated: $lastPhase")
57+
Utils.logger.debug("${connectParams.workspaceId} status updated: $lastPhase")
6058
lastWSEnvState.tryEmit(WorkspaceEnvState(status.phase))
6159
Utils.coroutineScope.launch {
6260
envContentsView.updateEnvironmentMeta(status)

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt

+6-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import io.gitpod.toolbox.components.EmptyUiPageWithTitle
1717
import io.gitpod.toolbox.components.GitpodIcon
1818
import io.gitpod.toolbox.components.SimpleButton
1919
import io.gitpod.toolbox.service.*
20-
import io.gitpod.toolbox.utils.GitpodLogger
2120
import kotlinx.coroutines.launch
2221
import java.net.URI
2322
import java.util.concurrent.CompletableFuture
@@ -49,19 +48,18 @@ class GitpodRemoteProvider(
4948

5049
private suspend fun setEnvironmentVisibility(connectParams: ConnectParams) {
5150
val workspaceId = connectParams.workspaceId
52-
GitpodLogger.debug("setEnvironmentVisibility $workspaceId, $connectParams")
51+
Utils.logger.debug("setEnvironmentVisibility $workspaceId, $connectParams")
5352
val obj = environmentMap[connectParams.uniqueID]
5453
var (workspace) = obj ?: Pair(null, null)
5554
if (obj == null) {
5655
workspace = publicApi.getWorkspace(workspaceId)
5756
val env = GitpodRemoteEnvironment(
58-
authManger,
5957
connectParams,
6058
publicApi,
6159
Utils.observablePropertiesFactory
6260
)
6361
environmentMap[connectParams.uniqueID] = Pair(workspace, env)
64-
consumer.consumeEnvironments(environmentMap.values.map { it.second })
62+
consumer.consumeEnvironments(environmentMap.values.map { it.second }, false)
6563
}
6664
val joinLinkInfo = publicApi.fetchJoinLink2Info(workspaceId, workspace!!.getIDEUrl())
6765
// TODO(hw): verify if it's working
@@ -77,13 +75,12 @@ class GitpodRemoteProvider(
7775
Utils.coroutineScope.launch {
7876
val workspaces = publicApi.listWorkspaces()
7977
if (workspaces.isEmpty()) {
80-
consumer.consumeEnvironments(emptyList())
78+
consumer.consumeEnvironments(emptyList(), false)
8179
return@launch
8280
}
8381
consumer.consumeEnvironments(workspaces.map {
8482
val connectParams = it.getConnectParams()
8583
val env = environmentMap[connectParams.uniqueID]?.second ?: GitpodRemoteEnvironment(
86-
authManger,
8784
connectParams,
8885
publicApi,
8986
Utils.observablePropertiesFactory
@@ -94,14 +91,14 @@ class GitpodRemoteProvider(
9491
pendingConnectParams = null
9592
}
9693
env
97-
})
94+
}, false)
9895
}
9996
}
10097

10198
private fun startup() {
10299
val account = authManger.getCurrentAccount() ?: return
103100
publicApi.setup()
104-
GitpodLogger.info("startup with ${account.getHost()} ${account.id}")
101+
Utils.logger.info("startup with ${account.getHost()} ${account.id}")
105102
showWorkspacesList()
106103
}
107104

@@ -169,7 +166,7 @@ class GitpodRemoteProvider(
169166
}
170167
when (uri.path) {
171168
else -> {
172-
GitpodLogger.warn("Unknown request: $uri")
169+
Utils.logger.warn("Unknown request: $uri")
173170
}
174171
}
175172
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodSettings.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
package io.gitpod.toolbox.gateway
66

77
import io.gitpod.toolbox.service.Utils
8-
import io.gitpod.toolbox.utils.GitpodLogger
98

109
class GitpodSettings {
1110
private val settingsChangedListeners: MutableList<(String, String) -> Unit> = mutableListOf()
1211

1312
private fun getStoreKey(key: SettingKey) = "GITPOD_SETTINGS:${key.name}"
1413

1514
private fun updateSetting(key: SettingKey, value: String) {
16-
GitpodLogger.debug("updateSetting ${key.name}=$value")
15+
Utils.logger.debug("updateSetting ${key.name}=$value")
1716
Utils.settingStore[getStoreKey(key)] = value
1817
settingsChangedListeners.forEach { it(key.name, value) }
1918
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodUriHandler.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package io.gitpod.toolbox.gateway
66

77
import io.gitpod.toolbox.service.ConnectParams
8-
import io.gitpod.toolbox.utils.GitpodLogger
8+
import io.gitpod.toolbox.service.Utils
99
import java.net.URI
1010
import java.util.concurrent.Future
1111

@@ -24,7 +24,7 @@ abstract class AbstractUriHandler<T> : UriHandler<T> {
2424
handle(data)
2525
true
2626
} catch (e: Exception) {
27-
GitpodLogger.warn(e, "cannot parse URI")
27+
Utils.logger.warn(e, "cannot parse URI")
2828
false
2929
}
3030
}
@@ -51,12 +51,11 @@ class GitpodOpenInToolboxUriHandler(val handler: (Pair<String, ConnectParams>) -
5151
}
5252

5353
try {
54-
URI.create(host)
54+
URI.create("https://$host")
5555
} catch (e: IllegalArgumentException) {
5656
throw IllegalArgumentException("invalid host: $host")
5757
}
58-
GitpodLogger.debug("parsed URI: $host, $workspaceId, $debugWorkspace")
59-
val gitpodHost = "https://$host"
60-
return Pair(gitpodHost, ConnectParams(workspaceId, gitpodHost, debugWorkspace))
58+
Utils.logger.debug("parsed URI: $host, $workspaceId, $debugWorkspace")
59+
return Pair(host, ConnectParams(workspaceId, host, debugWorkspace))
6160
}
6261
}

0 commit comments

Comments
 (0)