Skip to content

Commit

Permalink
read keyvaultsettings (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
simen-rekkedal authored Apr 26, 2024
1 parent 10c102b commit a309bdc
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async Task SetConfigurationProviders(ConfigurationManager config)
if (!builder.Environment.IsDevelopment())
{
await ConfigureApplicationInsights(config);
await ConfigureKeyVaultSettings(config);
}
}

Expand Down Expand Up @@ -152,4 +153,20 @@ void ConfigureAppliationInsightsServices()

logger.LogInformation("Startup // ApplicationInsightsConnectionString = {applicationInsightsConnectionString}", applicationInsightsConnectionString);
}
}

async Task ConfigureKeyVaultSettings(ConfigurationManager config)
{
KeyVaultSettings keyVaultSettings = new KeyVaultSettings();

config.GetSection("KeyVaultSettings").Bind(keyVaultSettings);

try
{
config.AddAzureKeyVault(new Uri(keyVaultSettings.SecretUri), new DefaultAzureCredential());
}
catch (Exception vaultException)
{
logger.LogError(vaultException, "Unable to add key vault secrets to config.");
}
}

0 comments on commit a309bdc

Please sign in to comment.