/// <summary> /// Asynchronously retrieves the specified SecretString after calling <see cref="GetCachedSecret"/>. /// </summary> public async Task <String> GetSecretString(String secretId) { SecretCacheItem secret = GetCachedSecret(secretId); GetSecretValueResponse response = null; response = await secret.GetSecretValue(); return(response?.SecretString); }
/// <summary> /// Asynchronously retrieves the specified SecretBinary after calling <see cref="GetCachedSecret"/>. /// </summary> public async Task <byte[]> GetSecretBinary(String secretId) { SecretCacheItem secret = GetCachedSecret(secretId); GetSecretValueResponse response = null; response = await secret.GetSecretValue(); return(response?.SecretBinary?.ToArray()); }
/// <summary> /// Returns the cache entry corresponding to the specified secret if it exists in the cache. /// Otherwise, the secret value is fetched from Secrets Manager and a new cache entry is created. /// </summary> public SecretCacheItem GetCachedSecret(string secretId) { SecretCacheItem secret = cache.Get <SecretCacheItem>(secretId); if (secret == null) { secret = cache.Set <SecretCacheItem>(secretId, new SecretCacheItem(secretId, secretsManager, config), cacheItemPolicy); if (cache.Count > config.MaxCacheSize) { // Trim cache size to MaxCacheSize, evicting entries using LRU. cache.Compact((double)(cache.Count - config.MaxCacheSize) / cache.Count); } } return(secret); }