private Dictionary<String, String> retrieveSecrets(bool cert)
{
Dictionary<string, string> keyValues = new Dictionary<string, string>();
KeyVaultClient kv;
if (cert)
{
kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken));
}
else
{
kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken));
}
List<string> secrets = new List<string>();
var values = kv.GetSecretsAsync(this.Configuration.GetSection("General").GetSection("KeyVaultURI").Value.ToString()).GetAwaiter().GetResult();
if (values != null && values.Value != null)
{
foreach (var m in values.Value)
secrets.Add(m.Identifier.Name);
}
while (values != null && !string.IsNullOrWhiteSpace(values.NextLink))
{
values = kv.GetSecretsNextAsync(values.NextLink).GetAwaiter().GetResult();
if (values != null && values.Value != null)
{
foreach (var m in values.Value)
secrets.Add(m.Identifier.Name);
}
}
foreach (var value in secrets)
{
var secret = kv.GetSecretAsync(this.Configuration.GetSection("General").GetSection("KeyVaultURI").Value.ToString(), value).GetAwaiter().GetResult();
keyValues.Add(value.Replace("-",":"), secret.Value);
}
return keyValues;
}