@@ -8,17 +8,29 @@ import {
8
8
ISecretsList ,
9
9
ISecretsManager
10
10
} from './token' ;
11
+ import { ISignal , Signal } from '@lumino/signaling' ;
12
+
13
+ interface IOptions {
14
+ showSecretFields ?: boolean ;
15
+ }
11
16
12
17
/**
13
18
* The default secrets manager.
14
19
*/
15
20
export class SecretsManager implements ISecretsManager {
16
21
/**
17
- * the secrets manager constructor.
22
+ * The secrets manager constructor.
18
23
*/
19
- constructor ( ) {
24
+ constructor ( options : IOptions ) {
20
25
this . _storing = new PromiseDelegate < void > ( ) ;
21
26
this . _storing . resolve ( ) ;
27
+ Private . setSecretFieldsVisibility ( options . showSecretFields ?? false ) ;
28
+
29
+ // If the secret fields are hidden from constructor, this setting comes from
30
+ // PageConfig, we need to lock the fields visibility.
31
+ if ( options . showSecretFields === false ) {
32
+ Private . lockFieldsVisibility ( ) ;
33
+ }
22
34
}
23
35
24
36
/**
@@ -33,14 +45,44 @@ export class SecretsManager implements ISecretsManager {
33
45
this . _ready . resolve ( ) ;
34
46
}
35
47
48
+ /**
49
+ * A promise that resolves when the connector is set.
50
+ */
36
51
get ready ( ) : Promise < void > {
37
52
return this . _ready . promise ;
38
53
}
39
54
55
+ /**
56
+ * A promise that locks the connector access during storage.
57
+ */
40
58
protected get storing ( ) : Promise < void > {
41
59
return this . _storing . promise ;
42
60
}
43
61
62
+ /**
63
+ * A signal emitting when the field visibility setting has changed.
64
+ */
65
+ get fieldVisibilityChanged ( ) : ISignal < this, boolean > {
66
+ return this . _fieldsVisibilityChanged ;
67
+ }
68
+
69
+ /**
70
+ * Get the visibility of the secret fields.
71
+ */
72
+ get secretFieldsVisibility ( ) : boolean {
73
+ return Private . getSecretFieldsVisibility ( ) ;
74
+ }
75
+
76
+ /**
77
+ * Set the visibility of the secret fields.
78
+ * The visibility cannot be set if it is locked (from page config).
79
+ */
80
+ set secretFieldsVisibility ( value : boolean ) {
81
+ if ( Private . setSecretFieldsVisibility ( value ) ) {
82
+ this . _fieldsVisibilityChanged . emit ( Private . getSecretFieldsVisibility ( ) ) ;
83
+ }
84
+ }
85
+
44
86
/**
45
87
* Get a secret given its namespace and ID.
46
88
*/
@@ -179,6 +221,7 @@ export class SecretsManager implements ISecretsManager {
179
221
180
222
private _ready = new PromiseDelegate < void > ( ) ;
181
223
private _storing : PromiseDelegate < void > ;
224
+ private _fieldsVisibilityChanged = new Signal < this, boolean > ( this ) ;
182
225
}
183
226
184
227
/**
@@ -293,7 +336,7 @@ namespace Private {
293
336
}
294
337
295
338
/**
296
- * Actually fetch the secret from the connector.
339
+ * Fetch the secret from the connector.
297
340
*/
298
341
export async function get ( id : string ) : Promise < ISecret | undefined > {
299
342
if ( ! connector ?. fetch ) {
@@ -303,7 +346,7 @@ namespace Private {
303
346
}
304
347
305
348
/**
306
- * Actually list the secret from the connector.
349
+ * List the secret from the connector.
307
350
*/
308
351
export async function list (
309
352
namespace : string
@@ -314,7 +357,7 @@ namespace Private {
314
357
return connector . list ( namespace ) ;
315
358
}
316
359
/**
317
- * Actually save the secret using the connector.
360
+ * Save the secret using the connector.
318
361
*/
319
362
export async function set ( id : string , secret : ISecret ) : Promise < any > {
320
363
if ( ! connector ?. save ) {
@@ -324,7 +367,7 @@ namespace Private {
324
367
}
325
368
326
369
/**
327
- * Actually remove the secrets using the connector.
370
+ * Remove the secrets using the connector.
328
371
*/
329
372
export async function remove ( id : string ) : Promise < void > {
330
373
if ( ! connector ?. remove ) {
@@ -333,6 +376,32 @@ namespace Private {
333
376
return connector . remove ( id ) ;
334
377
}
335
378
379
+ /**
380
+ * Lock the fields visibility value.
381
+ */
382
+ let fieldsVisibilityLocked = false ;
383
+ export function lockFieldsVisibility ( ) {
384
+ fieldsVisibilityLocked = true ;
385
+ }
386
+
387
+ /**
388
+ * Get/set the fields visibility.
389
+ */
390
+ let secretFieldsVisibility = false ;
391
+ export function getSecretFieldsVisibility ( ) : boolean {
392
+ return secretFieldsVisibility ;
393
+ }
394
+ export function setSecretFieldsVisibility ( value : boolean ) : boolean {
395
+ if ( ! fieldsVisibilityLocked && value !== secretFieldsVisibility ) {
396
+ secretFieldsVisibility = value ;
397
+ return true ;
398
+ }
399
+ return false ;
400
+ }
401
+
402
+ /**
403
+ * The secret path type.
404
+ */
336
405
export type SecretPath = {
337
406
namespace : string ;
338
407
id : string ;
0 commit comments