From 3c1691a41b8b3b5dcfa387fa9d541e0b0be1be20 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Sat, 9 May 2020 15:33:21 +0200 Subject: [PATCH 1/8] Enable linux tests with graphics workaround --- azure-pipelines.yml | 28 +++++++++++++---------- scripts/xvfb.init | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 scripts/xvfb.init diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 02c9580d1..84485bfb1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,17 +9,15 @@ trigger: # https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops strategy: matrix: - # # Linux testing is currently disabled because of issues with - # # headless linux & keytar. Tracked: VSCODE-110 - # linux: - # imageName: 'ubuntu-latest' - mac: - imageName: 'macos-latest' - windows: - # NOTE (lucas): Also blocked on Windows 2019 by - # https://jira.mongodb.org/browse/NODE-2465 - # imageName: 'windows-latest' - imageName: 'vs2017-win2016' + linux: + imageName: 'ubuntu-latest' + # mac: + # imageName: 'macos-latest' + # windows: + # # NOTE (lucas): Also blocked on Windows 2019 by + # # https://jira.mongodb.org/browse/NODE-2465 + # # imageName: 'windows-latest' + # imageName: 'vs2017-win2016' pool: vmImage: $(imageName) @@ -28,6 +26,12 @@ steps: set -e sudo apt-get update + sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 + sudo cp scripts/xvfb.init /etc/init.d/xvfb + sudo chmod +x /etc/init.d/xvfb + sudo update-rc.d xvfb defaults + sudo service xvfb start + displayName: 'Install native Linux dependencies' condition: in(variables['agent.os'], 'Linux') - task: NodeTool@0 @@ -51,7 +55,7 @@ steps: npm ci; displayName: 'Install dependencies from npm' - - bash: npm run test + - bash: DISPLAY=:10 npm run test displayName: 'Run Tests' env: SEGMENT_KEY: $(segmentKey) diff --git a/scripts/xvfb.init b/scripts/xvfb.init new file mode 100644 index 000000000..00832d1e5 --- /dev/null +++ b/scripts/xvfb.init @@ -0,0 +1,54 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/xvfbd +### From https://github.com/microsoft/vscode/blob/master/build/azure-pipelines/linux/xvfb.init +# +# chkconfig: 345 95 28 +# description: Starts/Stops X Virtual Framebuffer server +# processname: Xvfb +# +### BEGIN INIT INFO +# Provides: xvfb +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start xvfb at boot time +# Description: Enable xvfb provided by daemon. +### END INIT INFO + +[ "${NETWORKING}" = "no" ] && exit 0 + +PROG="/usr/bin/Xvfb" +PROG_OPTIONS=":10 -ac -screen 0 1024x768x24" +PROG_OUTPUT="/tmp/Xvfb.out" + +case "$1" in + start) + echo "Starting : X Virtual Frame Buffer " + $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 & + disown -ar + ;; + stop) + echo "Shutting down : X Virtual Frame Buffer" + killproc $PROG + RETVAL=$? + [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb + /var/run/Xvfb.pid + echo + ;; + restart|reload) + $0 stop + $0 start + RETVAL=$? + ;; + status) + status Xvfb + RETVAL=$? + ;; + *) + echo $"Usage: $0 (start|stop|restart|reload|status)" + exit 1 +esac + +exit $RETVAL From ee809200e4e604cf426a807cd47f2706d640be4f Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Thu, 14 May 2020 11:51:35 +0200 Subject: [PATCH 2/8] Use older ubuntu with python gnome keyring unlock --- azure-pipelines.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 84485bfb1..0b21126dd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ trigger: strategy: matrix: linux: - imageName: 'ubuntu-latest' + imageName: 'ubuntu-16.04' # mac: # imageName: 'macos-latest' # windows: @@ -26,12 +26,23 @@ steps: set -e sudo apt-get update + # Start xvfb running. sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 sudo cp scripts/xvfb.init /etc/init.d/xvfb sudo chmod +x /etc/init.d/xvfb sudo update-rc.d xvfb defaults sudo service xvfb start + # Give xvfb a moment to start. + sleep 3; + + # Login our credential store to avoid timeout when storing and retrieving. + sudo apt-get install -y gnome-keyring python-gnomekeyring + eval $(dbus-launch --sh-syntax); + eval $(echo -n "" | /usr/bin/gnome-keyring-daemon --login); + eval $(/usr/bin/gnome-keyring-daemon --components=secrets --start); + /usr/bin/python -c "import gnomekeyring;gnomekeyring.create_sync('login', '');"; + displayName: 'Install native Linux dependencies' condition: in(variables['agent.os'], 'Linux') - task: NodeTool@0 From 647c005398cbf65bae1606a89040aee19efd2ee8 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Thu, 14 May 2020 12:36:09 +0200 Subject: [PATCH 3/8] Tweak environment variable for display on linux --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0b21126dd..5701ed202 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -70,6 +70,7 @@ steps: displayName: 'Run Tests' env: SEGMENT_KEY: $(segmentKey) + DISPLAY: :10 - bash: ls -alh displayName: 'Post Tests' From 683fa881d2d1678eed65804e81f9f3c816b58abd Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 18 May 2020 14:42:50 +0200 Subject: [PATCH 4/8] Use fake keytar in testing environment --- src/connectionController.ts | 53 +++++++++++------------------- src/extension.ts | 8 +++++ src/extensionConstants.ts | 2 ++ src/test/suite/index.ts | 41 +++++++---------------- src/test/suite/keytarStub.ts | 63 ++++++++++++++++++++++++++++++++++++ src/utils/keytar.ts | 49 ++++++++++++++++++++++++++++ 6 files changed, 152 insertions(+), 64 deletions(-) create mode 100644 src/test/suite/keytarStub.ts create mode 100644 src/utils/keytar.ts diff --git a/src/connectionController.ts b/src/connectionController.ts index 22f5a05a0..eae051be8 100644 --- a/src/connectionController.ts +++ b/src/connectionController.ts @@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid'; import * as vscode from 'vscode'; import Connection = require('mongodb-connection-model/lib/model'); import DataService = require('mongodb-data-service'); -import * as keytarType from 'keytar'; + import { ConnectionModelType } from './connectionModelType'; import { DataServiceType } from './dataServiceType'; import { createLogger } from './logging'; @@ -10,25 +10,23 @@ import { StatusView } from './views'; import { EventEmitter } from 'events'; import { StorageController, StorageVariables } from './storage'; import { SavedConnection, StorageScope } from './storage/storageController'; -import { getNodeModule } from './utils/getNodeModule'; import TelemetryController from './telemetry/telemetryController'; +import { ext } from './extensionConstants'; const { name, version } = require('../package.json'); const log = createLogger('connection controller'); const MAX_CONNECTION_NAME_LENGTH = 512; -type KeyTar = typeof keytarType; - export enum DataServiceEventTypes { CONNECTIONS_DID_CHANGE = 'CONNECTIONS_DID_CHANGE', ACTIVE_CONNECTION_CHANGED = 'ACTIVE_CONNECTION_CHANGED', - ACTIVE_CONNECTION_CHANGING = 'ACTIVE_CONNECTION_CHANGING' + ACTIVE_CONNECTION_CHANGING = 'ACTIVE_CONNECTION_CHANGING', } export enum ConnectionTypes { CONNECTION_FORM = 'CONNECTION_FORM', CONNECTION_STRING = 'CONNECTION_STRING', - CONNECTION_ID = 'CONNECTION_ID' + CONNECTION_ID = 'CONNECTION_ID', } export type SavedConnectionInformation = { @@ -48,8 +46,6 @@ export default class ConnectionController { } = {}; private readonly _serviceName = 'mdb.vscode.savedConnections'; - private _keytar: KeyTar | undefined; - _activeDataService: null | DataServiceType = null; _activeConnectionModel: null | ConnectionModelType = null; private _currentConnectionId: null | string = null; @@ -73,33 +69,20 @@ export default class ConnectionController { this._statusView = _statusView; this._storageController = storageController; this._telemetryController = telemetryController; - - try { - // We load keytar in two different ways. This is because when the - // extension is webpacked it requires the vscode external keytar dependency - // differently then our testing development environment. - this._keytar = require('keytar'); - - if (!this._keytar) { - this._keytar = getNodeModule('keytar'); - } - } catch (err) { - // Couldn't load keytar, proceed without storing & loading connections. - } } _loadSavedConnection = async ( connectionId: string, savedConnection: SavedConnection ): Promise => { - if (!this._keytar) { + if (!ext.keytarModule) { return; } let loadedSavedConnection: LoadedConnection; try { - const unparsedConnectionInformation = await this._keytar.getPassword( + const unparsedConnectionInformation = await ext.keytarModule.getPassword( this._serviceName, connectionId ); @@ -138,7 +121,7 @@ export default class ConnectionController { }; loadSavedConnections = async (): Promise => { - if (!this._keytar) { + if (!ext.keytarModule) { return; } @@ -297,10 +280,10 @@ export default class ConnectionController { this._connections[connectionId] = newLoadedConnection; - if (this._keytar) { + if (ext.keytarModule) { const connectionInfoAsString = JSON.stringify(connectionInformation); - await this._keytar.setPassword( + await ext.keytarModule.setPassword( this._serviceName, connectionId, connectionInfoAsString @@ -496,8 +479,8 @@ export default class ConnectionController { ): Promise => { delete this._connections[connectionId]; - if (this._keytar) { - await this._keytar.deletePassword(this._serviceName, connectionId); + if (ext.keytarModule) { + await ext.keytarModule.deletePassword(this._serviceName, connectionId); // We only remove the connection from the saved connections if we // have deleted the connection information with keytar. this._storageController.removeConnection(connectionId); @@ -595,13 +578,13 @@ export default class ConnectionController { const connectionNameToRemove: | string | undefined = await vscode.window.showQuickPick( - connectionIds.map( - (id, index) => `${index + 1}: ${this._connections[id].name}` - ), - { - placeHolder: 'Choose a connection to remove...' - } - ); + connectionIds.map( + (id, index) => `${index + 1}: ${this._connections[id].name}` + ), + { + placeHolder: 'Choose a connection to remove...' + } + ); if (!connectionNameToRemove) { return Promise.resolve(false); diff --git a/src/extension.ts b/src/extension.ts index 2e842937a..7fe25472d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,7 @@ import * as vscode from 'vscode'; import { ext } from './extensionConstants'; +import { tryToCreateKeytar } from './utils/keytar'; import { createLogger } from './logging'; const log = createLogger('extension.ts'); @@ -26,6 +27,13 @@ export function activate(context: vscode.ExtensionContext): void { log.info('activate extension called'); ext.context = context; + + try { + ext.keytarModule = tryToCreateKeytar(); + } catch (err) { + // Couldn't load keytar, proceed without storing & loading connections. + } + mdbExtension = new MDBExtensionController(context); mdbExtension.activate(); diff --git a/src/extensionConstants.ts b/src/extensionConstants.ts index 68fe4e2c1..031b1ee9b 100644 --- a/src/extensionConstants.ts +++ b/src/extensionConstants.ts @@ -1,8 +1,10 @@ import { ExtensionContext } from 'vscode'; +import { KeytarInterface } from './utils/keytar'; // eslint-disable-next-line @typescript-eslint/no-namespace export namespace ext { export let context: ExtensionContext; + export let keytarModule: KeytarInterface | undefined; } export function getImagesPath(): string { diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index f7a8b4d48..2db916e28 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -5,9 +5,13 @@ import path = require('path'); import * as keytarType from 'keytar'; import MDBExtensionController from '../../mdbExtensionController'; +import { ext } from '../../extensionConstants'; +import KeytarStub from './keytarStub'; import { TestExtensionContext } from './stubs'; import { mdbTestExtension } from './stubbableMdbExtension'; +type KeyTar = typeof keytarType; + export function run(): Promise { const reporterOptions = { spec: '-', @@ -37,6 +41,12 @@ export function run(): Promise { ); mdbTestExtension.testExtensionController.activate(); + // We avoid using the user's credential store when running tests + // in order to ensure we're not polluting the credential store + // and because its tough to get the credential store running on + // headless linux. + ext.keytarModule = new KeytarStub(); + // Disable metrics. vscode.workspace.getConfiguration('mdb').update('sendTelemetry', false); @@ -44,39 +54,12 @@ export function run(): Promise { vscode.workspace .getConfiguration('mdb.connectionSaving') .update('hideOptionToChooseWhereToSaveNewConnections', true) - .then(async () => { - // We require keytar in runtime because it is a vscode provided - // native node module. - const keytar: typeof keytarType = require('keytar'); - const existingCredentials = await keytar.findCredentials( - 'mdb.vscode.savedConnections' - ); - + .then(() => { // Add files to the test suite. files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); try { // Run the mocha test. - mocha.run(async (failures) => { - // After tests are run we clear any passwords added - // to local secure storage. - const postRunCredentials = await keytar.findCredentials( - 'mdb.vscode.savedConnections' - ); - postRunCredentials.forEach((credential) => { - if ( - !existingCredentials.find( - (existingCredential) => - existingCredential.account === credential.account - ) - ) { - // If the credential is newly added, we remove it. - keytar.deletePassword( - 'mdb.vscode.savedConnections', - credential.account - ); - } - }); - + mocha.run((failures) => { if (failures > 0) { e(new Error(`${failures} tests failed.`)); } else { diff --git a/src/test/suite/keytarStub.ts b/src/test/suite/keytarStub.ts new file mode 100644 index 000000000..ad505f028 --- /dev/null +++ b/src/test/suite/keytarStub.ts @@ -0,0 +1,63 @@ +import { KeytarInterface } from '../../utils/keytar'; + +const retrievalDelay = 1; // ms simulated delay on keytar methods. + +export default class KeytarStub implements KeytarInterface { + private _services: Map> = new Map>(); + + public async findCredentials(service: string): Promise | undefined> { + await this.delay(); + const savedServices = this._services.get(service); + if (savedServices) { + return savedServices; + } + + return undefined; + } + + public async getPassword(service: string, account: string): Promise { + await this.delay(); + const savedService = this._services.get(service); + if (savedService) { + const savedAccount = savedService.get(account); + + if (savedAccount !== undefined) { + return savedAccount; + } + } + + return null; + } + + public async setPassword(service: string, account: string, password: string): Promise { + await this.delay(); + let savedService = this._services.get(service); + if (!savedService) { + savedService = new Map(); + this._services.set(service, savedService); + } + + savedService.set(account, password); + } + + public async deletePassword(service: string, account: string): Promise { + await this.delay(); + const savedService = this._services.get(service); + if (savedService) { + if (savedService.has(account)) { + savedService.delete(account); + return true; + } + } + + return false; + } + + private async delay(): Promise { + return new Promise(resolve => { + setTimeout(() => { + resolve(); + }, retrievalDelay); + }); + } +} diff --git a/src/utils/keytar.ts b/src/utils/keytar.ts new file mode 100644 index 000000000..75eb88818 --- /dev/null +++ b/src/utils/keytar.ts @@ -0,0 +1,49 @@ +import * as keytarType from 'keytar'; + +import { getNodeModule } from './getNodeModule'; + +export interface KeytarInterface { + /** + * Get the stored password for the service and account. + * + * @param service The string service name. + * @param account The string account name. + * + * @returns A promise for the password string. + */ + getPassword(service: string, account: string): Promise; + + /** + * Add the password for the service and account to the keychain. + * + * @param service The string service name. + * @param account The string account name. + * @param password The string password. + * + * @returns A promise for the set password completion. + */ + setPassword(service: string, account: string, password: string): Promise; + + /** + * Delete the stored password for the service and account. + * + * @param service The string service name. + * @param account The string account name. + * + * @returns A promise for the deletion status. True on success. + */ + deletePassword(service: string, account: string): Promise; +} + +export const tryToCreateKeytar = (): KeytarInterface | undefined => { + // We load keytar in two different ways. This is because when the + // extension is webpacked it requires the vscode external keytar dependency + // differently then our development environment. + let keytarModule: KeytarInterface | undefined = require('keytar'); + + if (!keytarModule) { + keytarModule = getNodeModule('keytar'); + } + + return keytarModule; +}; From 3dbbbeef09223f5c6c40b7dfc0f4e9287cd259da Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 18 May 2020 14:43:35 +0200 Subject: [PATCH 5/8] Remove unused linux packages and keyring setup --- azure-pipelines.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5701ed202..e739ef279 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,17 +32,6 @@ steps: sudo chmod +x /etc/init.d/xvfb sudo update-rc.d xvfb defaults sudo service xvfb start - - # Give xvfb a moment to start. - sleep 3; - - # Login our credential store to avoid timeout when storing and retrieving. - sudo apt-get install -y gnome-keyring python-gnomekeyring - eval $(dbus-launch --sh-syntax); - eval $(echo -n "" | /usr/bin/gnome-keyring-daemon --login); - eval $(/usr/bin/gnome-keyring-daemon --components=secrets --start); - /usr/bin/python -c "import gnomekeyring;gnomekeyring.create_sync('login', '');"; - displayName: 'Install native Linux dependencies' condition: in(variables['agent.os'], 'Linux') - task: NodeTool@0 From 1b8a78aa36ea71605a3d79b26f7bc2b7eac8d1cd Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 18 May 2020 15:05:53 +0200 Subject: [PATCH 6/8] Remove unused xvfb config --- azure-pipelines.yml | 26 ++++++++-------------- scripts/xvfb.init | 54 --------------------------------------------- 2 files changed, 9 insertions(+), 71 deletions(-) delete mode 100644 scripts/xvfb.init diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e739ef279..1019b4525 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,14 +10,14 @@ trigger: strategy: matrix: linux: - imageName: 'ubuntu-16.04' - # mac: - # imageName: 'macos-latest' - # windows: - # # NOTE (lucas): Also blocked on Windows 2019 by - # # https://jira.mongodb.org/browse/NODE-2465 - # # imageName: 'windows-latest' - # imageName: 'vs2017-win2016' + imageName: 'ubuntu-latest' + mac: + imageName: 'macos-latest' + windows: + # NOTE (lucas): Also blocked on Windows 2019 by + # https://jira.mongodb.org/browse/NODE-2465 + # imageName: 'windows-latest' + imageName: 'vs2017-win2016' pool: vmImage: $(imageName) @@ -25,13 +25,6 @@ steps: - script: | set -e sudo apt-get update - - # Start xvfb running. - sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 - sudo cp scripts/xvfb.init /etc/init.d/xvfb - sudo chmod +x /etc/init.d/xvfb - sudo update-rc.d xvfb defaults - sudo service xvfb start displayName: 'Install native Linux dependencies' condition: in(variables['agent.os'], 'Linux') - task: NodeTool@0 @@ -55,11 +48,10 @@ steps: npm ci; displayName: 'Install dependencies from npm' - - bash: DISPLAY=:10 npm run test + - bash: npm run test displayName: 'Run Tests' env: SEGMENT_KEY: $(segmentKey) - DISPLAY: :10 - bash: ls -alh displayName: 'Post Tests' diff --git a/scripts/xvfb.init b/scripts/xvfb.init deleted file mode 100644 index 00832d1e5..000000000 --- a/scripts/xvfb.init +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -# -# /etc/rc.d/init.d/xvfbd -### From https://github.com/microsoft/vscode/blob/master/build/azure-pipelines/linux/xvfb.init -# -# chkconfig: 345 95 28 -# description: Starts/Stops X Virtual Framebuffer server -# processname: Xvfb -# -### BEGIN INIT INFO -# Provides: xvfb -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start xvfb at boot time -# Description: Enable xvfb provided by daemon. -### END INIT INFO - -[ "${NETWORKING}" = "no" ] && exit 0 - -PROG="/usr/bin/Xvfb" -PROG_OPTIONS=":10 -ac -screen 0 1024x768x24" -PROG_OUTPUT="/tmp/Xvfb.out" - -case "$1" in - start) - echo "Starting : X Virtual Frame Buffer " - $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 & - disown -ar - ;; - stop) - echo "Shutting down : X Virtual Frame Buffer" - killproc $PROG - RETVAL=$? - [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb - /var/run/Xvfb.pid - echo - ;; - restart|reload) - $0 stop - $0 start - RETVAL=$? - ;; - status) - status Xvfb - RETVAL=$? - ;; - *) - echo $"Usage: $0 (start|stop|restart|reload|status)" - exit 1 -esac - -exit $RETVAL From 89bf0cbd3e9a4f939c41e563919f908195e8c0b2 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 18 May 2020 15:31:57 +0200 Subject: [PATCH 7/8] Tweak pipeline --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1019b4525..8ce076511 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,6 +25,7 @@ steps: - script: | set -e sudo apt-get update + displayName: 'Install native Linux dependencies' condition: in(variables['agent.os'], 'Linux') - task: NodeTool@0 From ee82282b067766a29ac89e0fc062abf5fffac5e5 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 18 May 2020 16:45:59 +0200 Subject: [PATCH 8/8] Improve keytar helper naming --- src/extension.ts | 4 ++-- src/utils/keytar.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7fe25472d..d15e5d1ef 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { ext } from './extensionConstants'; -import { tryToCreateKeytar } from './utils/keytar'; +import { createKeytar } from './utils/keytar'; import { createLogger } from './logging'; const log = createLogger('extension.ts'); @@ -29,7 +29,7 @@ export function activate(context: vscode.ExtensionContext): void { ext.context = context; try { - ext.keytarModule = tryToCreateKeytar(); + ext.keytarModule = createKeytar(); } catch (err) { // Couldn't load keytar, proceed without storing & loading connections. } diff --git a/src/utils/keytar.ts b/src/utils/keytar.ts index 75eb88818..1c4ce7053 100644 --- a/src/utils/keytar.ts +++ b/src/utils/keytar.ts @@ -22,7 +22,11 @@ export interface KeytarInterface { * * @returns A promise for the set password completion. */ - setPassword(service: string, account: string, password: string): Promise; + setPassword( + service: string, + account: string, + password: string + ): Promise; /** * Delete the stored password for the service and account. @@ -35,7 +39,7 @@ export interface KeytarInterface { deletePassword(service: string, account: string): Promise; } -export const tryToCreateKeytar = (): KeytarInterface | undefined => { +export const createKeytar = (): KeytarInterface | undefined => { // We load keytar in two different ways. This is because when the // extension is webpacked it requires the vscode external keytar dependency // differently then our development environment.