.NET

Updated

Kryptic.Daemon.Client plugs into the standard configuration system: one call on your builder and every secret is available through IConfiguration, options binding, and DI. Outside development it is a no-op, and it never throws.

Source: github.com/dev-kryptic/Kryptic.Net. Targets netstandard2.0, net6.0 and net8.0.

Install

dotnet add package Kryptic.Daemon.Client

Use

using Kryptic;

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddKryptic();   // that's the entire integration

// Secrets are ordinary configuration now:
var connectionString = builder.Configuration["DATABASE_URL"];

AddKryptic() also sets the values as environment variables so libraries that read Environment.GetEnvironmentVariable directly see them too.

Behavior

  • No-op when ASPNETCORE_ENVIRONMENT/DOTNET_ENVIRONMENT is not Development, or when KRYPTIC_DISABLED=true.
  • Finds kryptic.json by walking up from the working directory.
  • Existing environment variables and earlier configuration sources are never overwritten.
  • macOS/Linux via unix socket, Windows via named pipe (NamedPipeClientStream).

Options

builder.Configuration.AddKryptic(options =>
{
    options.Environment = "staging";   // default: kryptic.json defaultEnvironment
    options.ProjectId = "proj_x";      // default: kryptic.json projectId
    options.SocketTimeoutMs = 2000;
    options.FallbackSilently = true;   // suppress the missing-daemon warning
});

Environment variables override everything: KRYPTIC_PROJECT_ID, KRYPTIC_ENV, KRYPTIC_SOCKET_PATH, KRYPTIC_TIMEOUT_MS, KRYPTIC_DISABLED, KRYPTIC_SILENT.