@@ -32,6 +32,15 @@ export type ConnectionsFromStorage = {
32
32
[ connectionId : string ] : StoreConnectionInfo ;
33
33
} ;
34
34
35
+ export const SecretStorageLocation = {
36
+ Keytar : 'vscode.Keytar' ,
37
+ SecretStorage : 'vscode.SecretStorage' ,
38
+ } as const ;
39
+
40
+ export type SecretStorageLocationType =
41
+ | typeof SecretStorageLocation . Keytar
42
+ | typeof SecretStorageLocation . SecretStorage ;
43
+
35
44
interface StorageVariableContents {
36
45
[ StorageVariables . GLOBAL_USER_ID ] : string ;
37
46
[ StorageVariables . GLOBAL_ANONYMOUS_ID ] : string ;
@@ -48,11 +57,14 @@ export default class StorageController {
48
57
[ StorageLocation . WORKSPACE ] : vscode . Memento ;
49
58
} ;
50
59
60
+ _secretStorage : vscode . SecretStorage ;
61
+
51
62
constructor ( context : vscode . ExtensionContext ) {
52
63
this . _storage = {
53
64
[ StorageLocation . GLOBAL ] : context . globalState ,
54
65
[ StorageLocation . WORKSPACE ] : context . workspaceState ,
55
66
} ;
67
+ this . _secretStorage = context . secrets ;
56
68
}
57
69
58
70
get < T extends StoredVariableName > (
@@ -123,9 +135,9 @@ export default class StorageController {
123
135
) ;
124
136
}
125
137
126
- async saveConnection (
127
- storeConnectionInfo : StoreConnectionInfo
128
- ) : Promise < StoreConnectionInfo > {
138
+ async saveConnection < T extends StoreConnectionInfo > (
139
+ storeConnectionInfo : T
140
+ ) : Promise < T > {
129
141
const dontShowSaveLocationPrompt = vscode . workspace
130
142
. getConfiguration ( 'mdb.connectionSaving' )
131
143
. get ( 'hideOptionToChooseWhereToSaveNewConnections' ) ;
@@ -243,4 +255,17 @@ export default class StorageController {
243
255
244
256
return StorageLocation . NONE ;
245
257
}
258
+
259
+ async getSecret ( key : string ) : Promise < string | null > {
260
+ return ( await this . _secretStorage . get ( key ) ) ?? null ;
261
+ }
262
+
263
+ async deleteSecret ( key : string ) : Promise < boolean > {
264
+ await this . _secretStorage . delete ( key ) ;
265
+ return true ;
266
+ }
267
+
268
+ async setSecret ( key : string , value : string ) : Promise < void > {
269
+ await this . _secretStorage . store ( key , value ) ;
270
+ }
246
271
}
0 commit comments