Skip to content

Commit e8dd7f8

Browse files
update
1 parent 349d678 commit e8dd7f8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/keyvault/AzureKeyVaultSecretProvider.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class AzureKeyVaultSecretProvider {
1010
#keyVaultOptions: KeyVaultOptions | undefined;
1111
#secretRefreshTimer: RefreshTimer | undefined;
1212
#secretClients: Map<string, SecretClient>; // map key vault hostname to corresponding secret client
13-
#cachedSecretValue: Map<string, any> = new Map<string, any>(); // map secret identifier to secret value
13+
#cachedSecretValues: Map<string, any> = new Map<string, any>(); // map secret identifier to secret value
1414

1515
constructor(keyVaultOptions: KeyVaultOptions | undefined, refreshTimer?: RefreshTimer) {
1616
if (keyVaultOptions?.secretRefreshIntervalInMs !== undefined) {
@@ -33,26 +33,20 @@ export class AzureKeyVaultSecretProvider {
3333
async getSecretValue(secretIdentifier: KeyVaultSecretIdentifier): Promise<unknown> {
3434
const identifierKey = secretIdentifier.sourceId;
3535

36-
// If the secret has a version, always use the cached value if available.
37-
if (secretIdentifier.version && this.#cachedSecretValue.has(identifierKey)) {
38-
return this.#cachedSecretValue.get(identifierKey);
39-
}
40-
41-
if (this.#secretRefreshTimer && !this.#secretRefreshTimer.canRefresh()) {
42-
// If the refresh interval is not expired, return the cached value if available.
43-
if (this.#cachedSecretValue.has(identifierKey)) {
44-
return this.#cachedSecretValue.get(identifierKey);
45-
}
36+
// If the refresh interval is not expired, return the cached value if available.
37+
if (this.#cachedSecretValues.has(identifierKey) &&
38+
(!this.#secretRefreshTimer || !this.#secretRefreshTimer.canRefresh())) {
39+
return this.#cachedSecretValues.get(identifierKey);
4640
}
4741

4842
// Fallback to fetching the secret value from Key Vault.
4943
const secretValue = await this.#getSecretValueFromKeyVault(secretIdentifier);
50-
this.#cachedSecretValue.set(identifierKey, secretValue);
44+
this.#cachedSecretValues.set(identifierKey, secretValue);
5145
return secretValue;
5246
}
5347

5448
clearCache(): void {
55-
this.#cachedSecretValue.clear();
49+
this.#cachedSecretValues.clear();
5650
}
5751

5852
async #getSecretValueFromKeyVault(secretIdentifier: KeyVaultSecretIdentifier): Promise<unknown> {

0 commit comments

Comments
 (0)