secrets.ts ×15

Frontier kind: Code frontier

unlabeled · c_208a3c58ca15

13 tests · 13046 LOC · 52 files · introduces 0 tests · 72 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges72 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1929 ranges13046 lines · 52 files · Browse complete extent
All tests (intent)
13 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.

1 file ranked by introduced lines: 72 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

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

Open complete file

23 */
24 export function secretStorageKey(key: string): string {
25 > return `${SECRET_STORAGE_PREFIX}${key}`; secrets.ts
26 > }
27
28 /**
60 * @param logService Optional logger for trace output.
61 */
62 > export async function writeEncryptedSecret( secrets.ts
63 > key: string,
64 > value: string,
65 > storageSet: (fullKey: string, encrypted: string) => void,
66 > encrypt: (value: string) => Promise<string>,
67 > logService?: ILogService,
68 > ): Promise<void> {
69 > logService?.trace('[secrets] encrypting secret for key:', key);
70 > const encrypted = await encrypt(value);
71 > const fullKey = secretStorageKey(key);
72 > logService?.trace('[secrets] storing encrypted secret for key:', fullKey);
73 > storageSet(fullKey, encrypted);
74 > logService?.trace('[secrets] stored encrypted secret for key:', fullKey);
75 > }
76
77 /**
112
113 constructor(
114 > private readonly _useInMemoryStorage: boolean, secrets.ts
115 > @IStorageService private _storageService: IStorageService,
116 > @IEncryptionService protected _encryptionService: IEncryptionService,
117 > @ILogService protected readonly _logService: ILogService,
118 > ) {
119 > super();
120 > }
121 >
122 > protected useSharedStorage(key: string): boolean {
123 return isWindows && CROSS_APP_SHARED_SECRET_KEYS.includes(key);
124 }
125 > secrets.ts
126 > /**
127 > * @Note initialize must be called first so that this can be resolved properly
128 > * otherwise it will return 'unknown'.
129 > */
130 > get type() {
131 return this._type;
132 }
133 > secrets.ts
134 > private _lazyStorageService: Lazy<Promise<IStorageService>> = new Lazy(() => this.initialize());
135 protected get resolvedStorageService() {
136 > return this._lazyStorageService.value; secrets.ts
137 > }
138
139 get(key: string): Promise<string | undefined> {
158
159 set(key: string, value: string): Promise<void> {
160 > return this._sequencer.queue(key, async () => { secrets.ts
161 > const storageService = await this.resolvedStorageService;
162 >
163 > try {
164 > await writeEncryptedSecret(
165 > key,
166 > value,
167 > (fullKey, encrypted) => this.setValueInStorage(key, fullKey, encrypted, storageService),
168 > // If the storage service is in-memory, we don't need to encrypt
169 > this._type === 'in-memory' ? (v) => Promise.resolve(v) : (v) => this._encryptionService.encrypt(v),
170 > this._logService,
171 > );
172 > } catch (e) {
173 this._logService.error(e);
174 throw e;
175 }
176 > }); secrets.ts
177 > }
178
179 delete(key: string): Promise<void> {
208
209 private setValueInStorage(key: string, fullKey: string, value: string, storageService: IStorageService): void {
210 > if (this.useSharedStorage(key)) { secrets.ts
211 this._logService.trace(`[SecretStorageService] Setting value for cross-app shared secret: ${fullKey}`);
212 storageService.store(fullKey, value, StorageScope.APPLICATION_SHARED, StorageTarget.MACHINE);
214 }
215 storageService.store(fullKey, value, StorageScope.APPLICATION, StorageTarget.MACHINE);
216 > } secrets.ts
217
218 private async initialize(): Promise<IStorageService> {
219 > let storageService; secrets.ts
220 > if (!this._useInMemoryStorage && await this._encryptionService.isEncryptionAvailable()) {
221 this._logService.trace(`[SecretStorageService] Encryption is available, using persisted storage`);
222 this._type = 'persisted';
223 storageService = this._storageService;
224 > } else { secrets.ts
225 // If we already have an in-memory storage service, we don't need to recreate it
226 if (this._type === 'in-memory') {
231 storageService = this._register(new InMemoryStorageService());
232 }
233 > secrets.ts
234 > this._onDidChangeValueDisposable.clear();
235 > this._onDidChangeValueDisposable.add(Event.any<IStorageValueChangeEvent>(
236 > storageService.onDidChangeValue(StorageScope.APPLICATION, undefined, this._onDidChangeValueDisposable),
237 > storageService.onDidChangeValue(StorageScope.APPLICATION_SHARED, undefined, this._onDidChangeValueDisposable),
238 > )(e => {
239 > this.onDidChangeValue(e.key);
240 > }));
241 > return storageService;
242 > }
243
244 protected reinitialize(): void {
247
248 private onDidChangeValue(key: string): void {
249 > if (!key.startsWith(SECRET_STORAGE_PREFIX)) { secrets.ts
250 return;
251 }
252 > secrets.ts
253 > const secretKey = key.slice(SECRET_STORAGE_PREFIX.length);
254 >
255 > this._logService.trace(`[SecretStorageService] Notifying change in value for secret: ${secretKey}`);
256 > this.onDidChangeSecretEmitter.fire(secretKey);
257 > }
258 }