1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT license.
3
3
4
- import { AppConfigurationClient , ConfigurationSetting , ConfigurationSettingId , GetConfigurationSettingOptions , GetConfigurationSettingResponse , ListConfigurationSettingsOptions , featureFlagPrefix , isFeatureFlag } from "@azure/app-configuration" ;
4
+ import { AppConfigurationClient , ConfigurationSetting , ConfigurationSettingId , GetConfigurationSettingOptions , GetConfigurationSettingResponse , ListConfigurationSettingsOptions , featureFlagPrefix , isFeatureFlag , isSecretReference } from "@azure/app-configuration" ;
5
5
import { isRestError } from "@azure/core-rest-pipeline" ;
6
6
import { AzureAppConfiguration , ConfigurationObjectConstructionOptions } from "./AzureAppConfiguration.js" ;
7
7
import { AzureAppConfigurationOptions } from "./AzureAppConfigurationOptions.js" ;
@@ -83,6 +83,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
83
83
#ffRefreshInterval: number = DEFAULT_REFRESH_INTERVAL_IN_MS ;
84
84
#ffRefreshTimer: RefreshTimer ;
85
85
86
+ // Key Vault references
87
+ #resolveSecretInParallel: boolean = false ;
88
+
86
89
/**
87
90
* Selectors of key-values obtained from @see AzureAppConfigurationOptions.selectors
88
91
*/
@@ -163,6 +166,10 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
163
166
}
164
167
}
165
168
169
+ if ( options ?. keyVaultOptions ?. parallelSecretResolutionEnabled ) {
170
+ this . #resolveSecretInParallel = options . keyVaultOptions . parallelSecretResolutionEnabled ;
171
+ }
172
+
166
173
this . #adapters. push ( new AzureKeyVaultKeyValueAdapter ( options ?. keyVaultOptions ) ) ;
167
174
this . #adapters. push ( new JsonKeyValueAdapter ( ) ) ;
168
175
}
@@ -484,7 +491,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
484
491
*/
485
492
async #loadSelectedAndWatchedKeyValues( ) {
486
493
const keyValues : [ key : string , value : unknown ] [ ] = [ ] ;
487
- const loadedSettings = await this . #loadConfigurationSettings( ) ;
494
+ const loadedSettings : ConfigurationSetting [ ] = await this . #loadConfigurationSettings( ) ;
488
495
if ( this . #refreshEnabled && ! this . #watchAll) {
489
496
await this . #updateWatchedKeyValuesEtag( loadedSettings ) ;
490
497
}
@@ -494,11 +501,25 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
494
501
this . #aiConfigurationTracing. reset ( ) ;
495
502
}
496
503
497
- // adapt configuration settings to key-values
504
+ const secretResolutionPromises : Promise < void > [ ] = [ ] ;
498
505
for ( const setting of loadedSettings ) {
506
+ if ( this . #resolveSecretInParallel && isSecretReference ( setting ) ) {
507
+ // secret references are resolved asynchronously to improve performance
508
+ const secretResolutionPromise = this . #processKeyValue( setting )
509
+ . then ( ( [ key , value ] ) => {
510
+ keyValues . push ( [ key , value ] ) ;
511
+ } ) ;
512
+ secretResolutionPromises . push ( secretResolutionPromise ) ;
513
+ continue ;
514
+ }
515
+ // adapt configuration settings to key-values
499
516
const [ key , value ] = await this . #processKeyValue( setting ) ;
500
517
keyValues . push ( [ key , value ] ) ;
501
518
}
519
+ if ( secretResolutionPromises . length > 0 ) {
520
+ // wait for all secret resolution promises to be resolved
521
+ await Promise . all ( secretResolutionPromises ) ;
522
+ }
502
523
503
524
this . #clearLoadedKeyValues( ) ; // clear existing key-values in case of configuration setting deletion
504
525
for ( const [ k , v ] of keyValues ) {
@@ -543,7 +564,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
543
564
*/
544
565
async #loadFeatureFlags( ) {
545
566
const loadFeatureFlag = true ;
546
- const featureFlagSettings = await this . #loadConfigurationSettings( loadFeatureFlag ) ;
567
+ const featureFlagSettings : ConfigurationSetting [ ] = await this . #loadConfigurationSettings( loadFeatureFlag ) ;
547
568
548
569
if ( this . #requestTracingEnabled && this . #featureFlagTracing !== undefined ) {
549
570
// Reset old feature flag tracing in order to track the information present in the current response from server.
0 commit comments