blob: f00f3532d004ce6318222eff7476313d3e38e917 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { InMemoryCredentialsProvider } from 'vs/platform/credentials/common/credentials';
import { ILogService } from 'vs/platform/log/common/log';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IProductService } from 'vs/platform/product/common/productService';
import { BaseCredentialsMainService, KeytarModule } from 'vs/platform/credentials/common/credentialsMainService';
export class CredentialsWebMainService extends BaseCredentialsMainService {
constructor(
@ILogService logService: ILogService,
@INativeEnvironmentService private readonly environmentMainService: INativeEnvironmentService,
@IProductService private readonly productService: IProductService,
) {
super(logService);
}
// If the credentials service is running on the server, we add a suffix -server to differentiate from the location that the
// client would store the credentials.
public override async getSecretStoragePrefix() { return Promise.resolve(`${this.productService.urlProtocol}-server`); }
protected async withKeytar(): Promise<KeytarModule> {
if (this._keytarCache) {
return this._keytarCache;
}
if (this.environmentMainService.disableKeytar) {
this.logService.info('Keytar is disabled. Using in-memory credential store instead.');
this._keytarCache = new InMemoryCredentialsProvider();
return this._keytarCache;
}
try {
this._keytarCache = await import('keytar');
// Try using keytar to see if it throws or not.
await this._keytarCache.findCredentials('test-keytar-loads');
} catch (e) {
this.logService.warn(
`Using the in-memory credential store as the operating system's credential store could not be accessed. Please see https://aka.ms/vscode-server-keyring on how to set this up. Details: ${e.message ?? e}`);
this._keytarCache = new InMemoryCredentialsProvider();
}
return this._keytarCache;
}
}
|