GM.Secrets.Environment 1.0.0

dotnet add package GM.Secrets.Environment --version 1.0.0
                    
NuGet\Install-Package GM.Secrets.Environment -Version 1.0.0
                    
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="GM.Secrets.Environment" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GM.Secrets.Environment" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GM.Secrets.Environment" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GM.Secrets.Environment --version 1.0.0
                    
#r "nuget: GM.Secrets.Environment, 1.0.0"
                    
#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.
#:package GM.Secrets.Environment@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GM.Secrets.Environment&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GM.Secrets.Environment&version=1.0.0
                    
Install as a Cake Tool

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 core ISecretsService / ISecretsProvider, caching, typed & required access, and config-driven provider selection. Depends only on GM.Caching.
  • GM.Secrets.Environment — reads environment variables (with prefix + name normalization).
  • GM.Secrets.Configuration — reads from IConfiguration (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.AzureKeyVaultAzure.Security.KeyVault.Secrets + DefaultAzureCredential.
  • GM.Secrets.AwsSecretsManagerAWSSDK.SecretsManager.
  • GM.Secrets.Vault — HashiCorp Vault via VaultSharp.

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 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. 
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.0.0 85 8/5/2026