Skip to main content

API Reference

ISecretProvider​

The core interface that all providers implement.

public interface ISecretProvider : IAsyncDisposable
{
Task<SecretValue> GetSecretAsync(
string key,
SecretQuery? query = null,
CancellationToken cancellationToken = default);

Task<SecretValue> PutSecretAsync(
string key,
string value,
SecretMetadata? metadata = null,
CancellationToken cancellationToken = default);

Task DeleteSecretAsync(
string key,
CancellationToken cancellationToken = default);

Task<IReadOnlyList<SecretVersionInfo>> GetSecretVersionsAsync(
string key,
CancellationToken cancellationToken = default);

Task<bool> SecretExistsAsync(
string key,
CancellationToken cancellationToken = default);
}

Types​

SecretValue​

Represents a retrieved secret with its value and metadata.

PropertyTypeDescription
KeystringThe secret's key/name
ValuestringThe secret's value
Versionstring?Version identifier
CreatedAtDateTimeOffset?When this version was created
ContentTypestring?MIME type of the value

SecretQuery​

Options for retrieving secrets.

PropertyTypeDescription
Versionstring?Specific version to retrieve
Propertystring?JSON dot-path to extract a nested value

SecretMetadata​

Write-side metadata for creating or updating secrets.

PropertyTypeDescription
ContentTypestring?MIME type of the value
TagsDictionary<string, string>?Key-value tags/labels

SecretVersionInfo​

Information about a single version of a secret.

PropertyTypeDescription
VersionstringVersion identifier
CreatedAtDateTimeOffsetWhen this version was created

Exceptions​

SecretNotFoundException​

Thrown when a requested secret does not exist.

try
{
var secret = await provider.GetSecretAsync("nonexistent-key");
}
catch (SecretNotFoundException ex)
{
Console.WriteLine($"Secret not found: {ex.SecretKey}");
}

SecretProviderException​

Base exception for provider-specific errors (network failures, auth errors, etc.).

SecretProviderBuilder​

Fluent builder for configuring and creating providers.

var provider = new SecretProviderBuilder()
.WithFileSystem(options => { /* ... */ }) // or WithAzureKeyVault, WithScaleway, WithPostgreSql
.FromEnvironment() // optional: load from env vars
.FromYamlFile("secretstore.yaml") // optional: load from YAML
.Build(); // returns ISecretProvider

ISecretProviderLayer​

Layers are decorators that wrap providers and can add cross-cutting behavior.

public interface ISecretProviderLayer
{
ISecretProvider Wrap(ISecretProvider inner);
}

public sealed class SecretProviderBuilder
{
public SecretProviderBuilder AddLayer(ISecretProviderLayer layer);
}

Out-of-box layer extension methods​

Layer builders are in the SecretsManager.Builder namespace:

using SecretsManager;
using SecretsManager.Builder;

var provider = new SecretProviderBuilder()
.WithFileSystem(options => { /* ... */ })
.WithConcurrentLimiter() // controls max concurrent operations
.WithRetry() // retries transient failures
.WithTimeout() // per-operation timeout
.WithLogging() // start/success/failure/retry logging
.WithAudit() // durable per-access audit records
.WithOtelMetrics() // emits System.Diagnostics.Metrics
.WithOtelTrace() // emits OpenTelemetry Activity spans
.Build();

All layers support optional options callbacks, for example:

var provider = new SecretProviderBuilder()
.WithFileSystem(options => { /* ... */ })
.WithRetry(options => options.MaxAttempts = 5)
.WithTimeout(options => options.Timeout = TimeSpan.FromSeconds(5))
.WithConcurrentLimiter(options => options.MaxConcurrentRequests = 10)
.WithOtelMetrics(options => options.MeterName = "secrets-metrics")
.WithOtelTrace(options => options.ActivitySourceName = "secrets-traces")
.Build();

Logging types​

LoggingLayer writes events to an ISecretProviderLogger. See Logging.

TypeDescription
ISecretProviderLoggerLog sink with IsEnabled, LogStart, LogSuccess, LogFailure and LogRetry
LoggerSecretProviderLoggerAdapter that writes to a Microsoft.Extensions.Logging ILogger
NullSecretProviderLoggerNo-op default
SecretProviderLogContextOperation, key, provider, outcome and timestamp. It never holds a secret value
SecretProviderLogLevelDebug, Information, Warning or Error
SecretProviderLogOutcomeSuccess or Failure

Audit types​

AuditLayer writes a SecretAuditEvent to one or more ISecretAuditSink instances.

TypeDescription
SecretAuditEventImmutable record: operation, provider, key, version, outcome, timestamp, duration, actor, correlation id, trace id, and failure type
SecretAuditOutcomeSuccess, Failure, Cancelled, or Denied
SecretAuditScopeFlags that select reads, writes, deletes, enumeration, or all operations
ISecretAuditSinkDestination for audit records
ISecretActorAccessorAmbient actor lookup, with AmbientSecretActorAccessor.Instance as the default
FileSecretAuditSinkJSON Lines file sink
PostgreSqlSecretAuditSinkPostgreSQL sink in the SecretsManager.PostgreSql package

See Audit Trail for usage.