Skip to content

Commit adbfebf

Browse files
committed
Persist sessions per gitpod host
1 parent b5fa034 commit adbfebf

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

extensions/gitpod/src/authentication.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ export default class GitpodAuthenticationProvider extends Disposable implements
3636

3737
this._logger = logger;
3838
this._telemetry = telemetry;
39-
this._keychain = new Keychain(this.context, `gitpod.auth`, this._logger);
4039

41-
const serviceUrl = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
42-
this._gitpodServer = new GitpodServer(serviceUrl, this._logger);
43-
this._register(vscode.workspace.onDidChangeConfiguration(async e => {
40+
const gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
41+
const serviceUrl = new URL(gitpodHost);
42+
this._gitpodServer = new GitpodServer(serviceUrl.toString(), this._logger);
43+
this._keychain = new Keychain(this.context, `gitpod.auth.${serviceUrl.hostname}`, this._logger);
44+
this._register(vscode.workspace.onDidChangeConfiguration(e => {
4445
if (e.affectsConfiguration('gitpod.host')) {
45-
const serviceUrl = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
46+
const gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
47+
const serviceUrl = new URL(gitpodHost);
4648
this._gitpodServer.dispose();
47-
this._gitpodServer = new GitpodServer(serviceUrl, this._logger);
49+
this._gitpodServer = new GitpodServer(serviceUrl.toString(), this._logger);
50+
this._keychain = new Keychain(this.context, `gitpod.auth.${serviceUrl.hostname}`, this._logger);
4851

49-
// Remove all sessions when gitpod.host changes
50-
const sessions = await this._sessionsPromise;
51-
await this._keychain.deleteToken();
52-
this._sessionChangeEmitter.fire({ added: [], removed: sessions, changed: [] });
52+
this.checkForUpdates();
5353
}
5454
}));
5555

extensions/gitpod/src/extension.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ export async function activate(context: vscode.ExtensionContext) {
2525

2626
/* Gitpod settings sync */
2727
await updateSyncContext();
28-
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
28+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => {
2929
if (e.affectsConfiguration('gitpod.host') || e.affectsConfiguration('configurationSync.store')) {
30-
updateSyncContext();
30+
const addedSyncProvider = await updateSyncContext();
31+
if (!addedSyncProvider) {
32+
const action = 'Settings Sync: Enable signing in with Gitpod';
33+
const result = await vscode.window.showInformationMessage('Gitpod Settings Sync configuration invalidated, Settings Sync is disabled.', action);
34+
if (result === action) {
35+
vscode.commands.executeCommand('gitpod.syncProvider.add');
36+
}
37+
}
3138
}
3239
}));
3340

extensions/gitpod/src/gitpodServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class GitpodServer extends Disposable {
4040
constructor(serviceUrl: string, private readonly _logger: Log) {
4141
super();
4242

43-
this._serviceUrl = new URL(serviceUrl).toString().replace(/\/$/, '');
43+
this._serviceUrl = serviceUrl.replace(/\/$/, '');
4444
}
4545

4646
public async login(scopes: string): Promise<string> {

extensions/gitpod/src/settingsSync.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ function getGitpodSyncProviderConfig(serviceUrl: string): ConfigurationSyncStore
3636
/**
3737
* Updates the VS Code context to reflect whether the user added Gitpod as their Settings Sync provider.
3838
*/
39-
export async function updateSyncContext() {
39+
export async function updateSyncContext(): Promise<boolean> {
4040
const config = vscode.workspace.getConfiguration();
4141
const syncProviderConfig = config.get('configurationSync.store');
4242
const serviceUrl = config.get<string>('gitpod.host')!;
4343
const gitpodSyncProviderConfig = getGitpodSyncProviderConfig(serviceUrl);
44-
const addedSyncProvider = syncProviderConfig && JSON.stringify(syncProviderConfig) === JSON.stringify(gitpodSyncProviderConfig);
45-
await vscode.commands.executeCommand('setContext', 'gitpod.addedSyncProvider', !!addedSyncProvider);
44+
const addedSyncProvider = !!syncProviderConfig && JSON.stringify(syncProviderConfig) === JSON.stringify(gitpodSyncProviderConfig);
45+
await vscode.commands.executeCommand('setContext', 'gitpod.addedSyncProvider', addedSyncProvider);
46+
return addedSyncProvider;
4647
}
4748

4849
/**

0 commit comments

Comments
 (0)