From 6d7b035933fde7104bad8a53d6690ade81279dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=CA=9C=E1=B4=80=C9=B4?= Date: Thu, 11 Jul 2024 09:59:53 +0200 Subject: [PATCH] #141 wi-profile: Configuration for Workload Identity (#164) * wi-profile: giving access to platform keyvault * string interpolation removed --- src/Altinn.Profile/Program.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Altinn.Profile/Program.cs b/src/Altinn.Profile/Program.cs index e0d16a4..8c84cd7 100644 --- a/src/Altinn.Profile/Program.cs +++ b/src/Altinn.Profile/Program.cs @@ -96,21 +96,16 @@ async Task ConnectToKeyVaultAndSetApplicationInsights(ConfigurationManager confi { KeyVaultSettings keyVaultSettings = new(); config.GetSection("kvSetting").Bind(keyVaultSettings); - if (!string.IsNullOrEmpty(keyVaultSettings.ClientId) && - !string.IsNullOrEmpty(keyVaultSettings.TenantId) && - !string.IsNullOrEmpty(keyVaultSettings.ClientSecret) && - !string.IsNullOrEmpty(keyVaultSettings.SecretUri)) + if (!string.IsNullOrEmpty(keyVaultSettings.SecretUri)) { - logger.LogInformation("Program // Configure key vault client // App"); - Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", keyVaultSettings.ClientId); - Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", keyVaultSettings.ClientSecret); - Environment.SetEnvironmentVariable("AZURE_TENANT_ID", keyVaultSettings.TenantId); - var azureCredentials = new DefaultAzureCredential(); + logger.LogInformation("Program // Set app insights connection string // App"); - config.AddAzureKeyVault(new Uri(keyVaultSettings.SecretUri), azureCredentials); + DefaultAzureCredential azureCredentials = new(); SecretClient client = new(new Uri(keyVaultSettings.SecretUri), azureCredentials); + config.AddAzureKeyVault(new Uri(keyVaultSettings.SecretUri), azureCredentials); + try { KeyVaultSecret keyVaultSecret = await client.GetSecretAsync(VaultApplicationInsightsKey);