mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -6,22 +6,29 @@
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ICredentialsService } from 'vs/platform/credentials/common/credentials';
|
||||
import * as keytar from 'keytar';
|
||||
|
||||
export class CredentialsService implements ICredentialsService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
readSecret(service: string, account: string): TPromise<string | undefined> {
|
||||
return TPromise.wrap(keytar.getPassword(service, account))
|
||||
return this.getKeytar()
|
||||
.then(keytar => TPromise.wrap(keytar.getPassword(service, account)))
|
||||
.then(result => result === null ? undefined : result);
|
||||
}
|
||||
|
||||
writeSecret(service: string, account: string, secret: string): TPromise<void> {
|
||||
return TPromise.wrap(keytar.setPassword(service, account, secret));
|
||||
return this.getKeytar()
|
||||
.then(keytar => TPromise.wrap(keytar.setPassword(service, account, secret)));
|
||||
}
|
||||
|
||||
deleteSecret(service: string, account: string): TPromise<boolean> {
|
||||
return TPromise.wrap(keytar.deletePassword(service, account));
|
||||
return this.getKeytar()
|
||||
.then(keytar => TPromise.wrap(keytar.deletePassword(service, account)));
|
||||
}
|
||||
|
||||
private getKeytar() {
|
||||
// Avoids https://github.com/Microsoft/vscode/issues/33998
|
||||
return TPromise.wrap(import('keytar'));
|
||||
}
|
||||
}
|
||||
|
||||
26
src/vs/platform/credentials/test/node/keytar.test.ts
Normal file
26
src/vs/platform/credentials/test/node/keytar.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 * as assert from 'assert';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
|
||||
suite('Keytar', () => {
|
||||
|
||||
test('loads and is functional', done => {
|
||||
if (platform.isLinux) {
|
||||
// Skip test due to set up issue with Travis.
|
||||
done();
|
||||
return;
|
||||
}
|
||||
(async () => {
|
||||
const keytar = await import('keytar');
|
||||
await keytar.setPassword('VSCode Test', 'foo', 'bar');
|
||||
assert.equal(await keytar.getPassword('VSCode Test', 'foo'), 'bar');
|
||||
await keytar.deletePassword('VSCode Test', 'foo');
|
||||
assert.equal(await keytar.getPassword('VSCode Test', 'foo'), undefined);
|
||||
})().then(done, done);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user