mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
Move secrets API to extension context
This commit is contained in:
39
src/vs/workbench/api/common/extHostSecrets.ts
Normal file
39
src/vs/workbench/api/common/extHostSecrets.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as vscode from 'vscode';
|
||||
|
||||
import { ExtHostSecretState } from 'vs/workbench/api/common/exHostSecretState';
|
||||
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
|
||||
export class ExtensionSecrets implements vscode.SecretState {
|
||||
|
||||
protected readonly _id: string;
|
||||
protected readonly _secretState: ExtHostSecretState;
|
||||
|
||||
private _onDidChangePassword = new Emitter<void>();
|
||||
readonly onDidChangePassword: Event<void> = this._onDidChangePassword.event;
|
||||
|
||||
|
||||
constructor(extensionDescription: IExtensionDescription, secretState: ExtHostSecretState) {
|
||||
this._id = ExtensionIdentifier.toKey(extensionDescription.identifier);
|
||||
this._secretState = secretState;
|
||||
|
||||
this._secretState.onDidChangePassword(_ => this._onDidChangePassword.fire());
|
||||
}
|
||||
|
||||
get(key: string): Promise<string | undefined> {
|
||||
return this._secretState.get(this._id, key);
|
||||
}
|
||||
|
||||
set(key: string, value: string): Promise<void> {
|
||||
return this._secretState.set(this._id, key, value);
|
||||
}
|
||||
|
||||
delete(key: string): Promise<void> {
|
||||
return this._secretState.delete(this._id, key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user