Skip to content

Commit 4768e50

Browse files
committed
💄
1 parent 1f8e9e2 commit 4768e50

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

src/common/telemetry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export interface TelemetryOptions {
1515
workspaceId?: string;
1616
instanceId?: string;
1717

18-
userId?: string
18+
userId?: string;
1919

20-
[prop: string]: any
20+
[prop: string]: any;
2121
}
2222

2323
export interface UserFlowTelemetry extends TelemetryOptions {
24-
flow: string
24+
flow: string;
2525
}
2626

2727
const enum TelemetryLevel {

src/experiments.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ export class ExperimentalSettings {
3737
key: string,
3838
userId: string,
3939
custom: {
40-
gitpodHost: string
41-
[key: string]: string
40+
gitpodHost: string;
41+
[key: string]: string;
4242
},
43-
// '.' are not allowed in configcat
44-
configcatKey: string = key.replace(/\./g, '_')
43+
configcatKey?: string
4544
): Promise<T | undefined> {
4645
const config = vscode.workspace.getConfiguration('gitpod');
4746
const values = config.inspect<T>(key.substring('gitpod.'.length));
@@ -59,6 +58,7 @@ export class ExperimentalSettings {
5958
}
6059

6160
const user = userId ? new configcatcommon.User(userId, undefined, undefined, custom) : undefined;
61+
configcatKey = configcatKey ?? key.replace(/\./g, '_'); // '.' are not allowed in configcat
6262
const experimentValue = (await this.configcatClient.getValueAsync(configcatKey, undefined, user)) as T | undefined;
6363

6464
return experimentValue ?? values.defaultValue;
@@ -68,11 +68,10 @@ export class ExperimentalSettings {
6868
key: string,
6969
userId: string,
7070
custom: {
71-
gitpodHost: string
72-
[key: string]: string
71+
gitpodHost: string;
72+
[key: string]: string;
7373
},
74-
// '.' are not allowed in configcat
75-
configcatKey: string = key.replace(/\./g, '_')
74+
configcatKey?: string
7675
): Promise<{ key: string; defaultValue?: T; globalValue?: T; experimentValue?: T } | undefined> {
7776
const config = vscode.workspace.getConfiguration('gitpod');
7877
const values = config.inspect<T>(key.substring('gitpod.'.length));
@@ -82,6 +81,7 @@ export class ExperimentalSettings {
8281
}
8382

8483
const user = userId ? new configcatcommon.User(userId, undefined, undefined, custom) : undefined;
84+
configcatKey = configcatKey ?? key.replace(/\./g, '_'); // '.' are not allowed in configcat
8585
const experimentValue = (await this.configcatClient.getValueAsync(configcatKey, undefined, user)) as T | undefined;
8686

8787
return { key, defaultValue: values.defaultValue, globalValue: values.globalValue, experimentValue };

src/remoteConnector.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export default class RemoteConnector extends Disposable {
448448

449449
// From https://github.com/openssh/openssh-portable/blob/acb2059febaddd71ee06c2ebf63dcf211d9ab9f2/sshconnect2.c#L1689-L1690
450450
private async getIdentityKeys(hostConfig: Record<string, string>) {
451-
const identityFiles: string[] = ((hostConfig['IdentityFile'] as unknown as string[]) || []).map(untildify);
451+
const identityFiles: string[] = ((hostConfig['IdentityFile'] as unknown as string[]) || []).map(untildify).map(i => i.replace(/\.pub$/, ''));
452452
if (identityFiles.length === 0) {
453453
identityFiles.push(...DEFAULT_IDENTITY_FILES);
454454
}
@@ -736,21 +736,25 @@ export default class RemoteConnector extends Disposable {
736736
throw new Error('SSH password modal dialog, Canceled');
737737
}
738738

739-
private async getGitpodSession(gitpodHost: string, flow: UserFlowTelemetry) {
739+
private async ensureValidGitpodHost(gitpodHost: string, flow: UserFlowTelemetry): Promise<boolean>{
740740
const config = vscode.workspace.getConfiguration('gitpod');
741741
const currentGitpodHost = config.get<string>('host')!;
742742
if (new URL(gitpodHost).host !== new URL(currentGitpodHost).host) {
743743
const yes = 'Yes';
744744
const cancel = 'Cancel';
745745
const action = await this.notifications.showInformationMessage(`Connecting to a Gitpod workspace in '${gitpodHost}'. Would you like to switch from '${currentGitpodHost}' and continue?`, { id: 'switch_gitpod_host', flow }, yes, cancel);
746746
if (action === cancel) {
747-
return;
747+
return false;
748748
}
749749

750750
await config.update('host', gitpodHost, vscode.ConfigurationTarget.Global);
751751
this.logger.info(`Updated 'gitpod.host' setting to '${gitpodHost}' while trying to connect to a Gitpod workspace`);
752752
}
753753

754+
return true;
755+
}
756+
757+
private async getGitpodSession(gitpodHost: string) {
754758
const gitpodVersion = await getGitpodVersion(gitpodHost, this.logger);
755759
const sessionScopes = ['function:getWorkspace', 'function:getOwnerToken', 'function:getLoggedInUser', 'resource:default'];
756760
if (await isOauthInspectSupported(gitpodHost) || isFeatureSupported(gitpodVersion, 'SSHPublicKeys') /* && isFeatureSupported('', 'sendHeartBeat') */) {
@@ -780,7 +784,12 @@ export default class RemoteConnector extends Disposable {
780784
return;
781785
}
782786

783-
const session = await this.getGitpodSession(params.gitpodHost, sshFlow);
787+
const isGitpodHostValid = await this.ensureValidGitpodHost(params.gitpodHost, sshFlow);
788+
if (!isGitpodHostValid) {
789+
return;
790+
}
791+
792+
const session = await this.getGitpodSession(params.gitpodHost);
784793
if (!session) {
785794
return;
786795
}
@@ -790,7 +799,7 @@ export default class RemoteConnector extends Disposable {
790799

791800
const forceUseLocalApp = getServiceURL(params.gitpodHost) === 'https://gitpod.io'
792801
? (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', session.account.id, { gitpodHost: params.gitpodHost }))!
793-
: (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', session.account.id, { gitpodHost: params.gitpodHost }, 'gitpod_remote_useLocalApp_sh'))!
802+
: (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', session.account.id, { gitpodHost: params.gitpodHost }, 'gitpod_remote_useLocalApp_sh'))!;
794803
const userOverride = String(isUserOverrideSetting('gitpod.remote.useLocalApp'));
795804
let sshDestination: string | undefined;
796805
if (!forceUseLocalApp) {
@@ -892,14 +901,19 @@ export default class RemoteConnector extends Disposable {
892901
}
893902

894903
public async autoTunnelCommand(gitpodHost: string, instanceId: string, enabled: boolean) {
895-
const forceUseLocalApp = vscode.workspace.getConfiguration('gitpod').get<boolean>('remote.useLocalApp')!;
896-
if (!forceUseLocalApp) {
897-
const authority = vscode.Uri.parse(gitpodHost).authority;
898-
const configKey = `config/${authority}`;
899-
const localAppconfig = this.context.globalState.get<LocalAppConfig>(configKey);
900-
if (!localAppconfig || checkRunning(localAppconfig.pid) !== true) {
901-
// Do nothing if we are using SSH gateway and local app is not running
902-
return;
904+
const session = await this.getGitpodSession(gitpodHost);
905+
if (session) {
906+
const forceUseLocalApp = getServiceURL(gitpodHost) === 'https://gitpod.io'
907+
? (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', session.account.id, { gitpodHost }))!
908+
: (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', session.account.id, { gitpodHost }, 'gitpod_remote_useLocalApp_sh'))!;
909+
if (!forceUseLocalApp) {
910+
const authority = vscode.Uri.parse(gitpodHost).authority;
911+
const configKey = `config/${authority}`;
912+
const localAppconfig = this.context.globalState.get<LocalAppConfig>(configKey);
913+
if (!localAppconfig || checkRunning(localAppconfig.pid) !== true) {
914+
// Do nothing if we are using SSH gateway and local app is not running
915+
return;
916+
}
903917
}
904918
}
905919

@@ -944,7 +958,7 @@ export default class RemoteConnector extends Disposable {
944958
} catch (e) {
945959
if (e instanceof NoSyncStoreError) {
946960
const addSyncProvider = 'Settings Sync: Enable Sign In with Gitpod';
947-
const action = await this.notifications.showInformationMessage(`Could not install local extensions on remote workspace. Please enable [Settings Sync](https://www.gitpod.io/docs/ides-and-editors/settings-sync#enabling-settings-sync-in-vs-code-desktop) with Gitpod.`, { flow, id: 'no_sync_store' }, addSyncProvider);
961+
const action = await this.notifications.showInformationMessage(`Could not install local extensions on remote workspace. Please enable [Settings Sync](https://www.gitpod.io/docs/ides-and-editors/settings-sync#enabling-settings-sync-in-vs-code-desktop) with Gitpod.`, { flow, id: 'no_sync_store' }, addSyncProvider);
948962
if (action === addSyncProvider) {
949963
vscode.commands.executeCommand('gitpod.syncProvider.add');
950964
}
@@ -1025,13 +1039,11 @@ export default class RemoteConnector extends Disposable {
10251039
if (!connectionInfo) {
10261040
return;
10271041
}
1028-
const gitpodVersion = await getGitpodVersion(connectionInfo.gitpodHost, this.logger);
1029-
const initRemoteFlow: UserFlowTelemetry = { ...connectionInfo, gitpodVersion: gitpodVersion.raw, flow: 'init_remote' };
1030-
const session = await this.getGitpodSession(connectionInfo.gitpodHost, initRemoteFlow);
1042+
1043+
const session = await this.getGitpodSession(connectionInfo.gitpodHost);
10311044
if (!session) {
10321045
return;
10331046
}
1034-
initRemoteFlow.userId = session.account.id;
10351047

10361048
const workspaceInfo = await withServerApi(session.accessToken, connectionInfo.gitpodHost, service => service.server.getWorkspace(connectionInfo.workspaceId), this.logger);
10371049
if (workspaceInfo.latestInstance?.status?.phase !== 'running') {
@@ -1045,18 +1057,18 @@ export default class RemoteConnector extends Disposable {
10451057

10461058
await this.context.globalState.update(`${RemoteConnector.SSH_DEST_KEY}${sshDestStr}`, { ...connectionInfo, isFirstConnection: false });
10471059

1060+
const gitpodVersion = await getGitpodVersion(connectionInfo.gitpodHost, this.logger);
1061+
10481062
const heartbeatSupported = session.scopes.includes(ScopeFeature.LocalHeartbeat);
10491063
if (heartbeatSupported) {
10501064
this.startHeartBeat(session.accessToken, connectionInfo, gitpodVersion);
10511065
} else {
10521066
this.logger.warn(`Local heartbeat not supported in ${connectionInfo.gitpodHost}, using version ${gitpodVersion.raw}`);
10531067
}
10541068

1055-
const syncExtensions = (await this.experiments.get<boolean>('gitpod.remote.syncExtensions', session.account.id, {
1056-
gitpodHost: connectionInfo.gitpodHost
1057-
}))!;
1069+
const syncExtensions = (await this.experiments.get<boolean>('gitpod.remote.syncExtensions', session.account.id, { gitpodHost: connectionInfo.gitpodHost }))!;
10581070
const userOverride = String(isUserOverrideSetting('gitpod.remote.syncExtensions'));
1059-
const syncExtFlow = { ...initRemoteFlow, flow: 'sync_local_extensions', userOverride };
1071+
const syncExtFlow = { ...connectionInfo, gitpodVersion: gitpodVersion.raw, userId: session.account.id, flow: 'sync_local_extensions', userOverride };
10601072
this.telemetry.sendUserFlowStatus(syncExtensions ? 'enabled' : 'disabled', syncExtFlow);
10611073
if (syncExtensions) {
10621074
this.initializeRemoteExtensions(syncExtFlow);

0 commit comments

Comments
 (0)