secrets.ts ×15

Frontier kind: Code frontier

unlabeled · c_f79582620633

591 tests · 12428 LOC · 52 files · introduces 0 tests · 162 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges162 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1730 ranges12428 lines · 52 files · Browse complete extent
All tests (intent)
591 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 162 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/secrets/common/secrets.ts 99 introduced LOC · 15 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- secrets.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { SequencerByKey } from '../../../base/common/async.js';
7 > import { IEncryptionService } from '../../encryption/common/encryptionService.js';
8 > import { createDecorator } from '../../instantiation/common/instantiation.js';
9 > import { IStorageService, IStorageValueChangeEvent, InMemoryStorageService, StorageScope, StorageTarget } from '../../storage/common/storage.js';
10 > import { Emitter, Event } from '../../../base/common/event.js';
11 > import { ILogService } from '../../log/common/log.js';
12 > import { Disposable, DisposableStore } from '../../../base/common/lifecycle.js';
13 > import { Lazy } from '../../../base/common/lazy.js';
14 > import { isWindows } from '../../../base/common/platform.js';
15 >
16 > /**
17 > * The storage key prefix used for all secrets.
18 > */
19 > export const SECRET_STORAGE_PREFIX = 'secret://';
20 >
21 > /**
22 > * Builds the full storage key for a secret.
23 > */
24 > export function secretStorageKey(key: string): string {
25 return `${SECRET_STORAGE_PREFIX}${key}`;
26 }
27 > secrets.ts
28 > /**
29 > * Reads an encrypted secret from storage and decrypts it.
30 > * @param key The secret key (without the `secret://` prefix).
31 > * @param storageGet A function that reads the encrypted value from storage given a full storage key.
32 > * @param decrypt A function that decrypts the encrypted value.
33 > * @param logService Optional logger for trace output.
34 > */
35 export async function readEncryptedSecret(
36 key: string,
51 return result;
52 }
53 > secrets.ts
54 > /**
55 > * Encrypts a secret value and writes it to storage.
56 > * @param key The secret key (without the `secret://` prefix).
57 > * @param value The plaintext secret value.
58 > * @param storageSet A function that writes the encrypted value to storage given a full storage key.
59 > * @param encrypt A function that encrypts the plaintext value.
60 > * @param logService Optional logger for trace output.
61 > */
62 export async function writeEncryptedSecret(
63 key: string,
74 logService?.trace('[secrets] stored encrypted secret for key:', fullKey);
75 }
76 > secrets.ts
77 > /**
78 > * Secret keys that should be shared between the VS Code app and the agents app.
79 > * When the agents app starts and doesn't have these secrets, it requests them
80 > * from VS Code via crossAppIPC.
81 > */
82 > export const CROSS_APP_SHARED_SECRET_KEYS: readonly string[] = [
83 > '{"extensionId":"vscode.github-authentication","key":"github.auth"}',
84 > ];
85 >
86 > export const ISecretStorageService = createDecorator<ISecretStorageService>('secretStorageService');
87 >
88 > export interface ISecretStorageProvider {
89 > type: 'in-memory' | 'persisted' | 'unknown';
90 > get(key: string): Promise<string | undefined>;
91 > set(key: string, value: string): Promise<void>;
92 > delete(key: string): Promise<void>;
93 > keys?(): Promise<string[]>;
94 > }
95 >
96 > export interface ISecretStorageService extends ISecretStorageProvider {
97 > readonly _serviceBrand: undefined;
98 > readonly onDidChangeSecret: Event<string>;
99 > }
100 >
101 > export class BaseSecretStorageService extends Disposable implements ISecretStorageService {
102 > declare readonly _serviceBrand: undefined;
103 >
104 > protected readonly onDidChangeSecretEmitter = this._register(new Emitter<string>());
105 > readonly onDidChangeSecret: Event<string> = this.onDidChangeSecretEmitter.event;
106 >
107 > protected readonly _sequencer = new SequencerByKey<string>();
108 >
109 > private _type: 'in-memory' | 'persisted' | 'unknown' = 'unknown';
110 >
111 > private readonly _onDidChangeValueDisposable = this._register(new DisposableStore());
112 >
113 > constructor(
114 private readonly _useInMemoryStorage: boolean,
115 @IStorageService private _storageService: IStorageService,
133
134 private _lazyStorageService: Lazy<Promise<IStorageService>> = new Lazy(() => this.initialize());
135 > protected get resolvedStorageService() { secrets.ts
136 return this._lazyStorageService.value;
137 }
138 > secrets.ts
139 > get(key: string): Promise<string | undefined> {
140 return this._sequencer.queue(key, async () => {
141 const storageService = await this.resolvedStorageService;
156 });
157 }
158 > secrets.ts
159 > set(key: string, value: string): Promise<void> {
160 return this._sequencer.queue(key, async () => {
161 const storageService = await this.resolvedStorageService;
176 });
177 }
178 > secrets.ts
179 > delete(key: string): Promise<void> {
180 return this._sequencer.queue(key, async () => {
181 const storageService = await this.resolvedStorageService;
188 });
189 }
190 > secrets.ts
191 > keys(): Promise<string[]> {
192 return this._sequencer.queue('__keys__', async () => {
193 const storageService = await this.resolvedStorageService;
198 });
199 }
200 > secrets.ts
201 > private getValueFromStorage(key: string, fullKey: string, storageService: IStorageService): string | undefined {
202 if (this.useSharedStorage(key)) {
203 this._logService.trace(`[SecretStorageService] Fetching value for cross-app shared secret: ${fullKey}`);
206 return storageService.get(fullKey, StorageScope.APPLICATION);
207 }
208 > secrets.ts
209 > private setValueInStorage(key: string, fullKey: string, value: string, storageService: IStorageService): void {
210 if (this.useSharedStorage(key)) {
211 this._logService.trace(`[SecretStorageService] Setting value for cross-app shared secret: ${fullKey}`);
215 storageService.store(fullKey, value, StorageScope.APPLICATION, StorageTarget.MACHINE);
216 }
217 > secrets.ts
218 > private async initialize(): Promise<IStorageService> {
219 let storageService;
220 if (!this._useInMemoryStorage && await this._encryptionService.isEncryptionAvailable()) {
241 return storageService;
242 }
243 > secrets.ts
244 > protected reinitialize(): void {
245 this._lazyStorageService = new Lazy(() => this.initialize());
246 }
247 > secrets.ts
248 > private onDidChangeValue(key: string): void {
249 if (!key.startsWith(SECRET_STORAGE_PREFIX)) {
250 return;
256 this.onDidChangeSecretEmitter.fire(secretKey);
257 }
258 > } secrets.ts
src/vs/platform/encryption/common/encryptionService.ts 63 introduced LOC · 2 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- encryptionService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { createDecorator } from '../../instantiation/common/instantiation.js';
7 >
8 > export const IEncryptionService = createDecorator<IEncryptionService>('encryptionService');
9 > export interface IEncryptionService extends ICommonEncryptionService {
10 > setUsePlainTextEncryption(): Promise<void>;
11 > getKeyStorageProvider(): Promise<KnownStorageProvider>;
12 > }
13 >
14 > export const IEncryptionMainService = createDecorator<IEncryptionMainService>('encryptionMainService');
15 > export interface IEncryptionMainService extends IEncryptionService { }
16 >
17 > export interface ICommonEncryptionService {
18 >
19 > readonly _serviceBrand: undefined;
20 >
21 > encrypt(value: string): Promise<string>;
22 >
23 > decrypt(value: string): Promise<string>;
24 >
25 > isEncryptionAvailable(): Promise<boolean>;
26 > }
27 >
28 > // The values provided to the `password-store` command line switch.
29 > // Notice that they are not the same as the values returned by
30 > // `getSelectedStorageBackend` in the `safeStorage` API.
31 > export const enum PasswordStoreCLIOption {
32 > kwallet = 'kwallet',
33 > kwallet5 = 'kwallet5',
34 > gnomeLibsecret = 'gnome-libsecret',
35 > basic = 'basic'
36 > }
37 >
38 > // The values returned by `getSelectedStorageBackend` in the `safeStorage` API.
39 > export const enum KnownStorageProvider {
40 > unknown = 'unknown',
41 > basicText = 'basic_text',
42 >
43 > // Linux
44 > gnomeAny = 'gnome_any',
45 > gnomeLibsecret = 'gnome_libsecret',
46 > gnomeKeyring = 'gnome_keyring',
47 > kwallet = 'kwallet',
48 > kwallet5 = 'kwallet5',
49 > kwallet6 = 'kwallet6',
50 >
51 > // The rest of these are not returned by `getSelectedStorageBackend`
52 > // but these were added for platform completeness.
53 >
54 > // Windows
55 > dplib = 'dpapi',
56 >
57 > // macOS
58 > keychainAccess = 'keychain_access',
59 > }
60 >
61 > export function isKwallet(backend: string): boolean {
62 return backend === KnownStorageProvider.kwallet
63 || backend === KnownStorageProvider.kwallet5
64 || backend === KnownStorageProvider.kwallet6;
65 }
67 > export function isGnome(backend: string): boolean {
68 return backend === KnownStorageProvider.gnomeAny
69 || backend === KnownStorageProvider.gnomeLibsecret