Skip to content

Commit

Permalink
Proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Jun 7, 2024
1 parent aba9b71 commit 1f409c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ class GitpodSSHEnvironmentContentsView(
private val logger = LoggerFactory.getLogger(javaClass)

override fun getConnectionInfo(): CompletableFuture<SshConnectionInfo> {
// 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
}
}
Expand All @@ -47,7 +43,6 @@ class GitpodSSHEnvironmentContentsView(
}

override fun close() {
logger.info("==================close $workspaceId")
cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,14 +55,8 @@ class GitpodConnectionProvider(
}

val workspaceHost = URI.create(workspace.status.workspaceUrl).host

// TODO: Check if proxy works
val proxyList = mutableListOf<Proxy>()
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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import javax.websocket.MessageHandler.Partial
class GitpodWebSocketTunnelServer(
private val url: String,
private val ownerToken: String,
private val proxies: List<Proxy>,
) {
private val serverSocket = ServerSocket(0) // pass 0 to have the system choose a free port
private val logger = LoggerFactory.getLogger(javaClass)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -40,12 +43,21 @@ 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()
}

fun openUrl(url: String) {
toolboxUi.openUrl(url)
}

fun getProxyList(): List<Proxy> {
val proxyList = mutableListOf<Proxy>()
if (proxySettings.proxy != null && proxySettings.proxy != Proxy.NO_PROXY) {
proxyList.add(proxySettings.proxy!!)
}
return proxyList
}

private val isInitialized = AtomicBoolean(false)
}

0 comments on commit 1f409c1

Please sign in to comment.