@@ -10,19 +10,20 @@ export class AzureKeyVaultKeyValueAdapter implements IKeyValueAdapter {
1010 /**
1111 * Map vault hostname to corresponding secret client.
1212 */
13- private secretClients : Map < string , SecretClient > ;
13+ #secretClients: Map < string , SecretClient > ;
14+ #keyVaultOptions: KeyVaultOptions | undefined ;
1415
15- constructor (
16- private keyVaultOptions : KeyVaultOptions | undefined
17- ) { }
16+ constructor ( keyVaultOptions : KeyVaultOptions | undefined ) {
17+ this . # keyVaultOptions = keyVaultOptions ;
18+ }
1819
19- public canProcess ( setting : ConfigurationSetting ) : boolean {
20+ canProcess ( setting : ConfigurationSetting ) : boolean {
2021 return isSecretReference ( setting ) ;
2122 }
2223
23- public async processKeyValue ( setting : ConfigurationSetting ) : Promise < [ string , unknown ] > {
24+ async processKeyValue ( setting : ConfigurationSetting ) : Promise < [ string , unknown ] > {
2425 // TODO: cache results to save requests.
25- if ( ! this . keyVaultOptions ) {
26+ if ( ! this . # keyVaultOptions) {
2627 throw new Error ( "Configure keyVaultOptions to resolve Key Vault Reference(s)." ) ;
2728 }
2829
@@ -31,37 +32,37 @@ export class AzureKeyVaultKeyValueAdapter implements IKeyValueAdapter {
3132 parseSecretReference ( setting ) . value . secretId
3233 ) ;
3334
34- const client = this . getSecretClient ( new URL ( vaultUrl ) ) ;
35+ const client = this . # getSecretClient( new URL ( vaultUrl ) ) ;
3536 if ( client ) {
3637 // TODO: what if error occurs when reading a key vault value? Now it breaks the whole load.
3738 const secret = await client . getSecret ( secretName , { version } ) ;
3839 return [ setting . key , secret . value ] ;
3940 }
4041
41- if ( this . keyVaultOptions . secretResolver ) {
42- return [ setting . key , await this . keyVaultOptions . secretResolver ( new URL ( sourceId ) ) ] ;
42+ if ( this . # keyVaultOptions. secretResolver ) {
43+ return [ setting . key , await this . # keyVaultOptions. secretResolver ( new URL ( sourceId ) ) ] ;
4344 }
4445
4546 throw new Error ( "No key vault credential or secret resolver callback configured, and no matching secret client could be found." ) ;
4647 }
4748
48- private getSecretClient ( vaultUrl : URL ) : SecretClient | undefined {
49- if ( this . secretClients === undefined ) {
50- this . secretClients = new Map ( ) ;
51- for ( const c of this . keyVaultOptions ?. secretClients ?? [ ] ) {
52- this . secretClients . set ( getHost ( c . vaultUrl ) , c ) ;
49+ # getSecretClient( vaultUrl : URL ) : SecretClient | undefined {
50+ if ( this . # secretClients === undefined ) {
51+ this . # secretClients = new Map ( ) ;
52+ for ( const c of this . # keyVaultOptions?. secretClients ?? [ ] ) {
53+ this . # secretClients. set ( getHost ( c . vaultUrl ) , c ) ;
5354 }
5455 }
5556
5657 let client : SecretClient | undefined ;
57- client = this . secretClients . get ( vaultUrl . host ) ;
58+ client = this . # secretClients. get ( vaultUrl . host ) ;
5859 if ( client !== undefined ) {
5960 return client ;
6061 }
6162
62- if ( this . keyVaultOptions ?. credential ) {
63- client = new SecretClient ( vaultUrl . toString ( ) , this . keyVaultOptions . credential ) ;
64- this . secretClients . set ( vaultUrl . host , client ) ;
63+ if ( this . # keyVaultOptions?. credential ) {
64+ client = new SecretClient ( vaultUrl . toString ( ) , this . # keyVaultOptions. credential ) ;
65+ this . # secretClients. set ( vaultUrl . host , client ) ;
6566 return client ;
6667 }
6768
0 commit comments