Skip to content

Commit

Permalink
Persist sessions per gitpod host
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Apr 27, 2022
1 parent b5fa034 commit adbfebf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
20 changes: 10 additions & 10 deletions extensions/gitpod/src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ export default class GitpodAuthenticationProvider extends Disposable implements

this._logger = logger;
this._telemetry = telemetry;
this._keychain = new Keychain(this.context, `gitpod.auth`, this._logger);

const serviceUrl = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
this._gitpodServer = new GitpodServer(serviceUrl, this._logger);
this._register(vscode.workspace.onDidChangeConfiguration(async e => {
const gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
const serviceUrl = new URL(gitpodHost);
this._gitpodServer = new GitpodServer(serviceUrl.toString(), this._logger);
this._keychain = new Keychain(this.context, `gitpod.auth.${serviceUrl.hostname}`, this._logger);
this._register(vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('gitpod.host')) {
const serviceUrl = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
const gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
const serviceUrl = new URL(gitpodHost);
this._gitpodServer.dispose();
this._gitpodServer = new GitpodServer(serviceUrl, this._logger);
this._gitpodServer = new GitpodServer(serviceUrl.toString(), this._logger);
this._keychain = new Keychain(this.context, `gitpod.auth.${serviceUrl.hostname}`, this._logger);

// Remove all sessions when gitpod.host changes
const sessions = await this._sessionsPromise;
await this._keychain.deleteToken();
this._sessionChangeEmitter.fire({ added: [], removed: sessions, changed: [] });
this.checkForUpdates();
}
}));

Expand Down
11 changes: 9 additions & 2 deletions extensions/gitpod/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ export async function activate(context: vscode.ExtensionContext) {

/* Gitpod settings sync */
await updateSyncContext();
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration('gitpod.host') || e.affectsConfiguration('configurationSync.store')) {
updateSyncContext();
const addedSyncProvider = await updateSyncContext();
if (!addedSyncProvider) {
const action = 'Settings Sync: Enable signing in with Gitpod';
const result = await vscode.window.showInformationMessage('Gitpod Settings Sync configuration invalidated, Settings Sync is disabled.', action);
if (result === action) {
vscode.commands.executeCommand('gitpod.syncProvider.add');
}
}
}
}));

Expand Down
2 changes: 1 addition & 1 deletion extensions/gitpod/src/gitpodServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class GitpodServer extends Disposable {
constructor(serviceUrl: string, private readonly _logger: Log) {
super();

this._serviceUrl = new URL(serviceUrl).toString().replace(/\/$/, '');
this._serviceUrl = serviceUrl.replace(/\/$/, '');
}

public async login(scopes: string): Promise<string> {
Expand Down
7 changes: 4 additions & 3 deletions extensions/gitpod/src/settingsSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ function getGitpodSyncProviderConfig(serviceUrl: string): ConfigurationSyncStore
/**
* Updates the VS Code context to reflect whether the user added Gitpod as their Settings Sync provider.
*/
export async function updateSyncContext() {
export async function updateSyncContext(): Promise<boolean> {
const config = vscode.workspace.getConfiguration();
const syncProviderConfig = config.get('configurationSync.store');
const serviceUrl = config.get<string>('gitpod.host')!;
const gitpodSyncProviderConfig = getGitpodSyncProviderConfig(serviceUrl);
const addedSyncProvider = syncProviderConfig && JSON.stringify(syncProviderConfig) === JSON.stringify(gitpodSyncProviderConfig);
await vscode.commands.executeCommand('setContext', 'gitpod.addedSyncProvider', !!addedSyncProvider);
const addedSyncProvider = !!syncProviderConfig && JSON.stringify(syncProviderConfig) === JSON.stringify(gitpodSyncProviderConfig);
await vscode.commands.executeCommand('setContext', 'gitpod.addedSyncProvider', addedSyncProvider);
return addedSyncProvider;
}

/**
Expand Down

0 comments on commit adbfebf

Please sign in to comment.