|
2 | 2 | { |
3 | 3 | public static class ConfigurationBuilderExtensions |
4 | 4 | { |
5 | | - /// <summary> |
6 | | - /// Creates the AZURE_CLIENT_ID and AZURE_TENANT_ID configuration values for the |
7 | | - /// <see href="https://docs.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet">Environment Credentials</see> |
8 | | - /// used by the application when dockerized. |
9 | | - /// </summary> |
10 | | - /// <param name="builder"></param> |
11 | | - /// <returns></returns> |
12 | | - public static void AddAppSettingsEnvironmentVariables(this WebApplicationBuilder builder) |
13 | | - { |
14 | | - string? clientId = builder |
15 | | - .Configuration.GetSection("AzureAd") |
16 | | - .GetValue<string?>("ClientId"); |
17 | | - if (clientId is not null) |
18 | | - { |
19 | | - Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", clientId); |
20 | | - Console.WriteLine("'AZURE_CLIENT_ID' set to " + clientId); |
21 | | - } |
22 | | - |
23 | | - string? tenantId = builder |
24 | | - .Configuration.GetSection("AzureAd") |
25 | | - .GetValue<string?>("TenantId"); |
26 | | - if (tenantId is not null) |
27 | | - { |
28 | | - Environment.SetEnvironmentVariable("AZURE_TENANT_ID", tenantId); |
29 | | - Console.WriteLine("'AZURE_TENANT_ID' set to " + tenantId); |
30 | | - } |
31 | | - } |
32 | | - |
33 | | - /// <summary> |
34 | | - /// Creates if don't already exist/sets all the configuration variables present on the .env file for the |
35 | | - /// <see href="https://docs.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet">Environment Credentials</see> |
36 | | - /// used by the application when dockerized. |
37 | | - /// </summary> |
38 | | - /// <param name="builder"></param> |
39 | | - /// <param name="filePath"></param> |
40 | | - /// <returns></returns> |
41 | | - public static void AddDotEnvironmentVariables( |
42 | | - this WebApplicationBuilder builder, |
43 | | - string filePath |
44 | | - ) |
45 | | - { |
46 | | - if (!File.Exists(filePath)) |
47 | | - return; |
48 | | - |
49 | | - foreach (string line in File.ReadAllLines(filePath)) |
50 | | - { |
51 | | - string[] parts = line.Split('=', StringSplitOptions.RemoveEmptyEntries); |
52 | | - |
53 | | - if (parts.Length == 0 || parts[0].StartsWith('#')) |
54 | | - continue; |
55 | | - |
56 | | - Environment.SetEnvironmentVariable(parts[0], parts[1]); |
57 | | - } |
58 | | - |
59 | | - builder.Configuration.AddEnvironmentVariables(); |
60 | | - } |
61 | | - |
62 | 5 | /// <summary> |
63 | 6 | /// Configures the logger used by the application |
64 | 7 | /// </summary> |
|
0 commit comments