@@ -8,17 +8,29 @@ import {
88 ISecretsList ,
99 ISecretsManager
1010} from './token' ;
11+ import { ISignal , Signal } from '@lumino/signaling' ;
12+
13+ interface IOptions {
14+ showSecretFields ?: boolean ;
15+ }
1116
1217/**
1318 * The default secrets manager.
1419 */
1520export class SecretsManager implements ISecretsManager {
1621 /**
17- * the secrets manager constructor.
22+ * The secrets manager constructor.
1823 */
19- constructor ( ) {
24+ constructor ( options : IOptions ) {
2025 this . _storing = new PromiseDelegate < void > ( ) ;
2126 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+ }
2234 }
2335
2436 /**
@@ -33,14 +45,44 @@ export class SecretsManager implements ISecretsManager {
3345 this . _ready . resolve ( ) ;
3446 }
3547
48+ /**
49+ * A promise that resolves when the connector is set.
50+ */
3651 get ready ( ) : Promise < void > {
3752 return this . _ready . promise ;
3853 }
3954
55+ /**
56+ * A promise that locks the connector access during storage.
57+ */
4058 protected get storing ( ) : Promise < void > {
4159 return this . _storing . promise ;
4260 }
4361
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+
4486 /**
4587 * Get a secret given its namespace and ID.
4688 */
@@ -179,6 +221,7 @@ export class SecretsManager implements ISecretsManager {
179221
180222 private _ready = new PromiseDelegate < void > ( ) ;
181223 private _storing : PromiseDelegate < void > ;
224+ private _fieldsVisibilityChanged = new Signal < this, boolean > ( this ) ;
182225}
183226
184227/**
@@ -293,7 +336,7 @@ namespace Private {
293336 }
294337
295338 /**
296- * Actually fetch the secret from the connector.
339+ * Fetch the secret from the connector.
297340 */
298341 export async function get ( id : string ) : Promise < ISecret | undefined > {
299342 if ( ! connector ?. fetch ) {
@@ -303,7 +346,7 @@ namespace Private {
303346 }
304347
305348 /**
306- * Actually list the secret from the connector.
349+ * List the secret from the connector.
307350 */
308351 export async function list (
309352 namespace : string
@@ -314,7 +357,7 @@ namespace Private {
314357 return connector . list ( namespace ) ;
315358 }
316359 /**
317- * Actually save the secret using the connector.
360+ * Save the secret using the connector.
318361 */
319362 export async function set ( id : string , secret : ISecret ) : Promise < any > {
320363 if ( ! connector ?. save ) {
@@ -324,7 +367,7 @@ namespace Private {
324367 }
325368
326369 /**
327- * Actually remove the secrets using the connector.
370+ * Remove the secrets using the connector.
328371 */
329372 export async function remove ( id : string ) : Promise < void > {
330373 if ( ! connector ?. remove ) {
@@ -333,6 +376,32 @@ namespace Private {
333376 return connector . remove ( id ) ;
334377 }
335378
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+ */
336405 export type SecretPath = {
337406 namespace : string ;
338407 id : string ;
0 commit comments