Neolution.Extensions.Configuration.GoogleSecrets 1.1.6

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Neolution.Extensions.Configuration.GoogleSecrets --version 1.1.6                
NuGet\Install-Package Neolution.Extensions.Configuration.GoogleSecrets -Version 1.1.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Neolution.Extensions.Configuration.GoogleSecrets" Version="1.1.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Neolution.Extensions.Configuration.GoogleSecrets --version 1.1.6                
#r "nuget: Neolution.Extensions.Configuration.GoogleSecrets, 1.1.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Neolution.Extensions.Configuration.GoogleSecrets as a Cake Addin
#addin nuget:?package=Neolution.Extensions.Configuration.GoogleSecrets&version=1.1.6

// Install Neolution.Extensions.Configuration.GoogleSecrets as a Cake Tool
#tool nuget:?package=Neolution.Extensions.Configuration.GoogleSecrets&version=1.1.6                

Neolution.Extensions.Configuration.GoogleSecrets

This package is a configuration provider that injects google secrets into the Microsoft.Extensions.Configuration.

It is not recommended to store secrets like connection strings in the source code directly or in environment variables. The better approach is to use a secret provider like the secret manager for the google cloud eco system.

Usage

Install the package using your favourite method, for example: dotnet add package Neolution.Extensions.Configuration.GoogleSecrets

Add the custom configuration provider to your IHostBuilder :

public static IHostBuilder CreateHostBuilder(string[] args)
{
    return Host.CreateDefaultBuilder(args)
        ...
        .ConfigureAppConfiguration((_, configuration) =>
        {
            configuration.AddGoogleSecrets(options =>
            {
                options.ProjectName = "your-project-id";
            });
        });
}

Options

Name Required Description Default
ProjectName ✔️ Specifies which project the secrets are read from. null
Filter A server side filter forwarded to the google api according to https://cloud.google.com/secret-manager/docs/filtering null
FilterFn A filter function that will be run after the secrets are read from google (client side filtering). Supplies the Google.Cloud.SecretManager.V1.Secret as parameter. If returned true the secret will be processed otherwise it will be ignored. secret => true
MapFn A map function that will be run after the secrets have been filtered secret.SecretName.SecretId.Replace("__", ":")
VersionDictionary By default the latest version of each secret is taken. But you can specify a specific version in the form of a dictionary. Key is the secret id and value is the version to take. For example: {"MySecretId": "2"} null

Overriding default appsettings.json values

You can override existing appsettings.json values by making sure the MapFn maps it to the correct path. For example if we have the following appsettings.json:

{
  "Secrets": {
    "MyGoogleSecret": "santa isn't real"
  }
}

We can override it by making sure that the MapFn maps it to Secrets:MyGoogleSecret. With the default MapFn the google secret would have to be called Secrets__MyGoogleSecret.

Authentication

Inside GCP

Authorization is done automatically when run inside google cloud.

Outside GCP

To test it outside of google cloud you need to either set an environment variable called GOOGLE_APPLICATION_CREDENTIALS or use the gcloud auth application-default login command from the google cloud sdk.

Environment variable

Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the json file with your credentials. More details can be found here: https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable. You can also set the environment variable via code, for example:

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\\temp\\your-file.json");
gcloud auth application-default login

Simply run the command gcloud auth application-default login (after you have run gcloud auth login). This will set up the application default credentials using your personal account.

Version History

  • 1.1.6
    • Downgraded Microsoft.Extension packages from 6.0.0 to 3.1.0
  • 1.1.5
    • Back to .NET Standard 2.1
  • 1.1.4
    • Added more logging
    • Skipping unretrievalable secrets
  • 1.1.3
    • Updated nuget packages
  • 1.1.2
    • Fix github action to extract version from PackageVersion instead of Version
  • 1.1.0
    • Migrated from .NET Standard 2.1 to .NET 6
  • 1.0.1-alpha
    • Initial Release
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 6,952 3/12/2024
1.3.0 143 3/12/2024
1.2.0 16,536 6/29/2023
1.1.9 168 6/29/2023
1.1.7 4,169 9/6/2022
1.1.6 5,635 5/16/2022
1.1.5 443 5/10/2022
1.1.4 573 5/10/2022
1.1.3 626 2/16/2022