Skip to content

Commit

Permalink
Remove project path dependency for fetching secret
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadUsama-afk-equinor committed Dec 6, 2023
1 parent 839ad33 commit 51ebf9b
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions backend/api/EventHandlers/InspectionFindingEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

string adaptiveCardJson = GenerateAdaptiveCard(messageString);

string url = GetWebhookURL("TeamsInspectionFindingsWebhook");
string url = GetWebhookURL(configuration, "TeamsInspectionFindingsWebhook");

var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Expand Down Expand Up @@ -138,23 +138,10 @@ public static string GenerateAdaptiveCard(string messageContent)
return adaptiveCardJson;
}

public static string GetWebhookURL(string secretName)
public static string GetWebhookURL(IConfiguration configuration, string secretName)
{
string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")!;

string projectPath = Path.Combine(
Directory.GetParent(Directory.GetCurrentDirectory())!.FullName,
"api"
);

var config = new ConfigurationBuilder()
.SetBasePath(projectPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment}.json", optional: true)
.AddEnvironmentVariables()
.Build();

string? keyVaultUri = config.GetSection("KeyVault")["VaultUri"] ?? throw new KeyNotFoundException("No key vault in config");
string? keyVaultUri = configuration.GetSection("KeyVault")["VaultUri"] ?? throw new KeyNotFoundException("No key vault in config");

var keyVault = new SecretClient(
new Uri(keyVaultUri),
Expand Down

0 comments on commit 51ebf9b

Please sign in to comment.