Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove keytar in favor of VSCode API #2709

Merged
merged 1 commit into from Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion extension.bundle.ts
Expand Up @@ -25,7 +25,6 @@ export { Lazy, AsyncLazy } from './src/utils/lazy';
export { bufferToString } from './src/utils/spawnAsync';
export { ext } from './src/extensionVariables';
export { httpsRequestBinary } from './src/utils/httpRequest';
export { IKeytar } from './src/utils/keytar';
export { inferCommand, inferPackageName, InspectMode, NodePackage } from './src/utils/nodeUtils';
export { nonNullProp } from './src/utils/nonNull';
export { getDockerOSType } from "./src/utils/osUtils";
Expand Down
227 changes: 5 additions & 222 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -2680,7 +2680,7 @@
}
},
"engines": {
"vscode": "^1.52.0"
"vscode": "^1.53.0"
},
"scripts": {
"watch": "tsc -watch -p ./",
Expand All @@ -2705,14 +2705,13 @@
"@types/dockerode": "^3.2.2",
"@types/fs-extra": "^9.0.6",
"@types/glob": "^7.1.3",
"@types/keytar": "^4.4.2",
"@types/mocha": "^8.2.0",
"@types/node": "^12.19.14",
"@types/request-promise-native": "^1.0.17",
"@types/semver": "^7.3.4",
"@types/string-replace-webpack-plugin": "^0.1.0",
"@types/tar-stream": "^2.2.0",
"@types/vscode": "1.52.0",
"@types/vscode": "1.53.0",
"@types/xml2js": "^0.4.7",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.14.0",
Expand Down
5 changes: 0 additions & 5 deletions src/extension.ts
Expand Up @@ -30,7 +30,6 @@ import { SurveyManager } from './telemetry/surveys/SurveyManager';
import { registerTrees } from './tree/registerTrees';
import { AzureAccountExtensionListener } from './utils/AzureAccountExtensionListener';
import { cryptoUtils } from './utils/cryptoUtils';
import { Keytar } from './utils/keytar';
import { isLinux, isMac, isWindows } from './utils/osUtils';

export type KeyInfo = { [keyName: string]: string };
Expand Down Expand Up @@ -60,10 +59,6 @@ function initializeExtensionVariables(ctx: vscode.ExtensionContext): void {
ext.outputChannel = createAzExtOutputChannel('Docker', ext.prefix);
ctx.subscriptions.push(ext.outputChannel);

if (!ext.keytar) {
ext.keytar = Keytar.tryCreate();
}

registerUIExtensionVariables(ext);
}

Expand Down
2 changes: 0 additions & 2 deletions src/extensionVariables.ts
Expand Up @@ -14,7 +14,6 @@ import { ImagesTreeItem } from './tree/images/ImagesTreeItem';
import { NetworksTreeItem } from './tree/networks/NetworksTreeItem';
import { RegistriesTreeItem } from './tree/registries/RegistriesTreeItem';
import { VolumesTreeItem } from './tree/volumes/VolumesTreeItem';
import { IKeytar } from './utils/keytar';

/**
* Namespace for common variables used throughout the extension. They must be initialized in the activate() method of extension.ts
Expand All @@ -29,7 +28,6 @@ export namespace ext {
export let experimentationService: IExperimentationServiceAdapter;
export let activityMeasurementService: IActivityMeasurementService;

export let keytar: IKeytar | undefined;
export let dockerContextManager: ContextManager;
export let dockerClient: DockerApiClient;
export let treeInitError: unknown;
Expand Down
38 changes: 3 additions & 35 deletions src/tree/registries/registryPasswords.ts
Expand Up @@ -7,48 +7,16 @@ import * as crypto from 'crypto';
import { ext } from '../../extensionVariables';
import { ICachedRegistryProvider } from "./ICachedRegistryProvider";

const sessionPasswords: Map<string, string> = new Map<string, string>();

const serviceId: string = 'ms-azuretools.vscode-docker';

// Note: depending on OS configuration and installed components, the keytar module might or might not be able to persist the secrets.
// If it fails, we just exclusively rely on session password cache.
// See https://github.com/microsoft/vscode-docker/issues/722 for more information when that might happen.

export async function getRegistryPassword(cached: ICachedRegistryProvider): Promise<string | undefined> {
const key = getRegistryPasswordKey(cached);
let password = sessionPasswords.get(key);
if (!password && ext.keytar) {
try {
password = await ext.keytar.getPassword(serviceId, key);
} catch { }

if (password) {
sessionPasswords.set(key, password);
}
}

return password;
return ext.context.secrets.get(getRegistryPasswordKey(cached));
}

export async function setRegistryPassword(cached: ICachedRegistryProvider, password: string): Promise<void> {
const key = getRegistryPasswordKey(cached);
sessionPasswords.set(key, password);
if (ext.keytar) {
try {
await ext.keytar.setPassword(serviceId, key, password);
} catch { }
}
return ext.context.secrets.store(getRegistryPasswordKey(cached), password);
}

export async function deleteRegistryPassword(cached: ICachedRegistryProvider): Promise<void> {
const key = getRegistryPasswordKey(cached);
sessionPasswords.delete(key);
if (ext.keytar) {
try {
await ext.keytar.deletePassword(serviceId, key);
} catch { }
}
return ext.context.secrets.delete(getRegistryPasswordKey(cached));
}

function getRegistryPasswordKey(cached: ICachedRegistryProvider): string {
Expand Down
26 changes: 0 additions & 26 deletions src/utils/getCoreNodeModule.ts

This file was deleted.

81 changes: 0 additions & 81 deletions src/utils/keytar.ts

This file was deleted.

3 changes: 0 additions & 3 deletions test/global.test.ts
Expand Up @@ -9,7 +9,6 @@ import * as mocha from 'mocha';
import * as path from "path";
import * as vscode from "vscode";
import { ext } from "../extension.bundle";
import { TestKeytar } from "../test/testKeytar";
import { TestUserInput } from 'vscode-azureextensiondev';

export namespace constants {
Expand Down Expand Up @@ -69,8 +68,6 @@ suiteSetup(async function (this: mocha.Context): Promise<void> {
console.log('global.test.ts: suiteSetup');

ext.runningTests = true;
// Otherwise the app can blocking asking for keychain access
ext.keytar = new TestKeytar();

console.log("Refreshing tree to make sure extension is activated");
await vscode.commands.executeCommand('vscode-docker.registries.refresh');
Expand Down
52 changes: 0 additions & 52 deletions test/testKeytar.ts

This file was deleted.

9 changes: 0 additions & 9 deletions webpack.config.js
Expand Up @@ -35,12 +35,6 @@ let config = dev.getDefaultWebpackConfig({
'./dockerfile-language-server-nodejs/lib/server': './node_modules/dockerfile-language-server-nodejs/lib/server.js'
},

externals:
{
// ./getCoreNodeModule.js (path from keytar.ts) uses a dynamic require which can't be webpacked
'./getCoreNodeModule': 'commonjs getCoreNodeModule',
}, // end of externals

loaderRules: [
{
// Fix error:
Expand Down Expand Up @@ -105,9 +99,6 @@ let config = dev.getDefaultWebpackConfig({
// Copy files to dist folder where the runtime can find them
new CopyWebpackPlugin({
patterns: [
// getCoreNodeModule.js -> dist/node_modules/getCoreNodeModule.js
{ from: './out/src/utils/getCoreNodeModule.js', to: 'node_modules' },

// node_modules/vscode-codicons/dist/codicon.css, .ttf -> dist/node_modules/vscode-codicons/dist/codicon.css, .ttf
{ from: './node_modules/vscode-codicons/dist/codicon.css', to: 'node_modules/vscode-codicons/dist' },
{ from: './node_modules/vscode-codicons/dist/codicon.ttf', to: 'node_modules/vscode-codicons/dist' },
Expand Down