Skip to content

Commit aa6583a

Browse files
committed
fixes
1 parent 15fa891 commit aa6583a

6 files changed

Lines changed: 55 additions & 30 deletions

GoogleSecrets/ConfigurationBuilderExtensions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,29 @@
99
public static class ConfigurationBuilderExtensions
1010
{
1111
/// <summary>
12-
/// Adds the google secrets.
12+
/// Adds the Google secrets to the <see cref="ConfigurationBuilder"/>.
13+
/// If the GOOGLE_SECRETS_PROJECT environment variable is set, it will be used as the project name.
14+
/// </summary>
15+
/// <param name="configuration">The configuration.</param>
16+
/// <returns>The IConfigurationBuilder</returns>
17+
/// <exception cref="System.ArgumentNullException">options</exception>
18+
public static IConfigurationBuilder AddGoogleSecrets(this IConfigurationBuilder configuration)
19+
{
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))
23+
{
24+
return AddGoogleSecrets(configuration, options =>
25+
{
26+
options.ProjectName = googleSecretProject;
27+
});
28+
}
29+
30+
return AddGoogleSecrets(configuration, _ => { });
31+
}
32+
33+
/// <summary>
34+
/// Adds the Google secrets to the <see cref="ConfigurationBuilder"/>.
1335
/// </summary>
1436
/// <param name="configuration">The configuration.</param>
1537
/// <param name="options">The options.</param>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Neolution.Extensions.Configuration.GoogleSecrets
2+
{
3+
/// <summary>
4+
/// Contains the names of environment variables used for Google Secrets configuration.
5+
/// </summary>
6+
public static class EnvironmentVariableNames
7+
{
8+
/// <summary>
9+
/// The name of the environment variable where the google secrets project id is stored.
10+
/// </summary>
11+
public const string GoogleSecretsProject = "GOOGLE_SECRETS_PROJECT";
12+
}
13+
}

GoogleSecrets/GoogleSecrets.csproj renamed to GoogleSecrets/Neolution.Extensions.Configuration.GoogleSecrets.csproj

File renamed without changes.

Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore/Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<ProjectReference Include="..\GoogleSecrets\GoogleSecrets.csproj" />
16+
<ProjectReference Include="..\GoogleSecrets\Neolution.Extensions.Configuration.GoogleSecrets.csproj" />
1717
</ItemGroup>
1818

1919
</Project>

Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore/WebApplicationBuilderExtensions.cs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
1-
namespace Neolution.Extensions.Configuration.GoogleSecrets
1+
namespace Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore
22
{
33
using System;
44
using Microsoft.AspNetCore.Builder;
55

66
/// <summary>
7-
/// WebBuilder extensions for Google Secrets
7+
/// Google Secrets extensions for <see cref="WebApplicationBuilder"/>.
88
/// </summary>
99
public static class WebApplicationBuilderExtensions
1010
{
1111
/// <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.
2914
/// </summary>
3015
/// <param name="builder">The builder.</param>
3116
public static void AddGoogleSecrets(this WebApplicationBuilder builder)
3217
{
33-
if (builder == null)
34-
{
35-
throw new ArgumentNullException(nameof(builder));
36-
}
18+
ArgumentNullException.ThrowIfNull(builder);
3719

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))
4023
{
4124
builder.Configuration.AddGoogleSecrets(options =>
4225
{
43-
options.ProjectName = GoogleSecretsProjectName;
26+
options.ProjectName = googleSecretProject;
4427
});
4528
}
4629
}

GoogleSecrets.sln renamed to Neolution.Extensions.Configuration.GoogleSecrets.sln

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.12.35707.178 d17.12
4+
VisualStudioVersion = 17.12.35707.178
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleSecrets", "GoogleSecrets\GoogleSecrets.csproj", "{C7B9C660-1ABC-4DAE-B7C3-DB18810D3794}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neolution.Extensions.Configuration.GoogleSecrets", "GoogleSecrets\Neolution.Extensions.Configuration.GoogleSecrets.csproj", "{C7B9C660-1ABC-4DAE-B7C3-DB18810D3794}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore", "Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore\Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore.csproj", "{19D5426C-AF24-4CE1-9BD3-BEE2B77DD56B}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1A2F8802-860F-46EC-AE98-50D47A74FA91}"
11+
ProjectSection(SolutionItems) = preProject
12+
.github\workflows\ci.yml = .github\workflows\ci.yml
13+
.github\workflows\create-release.yml = .github\workflows\create-release.yml
14+
README.md = README.md
15+
EndProjectSection
16+
EndProject
1017
Global
1118
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1219
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)