Skip to content

Commit e11cbd0

Browse files
update
1 parent 6d8c41f commit e11cbd0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/keyvault/AzureKeyVaultSecretProvider.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ export class AzureKeyVaultSecretProvider {
3131
}
3232

3333
async getSecretValue(secretIdentifier: KeyVaultSecretIdentifier): Promise<unknown> {
34-
// The map key is a combination of sourceId and version: "{sourceId}\n{version}"
34+
// The map key is a combination of sourceId and version: "{sourceId}\n{version}".
3535
const identifierKey = `${secretIdentifier.sourceId}\n${secretIdentifier.version ?? ""}`;
36+
37+
// If the secret has a version, always use the cached value if available.
38+
if (secretIdentifier.version && this.#cachedSecretValue.has(identifierKey)) {
39+
return this.#cachedSecretValue.get(identifierKey);
40+
}
41+
3642
if (this.#refreshTimer && !this.#refreshTimer.canRefresh()) {
37-
// return the cached secret value if it exists
43+
// If the refresh interval is not expired, return the cached value if available.
3844
if (this.#cachedSecretValue.has(identifierKey)) {
39-
const cachedValue = this.#cachedSecretValue.get(identifierKey);
40-
return cachedValue;
45+
return this.#cachedSecretValue.get(identifierKey);
4146
}
42-
// not found in cache, get the secret value from key vault
43-
const secretValue = await this.#getSecretValueFromKeyVault(secretIdentifier);
44-
this.#cachedSecretValue.set(identifierKey, secretValue);
45-
return secretValue;
4647
}
4748

48-
// Always reload the secret value from key vault when the refresh timer expires.
49+
// Fallback to fetching the secret value from Key Vault.
4950
const secretValue = await this.#getSecretValueFromKeyVault(secretIdentifier);
5051
this.#cachedSecretValue.set(identifierKey, secretValue);
5152
return secretValue;

0 commit comments

Comments
 (0)