Proposed credentials API

This commit is contained in:
Christof Marti
2017-07-18 14:52:01 -07:00
parent 05e653d61e
commit a6a07a74e0
14 changed files with 309 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ import { ExtHostLanguageFeatures } from 'vs/workbench/api/node/extHostLanguageFe
import { ExtHostApiCommands } from 'vs/workbench/api/node/extHostApiCommands';
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
import { ExtHostCredentials } from 'vs/workbench/api/node/extHostCredentials';
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
import URI from 'vs/base/common/uri';
import Severity from 'vs/base/common/severity';
@@ -94,6 +95,7 @@ export function createApiFactory(
const extHostTerminalService = col.define(ExtHostContext.ExtHostTerminalService).set<ExtHostTerminalService>(new ExtHostTerminalService(threadService));
const extHostSCM = col.define(ExtHostContext.ExtHostSCM).set<ExtHostSCM>(new ExtHostSCM(threadService, extHostCommands));
const extHostTask = col.define(ExtHostContext.ExtHostTask).set<ExtHostTask>(new ExtHostTask(threadService));
const extHostCredentials = col.define(ExtHostContext.ExtHostCredentials).set<ExtHostCredentials>(new ExtHostCredentials(threadService));
col.define(ExtHostContext.ExtHostExtensionService).set(extensionService);
col.finish(false, threadService);
@@ -487,6 +489,19 @@ export function createApiFactory(
}
};
// namespace: credentials
const credentials: typeof vscode.credentials = {
readSecret(service: string, account: string): Thenable<string | undefined> {
return extHostCredentials.readSecret(service, account);
},
writeSecret(service: string, account: string, secret: string): Thenable<void> {
return extHostCredentials.writeSecret(service, account, secret);
},
deleteSecret(service: string, account: string): Thenable<boolean> {
return extHostCredentials.deleteSecret(service, account);
}
};
return {
version: pkg.version,
@@ -499,6 +514,11 @@ export function createApiFactory(
workspace,
scm,
debug,
get credentials() {
return proposedApiFunction(extension, () => {
return credentials;
})();
},
// types
CancellationTokenSource: CancellationTokenSource,
CodeLens: extHostTypes.CodeLens,

View File

@@ -350,6 +350,12 @@ export abstract class MainThreadDebugServiceShape {
$customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): TPromise<any> { throw ni(); }
}
export abstract class MainThreadCredentialsShape {
$readSecret(service: string, account: string): Thenable<string | undefined> { throw ni(); }
$writeSecret(service: string, account: string, secret: string): Thenable<void> { throw ni(); }
$deleteSecret(service: string, account: string): Thenable<boolean> { throw ni(); }
}
// -- extension host
export abstract class ExtHostCommandsShape {
@@ -506,6 +512,9 @@ export abstract class ExtHostDebugServiceShape {
$acceptDebugSessionCustomEvent(id: DebugSessionUUID, type: string, name: string, event: any): void { throw ni(); }
}
export abstract class ExtHostCredentialsShape {
}
// --- proxy identifiers
export const MainContext = {
@@ -530,7 +539,8 @@ export const MainContext = {
MainThreadWorkspace: createMainId<MainThreadWorkspaceShape>('MainThreadWorkspace', MainThreadWorkspaceShape),
MainProcessExtensionService: createMainId<MainProcessExtensionServiceShape>('MainProcessExtensionService', MainProcessExtensionServiceShape),
MainThreadSCM: createMainId<MainThreadSCMShape>('MainThreadSCM', MainThreadSCMShape),
MainThreadTask: createMainId<MainThreadTaskShape>('MainThreadTask', MainThreadTaskShape)
MainThreadTask: createMainId<MainThreadTaskShape>('MainThreadTask', MainThreadTaskShape),
MainThreadCredentials: createMainId<MainThreadCredentialsShape>('MainThreadCredentials', MainThreadCredentialsShape),
};
export const ExtHostContext = {
@@ -552,4 +562,5 @@ export const ExtHostContext = {
ExtHostSCM: createExtId<ExtHostSCMShape>('ExtHostSCM', ExtHostSCMShape),
ExtHostTask: createExtId<ExtHostTaskShape>('ExtHostTask', ExtHostTaskShape),
ExtHostWorkspace: createExtId<ExtHostWorkspaceShape>('ExtHostWorkspace', ExtHostWorkspaceShape),
ExtHostCredentials: createExtId<ExtHostCredentialsShape>('ExtHostCredentials', ExtHostCredentialsShape),
};

View File

@@ -0,0 +1,31 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { MainContext, MainThreadCredentialsShape, ExtHostCredentialsShape } from 'vs/workbench/api/node/extHost.protocol';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
export class ExtHostCredentials extends ExtHostCredentialsShape {
private _proxy: MainThreadCredentialsShape;
constructor(threadService: IThreadService) {
super();
this._proxy = threadService.get(MainContext.MainThreadCredentials);
};
readSecret(service: string, account: string): Thenable<string | undefined> {
return this._proxy.$readSecret(service, account);
}
writeSecret(service: string, account: string, secret: string): Thenable<void> {
return this._proxy.$writeSecret(service, account, secret);
}
deleteSecret(service: string, account: string): Thenable<boolean> {
return this._proxy.$deleteSecret(service, account);
}
}