Neolution.Extensions.Configuration.GoogleSecrets
1.1.6
Prefix Reserved
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
<PackageReference Include="Neolution.Extensions.Configuration.GoogleSecrets" Version="1.1.6" />
paket add Neolution.Extensions.Configuration.GoogleSecrets --version 1.1.6
#r "nuget: Neolution.Extensions.Configuration.GoogleSecrets, 1.1.6"
// 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 ofVersion
- Fix github action to extract version from
- 1.1.0
- Migrated from .NET Standard 2.1 to .NET 6
- 1.0.1-alpha
- Initial Release
Product | Versions 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. |
-
.NETStandard 2.1
- Google.Cloud.SecretManager.V1 (>= 1.8.0)
- Microsoft.Extensions.Configuration (>= 3.1.0)
- Microsoft.Extensions.Logging (>= 3.1.0)
- Microsoft.Extensions.Logging.Console (>= 3.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.