Skip to content

Release/2022.06.1 - NOT TO BE MERGED #11411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ flags:
dev-loadgen-app:
paths:
- dev/loadgen/
dev-poolkeeper-app:
paths:
- dev/poolkeeper/
dev-version-manifest-app:
paths:
- dev/version-manifest/
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@

package io.gitpod.gitpodprotocol.api;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpProxy;
import org.eclipse.jetty.client.Socks4Proxy;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.jsr356.ClientContainer;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.MessageIssueHandler;
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler;
import org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints;
import org.eclipse.lsp4j.websocket.WebSocketMessageHandler;

import javax.net.ssl.SSLContext;
import javax.websocket.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
Expand Down Expand Up @@ -46,11 +54,48 @@ public GitpodServerConnection listen(
String origin,
String userAgent,
String clientVersion,
String token
) throws DeploymentException, IOException {
String token,
List<Proxy> proxies,
SSLContext sslContext
) throws Exception {
String gitpodHost = URI.create(apiUrl).getHost();
SslContextFactory ssl = new SslContextFactory.Client();
if (sslContext != null) {
ssl.setSslContext(sslContext);
}
HttpClient httpClient = new HttpClient(ssl);
for (Proxy proxy : proxies) {
if (proxy.type().equals(Proxy.Type.DIRECT)) {
continue;
}
SocketAddress proxyAddress = proxy.address();
if (!(proxyAddress instanceof InetSocketAddress)) {
GitpodServerConnectionImpl.LOG.log(Level.WARNING, gitpodHost + ": unexpected proxy:", proxy);
continue;
}
String hostName = ((InetSocketAddress) proxyAddress).getHostString();
int port = ((InetSocketAddress) proxyAddress).getPort();
if (proxy.type().equals(Proxy.Type.HTTP)) {
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(hostName, port));
} else if (proxy.type().equals(Proxy.Type.SOCKS)) {
httpClient.getProxyConfiguration().getProxies().add(new Socks4Proxy(hostName, port));
}
}
ClientContainer container = new ClientContainer(httpClient);
// allow clientContainer to own httpClient (for start/stop lifecycle)
container.getClient().addManaged(httpClient);
container.start();

GitpodServerConnectionImpl connection = new GitpodServerConnectionImpl(gitpodHost);
connection.setSession(ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() {
connection.whenComplete((input, exception) -> {
try {
container.stop();
} catch (Throwable t) {
GitpodServerConnectionImpl.LOG.log(Level.WARNING, gitpodHost + ": failed to stop websocket container:", t);
}
});

connection.setSession(container.connectToServer(new Endpoint() {
@Override
public void onOpen(Session session, EndpointConfig config) {
session.addMessageHandler(new WebSocketMessageHandler(messageReader, jsonHandler, remoteEndpoint));
Expand All @@ -71,10 +116,10 @@ public void onError(Session session, Throwable thr) {
}, ClientEndpointConfig.Builder.create().configurator(new ClientEndpointConfig.Configurator() {
@Override
public void beforeRequest(final Map<String, List<String>> headers) {
headers.put("Origin", Arrays.asList(origin));
headers.put("Authorization", Arrays.asList("Bearer " + token));
headers.put("User-Agent", Arrays.asList(userAgent));
headers.put("X-Client-Version", Arrays.asList(clientVersion));
headers.put("Origin", Collections.singletonList(origin));
headers.put("Authorization", Collections.singletonList("Bearer " + token));
headers.put("User-Agent", Collections.singletonList(userAgent));
headers.put("X-Client-Version", Collections.singletonList(clientVersion));
}
}).build(), URI.create(apiUrl)));
return connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
import io.gitpod.gitpodprotocol.api.entities.SendHeartBeatOptions;
import io.gitpod.gitpodprotocol.api.entities.User;

import java.util.Collections;

public class TestClient {
public static void main(String[] args) throws Exception {
String uri = "wss://gitpod.io/api/v1";
String token = "CHANGE-ME";
String origin = "https://CHANGE-ME.gitpod.io/";

GitpodClient client = new GitpodClient();
GitpodServerLauncher.create(client).listen(uri, origin, token, "Test", "Test");
GitpodServerLauncher.create(client).listen(uri, origin, token, "Test", "Test", Collections.emptyList(), null);
GitpodServer gitpodServer = client.getServer();
User user = gitpodServer.getLoggedInUser().join();
System.out.println("logged in user:" + user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.util.LowMemoryWatcher
import com.intellij.remoteDev.util.onTerminationOrNow
import com.intellij.util.application
import com.intellij.util.net.ssl.CertificateManager
import com.intellij.util.proxy.CommonProxy
import com.jetbrains.rd.util.lifetime.Lifetime
import git4idea.config.GitVcsApplicationSettings
import io.gitpod.gitpodprotocol.api.GitpodClient
Expand All @@ -40,6 +42,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.jetbrains.ide.BuiltInServerManager
import java.net.URI
import java.net.URL
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
Expand Down Expand Up @@ -269,14 +272,20 @@ class GitpodManager : Disposable {
val connect = {
val originalClassLoader = Thread.currentThread().contextClassLoader
try {
val proxies = CommonProxy.getInstance().select(URL(info.gitpodHost))
val sslContext = CertificateManager.getInstance().sslContext

// see https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003146180/comments/360000376240
Thread.currentThread().contextClassLoader = HeartbeatService::class.java.classLoader

launcher.listen(
info.gitpodApi.endpoint,
info.gitpodHost,
plugin.pluginId.idString,
plugin.version,
tokenResponse.token
tokenResponse.token,
proxies,
sslContext
)
} finally {
Thread.currentThread().contextClassLoader = originalClassLoader
Expand Down
7 changes: 1 addition & 6 deletions components/ide/jetbrains/gateway-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
// Kotlin support - check the latest version at https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm
id("org.jetbrains.kotlin.jvm") version "1.7.0"
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.6.0"
id("org.jetbrains.intellij") version "1.7.0"
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "1.1.2"
// detekt linter - read more: https://detekt.github.io/detekt/gradle.html
Expand Down Expand Up @@ -137,11 +137,6 @@ tasks {
channels.set(listOf(pluginChannel))
}

// TODO: Remove the following three lines to reenable 'buildSearchableOptions' task if it's working fine next time we update 'platformVersion' on 'gradle.properties'.
buildSearchableOptions {
isEnabled = false
}

register("buildFromLeeway") {
if ("true" == System.getenv("DO_PUBLISH")) {
dependsOn("publishPlugin")
Expand Down
4 changes: 2 additions & 2 deletions components/ide/jetbrains/gateway-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ pluginName=gitpod-gateway
pluginVersion=0.0.1
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=222.3048.1
pluginSinceBuild=222.3345.1
pluginUntilBuild=222.*
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions=2022.1, 2022.2
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type
platformType=GW
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
platformVersion=222-NIGHTLY-CUSTOM-SNAPSHOT
platformVersion=222.3345.1-CUSTOM-SNAPSHOT
platformDownloadSources=true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ internal class GitpodAuthCallbackHandler : RestService() {
</html>
""".trimIndent()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import java.util.*
import java.util.concurrent.CompletableFuture
import kotlin.math.absoluteValue


@Service
internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
override val name: String
Expand Down Expand Up @@ -66,7 +65,7 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
constructor(gitpodHost: String) {
val codeVerifier = generateCodeVerifier()
val codeChallenge = generateCodeChallenge(codeVerifier)
val serviceUrl = newFromEncoded("https://${gitpodHost}/api/oauth")
val serviceUrl = newFromEncoded("https://$gitpodHost/api/oauth")
credentialsAcquirer = GitpodAuthCredentialsAcquirer(
serviceUrl.resolve("token"), mapOf(
"grant_type" to "authorization_code",
Expand Down Expand Up @@ -94,7 +93,7 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
val bytes = ByteArray(size)
secureRandom.nextBytes(bytes)

val mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
val mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"
val scale = 256 / mask.length
val builder = StringBuilder()
for (i in 0 until size) {
Expand Down Expand Up @@ -147,7 +146,6 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {

private data class AuthorizationResponseData(val accessToken: String)
private data class JsonWebToken(val jti: String)

}

companion object {
Expand Down Expand Up @@ -198,8 +196,8 @@ internal class GitpodAuthService : OAuthServiceBase<Credentials>() {
listener()
}
}
dispatcher.addListener(internalListener);
dispatcher.addListener(internalListener)
return Disposable { dispatcher.removeListener(internalListener) }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

class GatewayGitpodClient(
private val lifetimeDefinition: LifetimeDefinition, private val gitpodHost: String
private val lifetimeDefinition: LifetimeDefinition,
private val gitpodHost: String
) : GitpodClient() {

private val mutex = Mutex()

private val listeners = concurrentMapOf<String, CopyOnWriteArrayList<Channel<WorkspaceInstance>>?>()

private val timeoutDelayInMinutes = 15
private var timeoutJob: Job? = null;
private var timeoutJob: Job? = null

init {
GlobalScope.launch {
Expand Down Expand Up @@ -59,7 +60,7 @@ class GatewayGitpodClient(
}
}

private var syncJob: Job? = null;
private var syncJob: Job? = null
override fun notifyConnect() {
syncJob?.cancel()
syncJob = GlobalScope.launch {
Expand All @@ -69,17 +70,17 @@ class GatewayGitpodClient(
continue
}
try {
syncWorkspace(id);
syncWorkspace(id)
} catch (t: Throwable) {
thisLogger().error("${gitpodHost}: ${id}: failed to sync", t)
thisLogger().error("$gitpodHost: $id: failed to sync", t)
}
}
}
}

override fun onInstanceUpdate(instance: WorkspaceInstance?) {
if (instance == null) {
return;
return
}
GlobalScope.launch {
val wsListeners = listeners[instance.workspaceId] ?: return@launch
Expand All @@ -102,7 +103,7 @@ class GatewayGitpodClient(
val listener = Channel<WorkspaceInstance>()
mutex.withLock {
val listeners = this.listeners.getOrPut(workspaceId) { CopyOnWriteArrayList() }!!
listeners.add(listener);
listeners.add(listener)
cancelTimeout("listening to workspace: $workspaceId")
}
listenerLifetime.onTerminationOrNow {
Expand All @@ -120,7 +121,7 @@ class GatewayGitpodClient(
if (listeners.isNullOrEmpty()) {
return
}
listeners.remove(listener);
listeners.remove(listener)
if (listeners.isNotEmpty()) {
return
}
Expand All @@ -137,5 +138,4 @@ class GatewayGitpodClient(
onInstanceUpdate(info.latestInstance)
return info
}

}
}
Loading