Skip to content

Commit 15fa891

Browse files
committed
Create dedicated package to reference in ASP.NET Core projects
1 parent 6ad5651 commit 15fa891

5 files changed

Lines changed: 80 additions & 6 deletions

File tree

GoogleSecrets.sln

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

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31515.178
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleSecrets", "GoogleSecrets\GoogleSecrets.csproj", "{C7B9C660-1ABC-4DAE-B7C3-DB18810D3794}"
77
EndProject
8+
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}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{C7B9C660-1ABC-4DAE-B7C3-DB18810D3794}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{C7B9C660-1ABC-4DAE-B7C3-DB18810D3794}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{C7B9C660-1ABC-4DAE-B7C3-DB18810D3794}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{19D5426C-AF24-4CE1-9BD3-BEE2B77DD56B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{19D5426C-AF24-4CE1-9BD3-BEE2B77DD56B}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{19D5426C-AF24-4CE1-9BD3-BEE2B77DD56B}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{19D5426C-AF24-4CE1-9BD3-BEE2B77DD56B}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

GoogleSecrets/GoogleSecretsExtensions.cs renamed to GoogleSecrets/ConfigurationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// <summary>
77
/// The Google Secrets Extensions
88
/// </summary>
9-
public static class GoogleSecretsExtensions
9+
public static class ConfigurationBuilderExtensions
1010
{
1111
/// <summary>
1212
/// Adds the google secrets.

GoogleSecrets/GoogleSecrets.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Google.Cloud.SecretManager.V1" Version="2.1.0" />
22-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
23-
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
24-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
23+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
24+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
25+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
2526
</ItemGroup>
2627

2728
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<IsPackable>true</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\GoogleSecrets\GoogleSecrets.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Neolution.Extensions.Configuration.GoogleSecrets
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Builder;
5+
6+
/// <summary>
7+
/// WebBuilder extensions for Google Secrets
8+
/// </summary>
9+
public static class WebApplicationBuilderExtensions
10+
{
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.
29+
/// </summary>
30+
/// <param name="builder">The builder.</param>
31+
public static void AddGoogleSecrets(this WebApplicationBuilder builder)
32+
{
33+
if (builder == null)
34+
{
35+
throw new ArgumentNullException(nameof(builder));
36+
}
37+
38+
// Configure app configuration to add Google Secrets if applicable
39+
if (LoadGoogleSecrets)
40+
{
41+
builder.Configuration.AddGoogleSecrets(options =>
42+
{
43+
options.ProjectName = GoogleSecretsProjectName;
44+
});
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)