From 3dd00573d494ce6b6075f9cd1c5389f4eefd908b Mon Sep 17 00:00:00 2001 From: hwen Date: Tue, 23 Apr 2024 17:14:15 +0800 Subject: [PATCH] Proxy settings --- .../gateway/GitpodSSHEnvironmentContentsView.kt | 5 ----- .../toolbox/service/GitpodConnectionProvider.kt | 9 +-------- .../toolbox/service/GitpodWebSocketTunnelServer.kt | 2 +- .../main/kotlin/io/gitpod/toolbox/service/Utils.kt | 12 ++++++++++++ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodSSHEnvironmentContentsView.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodSSHEnvironmentContentsView.kt index 1d8d028073f6b3..daa087ce41a485 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodSSHEnvironmentContentsView.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodSSHEnvironmentContentsView.kt @@ -26,14 +26,10 @@ class GitpodSSHEnvironmentContentsView( private val logger = LoggerFactory.getLogger(javaClass) override fun getConnectionInfo(): CompletableFuture { -// stateListeners.forEach { -// } return Utils.coroutineScope.future { val provider = GitpodConnectionProvider(authManager, workspaceId, publicApi) - logger.info("==================connect $workspaceId") val (connInfo, cancel) = provider.connect() this@GitpodSSHEnvironmentContentsView.cancel = cancel - logger.info("==================connect info $connInfo") return@future connInfo } } @@ -47,7 +43,6 @@ class GitpodSSHEnvironmentContentsView( } override fun close() { - logger.info("==================close $workspaceId") cancel() } } diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodConnectionProvider.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodConnectionProvider.kt index 1df1291cc18b22..ea981091b8920f 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodConnectionProvider.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodConnectionProvider.kt @@ -10,7 +10,6 @@ import com.jetbrains.toolbox.gateway.ssh.SshConnectionInfo import io.gitpod.publicapi.v1.WorkspaceOuterClass import io.gitpod.toolbox.auth.GitpodAuthManager import kotlinx.serialization.Serializable -import java.net.Proxy class GitpodConnectionProvider( private val authManager: GitpodAuthManager, @@ -56,14 +55,8 @@ class GitpodConnectionProvider( } val workspaceHost = URI.create(workspace.status.workspaceUrl).host - - // TODO: Check if proxy works - val proxyList = mutableListOf() - if (Utils.httpClient.proxy != null && Utils.httpClient.proxy != Proxy.NO_PROXY) { - proxyList.add(Utils.httpClient.proxy!!) - } val server = - GitpodWebSocketTunnelServer("wss://${workspaceHost}/_supervisor/tunnel/ssh", ownerToken, proxyList) + GitpodWebSocketTunnelServer("wss://${workspaceHost}/_supervisor/tunnel/ssh", ownerToken) val cancelServer = server.start() diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodWebSocketTunnelServer.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodWebSocketTunnelServer.kt index 9c5b03fb7790f5..571c47d89f61c6 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodWebSocketTunnelServer.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodWebSocketTunnelServer.kt @@ -25,7 +25,6 @@ import javax.websocket.MessageHandler.Partial class GitpodWebSocketTunnelServer( private val url: String, private val ownerToken: String, - private val proxies: List, ) { private val serverSocket = ServerSocket(0) // pass 0 to have the system choose a free port private val logger = LoggerFactory.getLogger(javaClass) @@ -107,6 +106,7 @@ class GitpodWebSocketTunnelServer( val ssl: SslContextFactory = SslContextFactory.Client() ssl.sslContext = SSLContext.getDefault() val httpClient = HttpClient(ssl) + val proxies = Utils.getProxyList() for (proxy in proxies) { if (proxy.type() == Proxy.Type.DIRECT) { continue diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/Utils.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/Utils.kt index 8eb2315e36a23c..02073623307fd2 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/Utils.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/Utils.kt @@ -7,11 +7,13 @@ package io.gitpod.toolbox.service import com.jetbrains.toolbox.gateway.PluginSettingsStore import com.jetbrains.toolbox.gateway.ToolboxServiceLocator import com.jetbrains.toolbox.gateway.connection.ClientHelper +import com.jetbrains.toolbox.gateway.connection.ToolboxProxySettings import com.jetbrains.toolbox.gateway.ssh.validation.SshConnectionValidator import com.jetbrains.toolbox.gateway.ui.ObservablePropertiesFactory import com.jetbrains.toolbox.gateway.ui.ToolboxUi import kotlinx.coroutines.CoroutineScope import okhttp3.OkHttpClient +import java.net.Proxy import java.util.concurrent.atomic.AtomicBoolean object Utils { @@ -22,6 +24,7 @@ object Utils { lateinit var httpClient: OkHttpClient private set lateinit var clientHelper: ClientHelper private set lateinit var observablePropertiesFactory: ObservablePropertiesFactory private set + lateinit var proxySettings: ToolboxProxySettings private set lateinit var dataManager: DataManager private set @@ -40,6 +43,7 @@ object Utils { httpClient = serviceLocator.getService(OkHttpClient::class.java) clientHelper = serviceLocator.getService(ClientHelper::class.java) observablePropertiesFactory = serviceLocator.getService(ObservablePropertiesFactory::class.java) + proxySettings = serviceLocator.getService(ToolboxProxySettings::class.java) dataManager = DataManager() } @@ -47,5 +51,13 @@ object Utils { toolboxUi.openUrl(url) } + fun getProxyList(): List { + val proxyList = mutableListOf() + if (proxySettings.proxy != null && proxySettings.proxy != Proxy.NO_PROXY) { + proxyList.add(proxySettings.proxy!!) + } + return proxyList + } + private val isInitialized = AtomicBoolean(false) } \ No newline at end of file