Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update order of keyvaultsetting #70

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/Altinn.Auth.AuditLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ async Task ConfigurePostgreSql(ConfigurationManager config)
{
ConsoleTraceService traceService = new ConsoleTraceService { IsDebugEnabled = true };

KeyVaultSettings keyVaultSettings = new KeyVaultSettings();

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

SecretClient client = new SecretClient(new Uri(keyVaultSettings.SecretUri), new DefaultAzureCredential());
KeyVaultSecret dbAdminConnectionsecret = await client.GetSecretAsync(postgreDbAdminConnectionStringSecretName);
postgreDbAdminConnectionString = dbAdminConnectionsecret.Value;

KeyVaultSecret dbConnectionsecret = await client.GetSecretAsync(postgreDbConnectionStringSecretName);
postgreDbConnectionString = dbConnectionsecret.Value;

string workspacePath = Path.Combine(Environment.CurrentDirectory, builder.Configuration.GetValue<string>("PostgreSQLSettings:WorkspacePath"));
if (builder.Environment.IsDevelopment())
{
Expand Down Expand Up @@ -181,11 +170,11 @@ async Task SetConfigurationProviders(ConfigurationManager config)

if (!builder.Environment.IsDevelopment())
{
await ConnectToKeyVaultAndSetApplicationInsights(config);
await ConfigureKeyVaultSettings(config);
}
}

async Task ConnectToKeyVaultAndSetApplicationInsights(ConfigurationManager config)
async Task ConfigureKeyVaultSettings(ConfigurationManager config)
{
logger.LogInformation("Program // Connect to key vault and set up application insights");

Expand All @@ -197,10 +186,16 @@ async Task ConnectToKeyVaultAndSetApplicationInsights(ConfigurationManager confi
SecretClient client = new SecretClient(new Uri(keyVaultSettings.SecretUri), new DefaultAzureCredential());
KeyVaultSecret secret = await client.GetSecretAsync(applicationInsightsKeySecretName);
applicationInsightsConnectionString = string.Format("InstrumentationKey={0}", secret.Value);

KeyVaultSecret dbAdminConnectionsecret = await client.GetSecretAsync(postgreDbAdminConnectionStringSecretName);
postgreDbAdminConnectionString = dbAdminConnectionsecret.Value;

KeyVaultSecret dbConnectionsecret = await client.GetSecretAsync(postgreDbConnectionStringSecretName);
postgreDbConnectionString = dbConnectionsecret.Value;
}
catch (Exception vaultException)
{
logger.LogError(vaultException, "Unable to read application insights key.");
logger.LogError(vaultException, "Unable to read key vault settings.");
}

try
Expand Down
Loading