GM.Secrets
1.0.1
See the version list below for details.
dotnet add package GM.Secrets --version 1.0.1
NuGet\Install-Package GM.Secrets -Version 1.0.1
<PackageReference Include="GM.Secrets" Version="1.0.1" />
<PackageVersion Include="GM.Secrets" Version="1.0.1" />
<PackageReference Include="GM.Secrets" />
paket add GM.Secrets --version 1.0.1
#r "nuget: GM.Secrets, 1.0.1"
#:package GM.Secrets@1.0.1
#addin nuget:?package=GM.Secrets&version=1.0.1
#tool nuget:?package=GM.Secrets&version=1.0.1
GM.Secrets
A provider-agnostic secrets abstraction for the GM.* ecosystem. Your code depends on one
interface — ISecretsService — and the backend (environment variables, configuration, and, as
follow-on packages, Azure Key Vault / AWS Secrets Manager / HashiCorp Vault) is chosen by
configuration. Remote lookups are cached with a TTL via GM.Caching, so reads are cheap and
rotation happens automatically when the cache entry expires.
GM.Secrets— the coreISecretsService/ISecretsProvider, caching, typed & required access, and config-driven provider selection. Depends only onGM.Caching.GM.Secrets.Environment— reads environment variables (with prefix + name normalization).GM.Secrets.Configuration— reads fromIConfiguration(appsettings, user secrets, any source).
Install
dotnet add package GM.Secrets
dotnet add package GM.Secrets.Environment # and/or
dotnet add package GM.Secrets.Configuration
Register
builder.Services.AddGMCaching(); // optional — enables TTL caching / rotation of secret reads
// Register the providers you want available…
builder.Services.AddGMEnvironmentSecrets(builder.Configuration);
builder.Services.AddGMConfigurationSecrets(builder.Configuration);
// …and select the active one (+ options) from configuration.
builder.Services.AddGMSecrets(builder.Configuration);
{
"Secrets": {
"Provider": "Environment", // which backend wins
"CacheDuration": "00:05:00", // 0 disables caching
"Environment": { "Prefix": "MYAPP_" },
"Configuration": { "SectionName": "SecretValues" }
}
}
Switching backends (dev → prod, Environment → Key Vault) is a config change — no code change — as long as the provider package is registered.
Use
public sealed class PaymentClient(ISecretsService secrets)
{
public async Task ChargeAsync(...)
{
// Required: throws SecretNotFoundException if absent (fail fast at the edge).
var apiKey = await secrets.GetRequiredSecretAsync("Payments:ApiKey");
// Optional: null when absent.
var webhookSecret = await secrets.GetSecretAsync("Payments:WebhookSecret");
// Typed: a structured secret stored as JSON.
var creds = await secrets.GetSecretAsync<DbCredentials>("Db:Credentials");
// …use them; never log a secret value.
}
}
Values returned are sensitive — pass them straight to the consumer (a connection string, an SDK
credential); don't log them. SecretNotFoundException and error messages carry only the secret
name, never a value.
Add a provider
Implement ISecretsProvider and register it as a keyed singleton under a provider name — the
core selector resolves whichever Secrets:Provider names:
public sealed class VaultSecretsProvider : ISecretsProvider
{
public string Name => "Vault";
public Task<string?> GetSecretAsync(string name, CancellationToken ct = default) => /* fetch */;
}
services.AddKeyedSingleton<ISecretsProvider, VaultSecretsProvider>("Vault");
Follow-up provider packages (flagged, not built)
Cloud backends slot in behind the same ISecretsProvider — deliberately left as follow-ups so each
ships tested against its SDK:
GM.Secrets.AzureKeyVault—Azure.Security.KeyVault.Secrets+DefaultAzureCredential.GM.Secrets.AwsSecretsManager—AWSSDK.SecretsManager.GM.Secrets.Vault— HashiCorp Vault viaVaultSharp.
A configuration-provider integration (surface secrets through IConfiguration at startup) and using
GM.Secrets to supply runtime overrides elsewhere in the stack (e.g. rate-limit policy values) are
natural extensions.
Samples
GM.Secrets.Samples — a runnable API that consumes secrets without ever exposing them.
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- GM.Caching (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
NuGet packages (8)
Showing the top 5 NuGet packages that depend on GM.Secrets:
| Package | Downloads |
|---|---|
|
GM.API
An opinionated ASP.NET Core Web API starter for .NET. A single AddGMAPI/UseGMAPI pair wires up controllers, CORS, API versioning, Swagger docs, FluentValidation, Serilog, and middlewares for exception handling, request logging (with sensitive-data masking) and request localization. Loads secrets into configuration from a local appsecrets.json or the store the SECRETS_PROVIDER environment variable names (Doppler, AWS Secrets Manager, Azure Key Vault, HashiCorp Vault). Bundles the GM.API.* companion packages. |
|
|
GM.Secrets.AzureKeyVault
Azure Key Vault secrets provider for GM.Secrets — loads a vault's enabled secrets into IConfiguration at startup with DefaultAzureCredential (managed identity in Azure, az login / Visual Studio locally), with optional periodic reload. Db--Password maps to Db:Password. Register with builder.AddGMSecrets(s => s.AddAzureKeyVault()) and select via Secrets:Provider = "AzureKeyVault". |
|
|
GM.Secrets.AwsSecretsManager
AWS Secrets Manager provider for GM.Secrets — reads the configured secrets (a JSON secret is flattened into keys, a plain one is keyed by its name) with the AWS SDK's default credential chain, and loads them into IConfiguration at startup, with optional periodic reload. Works with LocalStack/moto via ServiceUrl. Register with builder.AddGMSecrets(s => s.AddAwsSecretsManager()) and select via Secrets:Provider = "AwsSecretsManager". |
|
|
GM.Secrets.Doppler
Doppler store for GM.Secrets — downloads a Doppler config's secrets (REST API, no SDK dependency) and loads them into IConfiguration at startup, with optional periodic reload. DB__PASSWORD maps to Db:Password. With a personal or CLI token the app environment picks the config (Development → dev, Staging → stg, Production → prd). Register with builder.AddGMSecrets(s => s.AddDoppler()) and select with the SECRETS_PROVIDER=Doppler environment variable. |
|
|
GM.Secrets.Vault
HashiCorp Vault secrets provider for GM.Secrets — reads KV v2 paths over Vault's HTTP API (token or AppRole auth, no SDK dependency) and loads them into IConfiguration at startup, with optional periodic reload. Nested values become sections. Register with builder.AddGMSecrets(s => s.AddVault()) and select via Secrets:Provider = "Vault". |
GitHub repositories
This package is not used by any popular GitHub repositories.