mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 01:25:36 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
66
src/sql/workbench/api/node/mainThreadCredentialManagement.ts
Normal file
66
src/sql/workbench/api/node/mainThreadCredentialManagement.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import {
|
||||
SqlExtHostContext, ExtHostCredentialManagementShape,
|
||||
MainThreadCredentialManagementShape, SqlMainContext } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
import { ICredentialsService } from 'sql/services/credentials/credentialsService';
|
||||
import * as data from 'data';
|
||||
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||
|
||||
@extHostNamedCustomer(SqlMainContext.MainThreadCredentialManagement)
|
||||
export class MainThreadCredentialManagement extends MainThreadCredentialManagementShape {
|
||||
|
||||
private _proxy: ExtHostCredentialManagementShape;
|
||||
|
||||
private _toDispose: IDisposable[];
|
||||
|
||||
private _registrations: { [handle: number]: IDisposable; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@ICredentialsService private credentialService: ICredentialsService
|
||||
) {
|
||||
super();
|
||||
if (extHostContext) {
|
||||
this._proxy = extHostContext.get(SqlExtHostContext.ExtHostCredentialManagement);
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
}
|
||||
|
||||
public $registerCredentialProvider(handle: number): TPromise<any> {
|
||||
let self = this;
|
||||
|
||||
this._registrations[handle] = this.credentialService.addEventListener(handle, {
|
||||
onSaveCredential(credentialId: string, password: string): Thenable<boolean> {
|
||||
return self._proxy.$saveCredential(credentialId, password);
|
||||
},
|
||||
onReadCredential(credentialId: string): Thenable<data.Credential> {
|
||||
return self._proxy.$readCredential(credentialId);
|
||||
},
|
||||
onDeleteCredential(credentialId: string): Thenable<boolean> {
|
||||
return self._proxy.$deleteCredential(credentialId);
|
||||
}
|
||||
});
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public $unregisterCredentialProvider(handle: number): TPromise<any> {
|
||||
let registration = this._registrations[handle];
|
||||
if (registration) {
|
||||
registration.dispose();
|
||||
delete this._registrations[handle];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user