Skip to content

Commit

Permalink
chore: only load keytar during the migration process VSCODE-450 (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz authored Aug 7, 2023
1 parent 711587b commit 095a20b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ConnectionString from 'mongodb-connection-string-url';
import { EventEmitter } from 'events';
import type { MongoClientOptions } from 'mongodb';
import { v4 as uuidv4 } from 'uuid';

import { createKeytar } from './utils/keytar';
import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
import { createLogger } from './logging';
import { ext } from './extensionConstants';
Expand Down Expand Up @@ -296,6 +296,13 @@ export default class ConnectionController {
async _migrateConnectionWithKeytarSecrets(
savedConnectionInfo: StoreConnectionInfoWithConnectionOptions
): Promise<MigratedStoreConnectionInfoWithConnectionOptions | undefined> {
try {
ext.keytarModule =
ext.keytarModule === undefined ? createKeytar() : ext.keytarModule;
} catch (err) {
// Couldn't load keytar, proceed without storing & loading connections.
}

// If the Keytar module is not available, we simply mark the connections
// storage as Keytar and return
if (!ext.keytarModule) {
Expand Down
10 changes: 0 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import * as vscode from 'vscode';

import { ext } from './extensionConstants';
import { createKeytar } from './utils/keytar';
import { createLogger } from './logging';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../package.json');
Expand All @@ -30,14 +29,6 @@ export async function activate(
context: vscode.ExtensionContext
): Promise<void> {
ext.context = context;
let hasKeytar = false;

try {
ext.keytarModule = createKeytar();
hasKeytar = true;
} catch (err) {
// Couldn't load keytar, proceed without storing & loading connections.
}

const defaultConnectionSavingLocation = vscode.workspace
.getConfiguration('mdb.connectionSaving')
Expand All @@ -53,7 +44,6 @@ export async function activate(
workspaceStoragePath: context.storageUri?.path,
globalStoragePath: context.globalStorageUri.path,
defaultConnectionSavingLocation,
hasKeytar,
buildInfo: {
nodeVersion: process.version,
runtimePlatform: process.platform,
Expand Down

0 comments on commit 095a20b

Please sign in to comment.