|
5 | 5 | using Microsoft.Azure.Functions.Worker; |
6 | 6 | using Microsoft.Azure.Functions.Worker.Builder; |
7 | 7 | using Microsoft.Azure.Functions.Worker.OpenTelemetry; |
| 8 | +using Microsoft.Extensions.Configuration; |
| 9 | +using Microsoft.Extensions.Configuration.AzureAppConfiguration; |
8 | 10 | using Microsoft.Extensions.DependencyInjection; |
9 | 11 | using Microsoft.Extensions.Hosting; |
10 | 12 | using OpenTelemetry; |
|
13 | 15 |
|
14 | 16 | builder.ConfigureFunctionsWebApplication(); |
15 | 17 |
|
| 18 | +// ---------------- Azure App Configuration ---------------- |
| 19 | +// Wires builder.Configuration to read keys seeded by infra/modules/appconfig.bicep. Keys are |
| 20 | +// stored with the "blkmon:" prefix and an environment-name label (e.g. dev / prod); TrimKeyPrefix |
| 21 | +// strips the prefix so callers can read "Encryption:KeyVault:Uri" directly. ConfigureKeyVault |
| 22 | +// resolves App Configuration KV-references (e.g. SQL connection string) via the same managed |
| 23 | +// identity. Without this block, the Phase 2 KeyVaultKekProvider and Phase 3 DekSealingService |
| 24 | +// would silently fail to register because their config keys would always resolve to null. |
| 25 | + |
| 26 | +var appConfigEndpoint = builder.Configuration["AzureAppConfig:Endpoint"] |
| 27 | + ?? Environment.GetEnvironmentVariable("AzureAppConfig__Endpoint"); |
| 28 | +var envLabel = builder.Configuration["AzureAppConfig:Label"] |
| 29 | + ?? Environment.GetEnvironmentVariable("AZURE_ENV_NAME") |
| 30 | + ?? builder.Environment.EnvironmentName; |
| 31 | + |
| 32 | +if (!string.IsNullOrEmpty(appConfigEndpoint)) |
| 33 | +{ |
| 34 | + var appConfigCredential = new DefaultAzureCredential(); |
| 35 | + builder.Configuration.AddAzureAppConfiguration(options => |
| 36 | + { |
| 37 | + options |
| 38 | + .Connect(new Uri(appConfigEndpoint), appConfigCredential) |
| 39 | + .Select("blkmon:*", LabelFilter.Null) |
| 40 | + .Select("blkmon:*", envLabel) |
| 41 | + .TrimKeyPrefix("blkmon:") |
| 42 | + .ConfigureKeyVault(kv => kv.SetCredential(appConfigCredential)); |
| 43 | + }); |
| 44 | +} |
| 45 | + |
16 | 46 | if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"))) |
17 | 47 | { |
18 | 48 | builder.Services.AddOpenTelemetry() |
|
0 commit comments