Make _creds static, and log whether we're using a cached version to ensure that making it static prevents constant re-fetching.

This commit is contained in:
Matt Galbraith 2020-06-22 14:57:02 -07:00
Родитель 43fa94646f
Коммит aaeab5a9a9
1 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.DotNet.HelixPoolProvider
private IConfiguration _configuration;
private ILogger _logger;
private ConcurrentDictionary<string, string> _creds = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static ConcurrentDictionary<string, string> _creds = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
public Config(IConfiguration config, ILoggerFactory loggerFactory)
{
@ -64,10 +64,12 @@ namespace Microsoft.DotNet.HelixPoolProvider
string currentSecret;
if (_creds.TryGetValue(secretName, out currentSecret))
{
_logger.LogInformation($"Successfully fetched cached value for secret '{secretName}'");
return currentSecret;
}
else
{
_logger.LogInformation($"Fetching value for secret '{secretName}' from Key Vault");
AzureServiceTokenProvider tokenProvider = new AzureServiceTokenProvider();
try
{