|
1 | | -namespace Neolution.Extensions.Configuration.GoogleSecrets |
| 1 | +namespace Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore |
2 | 2 | { |
3 | 3 | using System; |
4 | 4 | using Microsoft.AspNetCore.Builder; |
5 | 5 |
|
6 | 6 | /// <summary> |
7 | | - /// WebBuilder extensions for Google Secrets |
| 7 | + /// Google Secrets extensions for <see cref="WebApplicationBuilder"/>. |
8 | 8 | /// </summary> |
9 | 9 | public static class WebApplicationBuilderExtensions |
10 | 10 | { |
11 | 11 | /// <summary> |
12 | | - /// Gets the value of the environment variable of the google secrets project which decides where to load secrets from. |
13 | | - /// </summary> |
14 | | - /// <value> |
15 | | - /// The string with the project name |
16 | | - /// </value> |
17 | | - private static string GoogleSecretsProjectName => Environment.GetEnvironmentVariable("GOOGLE_SECRETS_PROJECT") ?? "default-project-goes-here"; |
18 | | - |
19 | | - /// <summary> |
20 | | - /// Gets a value indicating whether to load google secrets or not |
21 | | - /// </summary> |
22 | | - /// <value> |
23 | | - /// <c>true</c> to load google secrets; otherwise not. |
24 | | - /// </value> |
25 | | - private static bool LoadGoogleSecrets => bool.TryParse(Environment.GetEnvironmentVariable("LOAD_GOOGLE_SECRETS"), out var result) && result; |
26 | | - |
27 | | - /// <summary> |
28 | | - /// Adds the Google secrets. |
| 12 | + /// Adds the Google secrets to the <see cref="WebApplicationBuilder"/>. |
| 13 | + /// Uses the GOOGLE_SECRETS_PROJECT environment variable as the project name. |
29 | 14 | /// </summary> |
30 | 15 | /// <param name="builder">The builder.</param> |
31 | 16 | public static void AddGoogleSecrets(this WebApplicationBuilder builder) |
32 | 17 | { |
33 | | - if (builder == null) |
34 | | - { |
35 | | - throw new ArgumentNullException(nameof(builder)); |
36 | | - } |
| 18 | + ArgumentNullException.ThrowIfNull(builder); |
37 | 19 |
|
38 | | - // Configure app configuration to add Google Secrets if applicable |
39 | | - if (LoadGoogleSecrets) |
| 20 | + // Configure app configuration to add Google Secrets if environment variable is set |
| 21 | + var googleSecretProject = Environment.GetEnvironmentVariable(EnvironmentVariableNames.GoogleSecretsProject); |
| 22 | + if (!string.IsNullOrWhiteSpace(googleSecretProject)) |
40 | 23 | { |
41 | 24 | builder.Configuration.AddGoogleSecrets(options => |
42 | 25 | { |
43 | | - options.ProjectName = GoogleSecretsProjectName; |
| 26 | + options.ProjectName = googleSecretProject; |
44 | 27 | }); |
45 | 28 | } |
46 | 29 | } |
|
0 commit comments