Path: redb-route/redb.Route.S3/S3EndpointOptions.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.S3/S3EndpointOptions.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Expressions;
namespace redb.Route.S3;
///
/// Endpoint options for S3/MinIO transport. All properties are auto-bound from URI query parameters.
///
/// URI format: s3://bucket-name?region=us-east-1&accessKey=KEY&secretKey=SECRET
///
///
/// For producer operations: s3:PutObject:bucket-name?keyName=folder/${header.name}&...
///
///
/// Enterprise-grade S3 integration compatible with AWS S3 and MinIO.
/// Supports multipart uploads, server-side encryption (SSE-S3, SSE-KMS, SSE-C),
/// presigned URLs, tagging, versioning, ACL, lifecycle, and more.
/// Inspired by Apache Camel's aws2-s3 component (81 parameters).
///
///
public class S3EndpointOptions : EndpointOptions
{
// ═══════════════════════════════════════════════════════════════════
// CONNECTION / CREDENTIALS
// ═══════════════════════════════════════════════════════════════════
///
/// Custom service URL for S3-compatible storage (MinIO, Dell ECS, Ceph, etc.).
/// Example: http://localhost:9000 for MinIO.
/// When set, should typically be true.
///
public string ServiceUrl { get; set; } = "";
///
/// AWS region (e.g. "us-east-1", "eu-west-1"). Required for AWS S3.
/// For MinIO, use any value (e.g. "us-east-1"). (default: "us-east-1")
///
public string Region { get; set; } = "us-east-1";
/// AWS access key ID. Required unless using default credentials provider.
[Sensitive]
public string AccessKey { get; set; } = "";
/// AWS secret access key. Required unless using default credentials provider.
[Sensitive]
public string SecretKey { get; set; } = "";
/// AWS session token for temporary credentials (STS AssumeRole).
[Sensitive]
public string SessionToken { get; set; } = "";
/// AWS named profile for credentials (from ~/.aws/credentials).
public string ProfileName { get; set; } = "";
///
/// Use path-style URL (http://host/bucket/key) instead of virtual-hosted-style
/// (http://bucket.host/key). Required for MinIO and most S3-compatible stores.
/// (default: false)
///
public bool ForcePathStyle { get; set; }
///
/// Use the default AWS credentials provider chain (env vars, instance profile, etc.)
/// instead of explicit AccessKey/SecretKey. (default: false)
///
public bool UseDefaultCredentialsProvider { get; set; }
///
/// Named connection factory reference. If set, looks up an
/// from the DI registry by this name to build the S3 client. Overrides individual connection options.
///
[RegistryReference(typeof(S3ConnectionFactory))]
public string ConnectionFactory { get; set; } = "";
// ── Proxy ────────────────────────────────────────────────────────
/// HTTP proxy host for the S3 client.
public string ProxyHost { get; set; } = "";
/// HTTP proxy port. (default: 0 = no proxy)
public int ProxyPort { get; set; }
// ── Timeouts / Resilience ────────────────────────────────────────
/// Connection timeout in milliseconds. (default: 30000 = 30s)
public int ConnectionTimeout { get; set; } = 30_000;
/// Socket/read timeout in milliseconds. (default: 60000 = 60s)
public int SocketTimeout { get; set; } = 60_000;
/// Maximum number of connections in the SDK connection pool. (default: 50)
public int MaxConnections { get; set; } = 50;
/// Number of retry attempts for failed requests. (default: 3)
public int RetryCount { get; set; } = 3;
///
/// Retry mode: "standard" or "adaptive". (default: "standard")
///
public string RetryMode { get; set; } = "standard";
/// Trust all SSL certificates (for self-signed MinIO certs). (default: false)
public bool TrustAllCertificates { get; set; }
// ═══════════════════════════════════════════════════════════════════
// COMMON (consumer + producer)
// ═══════════════════════════════════════════════════════════════════
///
/// Automatically create the S3 bucket if it doesn't exist.
/// Also applies to when is true.
/// (default: false)
///
public bool AutoCreateBucket { get; set; }
///
/// Prefix filter for ListObjectsV2. Only objects whose key starts with this prefix
/// are listed by the consumer or the ListObjects producer operation.
///
public string Prefix { get; set; } = "";
///
/// Delimiter for ListObjectsV2 to group keys (typically "/").
/// When set, keys containing the delimiter after the prefix are rolled up into common-prefix entries.
///
public string Delimiter { get; set; } = "";
///
/// If true, download the object body and place it in the exchange body.
/// If false, set headers only (metadata mode). (default: true)
///
public bool IncludeBody { get; set; } = true;
///
/// If true, the exchange body is set to the S3 response stream (Stream) instead of byte[].
/// Takes precedence over . The stream is closed by Exchange.DisposeAsync(). Default: false.
///
public bool StreamBody { get; set; }
///
/// If true, the S3 object body is completely ignored (no download, no stream).
/// Overrides and . (default: false)
///
public bool IgnoreBody { get; set; }
///
/// If true, include folder/directory marker objects in consumer results.
/// If false, objects ending with "/" are skipped. (default: false)
///
public bool IncludeFolders { get; set; }
// ═══════════════════════════════════════════════════════════════════
// CONSUMER (polling bucket)
// ═══════════════════════════════════════════════════════════════════
/// Polling delay in milliseconds between bucket scans. (default: 60000 = 60s)
public int Delay { get; set; } = 60_000;
/// Initial delay before the first poll in milliseconds. (default: 1000)
public int InitialDelay { get; set; } = 1000;
/// Maximum number of objects to retrieve per poll. 0 = unlimited. (default: 10)
public int MaxMessagesPerPoll { get; set; } = 10;
///
/// Delete objects from S3 after they have been successfully consumed.
/// Only performed if the exchange completes without error and is not marked rollback-only. (default: true; with the
/// object is moved instead, as Apache Camel's move takes the place of the delete)
///
public bool DeleteAfterRead
{
get => _deleteAfterRead;
set
{
_deleteAfterRead = value;
_deleteAfterReadSet = true;
}
}
private bool _deleteAfterRead = true;
// Only a delete asked for explicitly conflicts with a move; the default gives way to it.
private bool _deleteAfterReadSet;
///
/// Move objects to after successful consumption
/// instead of deleting. Requires to be set.
/// (default: false)
///
public bool MoveAfterRead { get; set; }
/// Destination bucket for move-after-read. Required when MoveAfterRead=true.
public string DestinationBucket { get; set; } = "";
/// Prefix to add to the destination key when moving objects.
public string DestinationBucketPrefix { get; set; } = "";
/// Suffix to add to the destination key when moving objects.
public string DestinationBucketSuffix { get; set; } = "";
///
/// Remove the source prefix from the key before constructing the destination key.
/// Only applicable when is true. (default: false)
///
public bool RemovePrefixOnMove { get; set; }
///
/// Filter consumer to only process a specific object by key name.
/// When set, the consumer downloads this single file directly (no listing).
///
public string FileName { get; set; } = "";
///
/// Glob pattern to include objects (applied to the object key). e.g. "*.csv", "data/*.json".
/// Empty = all objects. (default: "")
///
public string Include { get; set; } = "";
///
/// Glob pattern to exclude objects. e.g. "*.tmp", ".hidden/*".
/// Empty = exclude nothing. (default: "")
///
public string Exclude { get; set; } = "";
///
/// If the poll returns no objects, send an empty exchange (heartbeat).
/// (default: false)
///
public bool SendEmptyMessageWhenIdle { get; set; }
///
/// Done file marker pattern. If set, the consumer only processes an object
/// when a corresponding marker object exists (e.g. ${file:name}.done). The file keys read the object key:
/// ${file:name} is the whole key, ${file:name.noext}, ${file:ext} and ${file:parent} its parts.
///
public string DoneFileName { get; set; } = "";
/// Sort order for consumed objects. (default: None)
public S3SortBy SortBy { get; set; } = S3SortBy.None;
/// Minimum object age in milliseconds before consumption. (default: 0)
public long MinAge { get; set; }
/// Maximum object age in milliseconds. Objects older than this are skipped. 0 = no limit. (default: 0)
public long MaxAge { get; set; }
// ── Idempotency ─────────────────────────────────────────────────
///
/// Enable idempotent consumer — skip objects already processed
/// (tracked by key|ETag|size). Uses an in-memory repository by default.
/// (default: false)
///
public bool Idempotent { get; set; }
///
/// Name of an IIdempotentRepository registered via
/// context.AddIdempotentRepository(name, repo) — the same contract the route-level
/// IdempotentConsumer EIP uses. With a persistent repository (RedbIdempotentRepository)
/// deduplication survives restarts and scale-out. Takes precedence over the in-memory
/// flag.
///
[RegistryReference(typeof(IIdempotentRepository))]
public string IdempotentRepository { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// PRODUCER (uploading/operations)
// ═══════════════════════════════════════════════════════════════════
///
/// Dynamic object key name for upload. Supports ${header.xxx} expressions.
/// If not set, falls back to the header from the exchange.
///
public DynamicValue? KeyName { get; set; }
///
/// S3 storage class for uploaded objects: STANDARD, REDUCED_REDUNDANCY, GLACIER,
/// STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
/// Empty = bucket default (STANDARD). (default: "")
///
public string StorageClass { get; set; } = "";
/// Content-Type for uploaded objects. Empty = auto-detect.
public string ContentType { get; set; } = "";
/// Content-Disposition header for uploaded objects.
public string ContentDisposition { get; set; } = "";
/// Content-Encoding header for uploaded objects (e.g. "gzip").
public string ContentEncoding { get; set; } = "";
/// Cache-Control header for uploaded objects.
public string CacheControl { get; set; } = "";
/// Canned ACL for uploaded objects. (default: Private)
public S3CannedAcl CannedAcl { get; set; } = S3CannedAcl.Private;
///
/// If true, use multipart upload for files larger than .
/// Smaller files use single-part upload. (default: false)
///
public bool MultiPartUpload { get; set; }
///
/// Part size in bytes for multipart uploads. Minimum AWS limit: 5 MB.
/// (default: 26214400 = 25 MB)
///
public long PartSize { get; set; } = 26_214_400;
///
/// If true, upload only succeeds if the object key does not already exist.
/// Uses conditional writes (x-amz-if-none-match). (default: false)
///
public bool ConditionalWrite { get; set; }
// ── Server-Side Encryption ──────────────────────────────────────
/// Server-side encryption mode. (default: None)
public S3ServerSideEncryption ServerSideEncryption { get; set; } = S3ServerSideEncryption.None;
/// KMS key ID for SSE-KMS encryption.
public string KmsKeyId { get; set; } = "";
/// Customer encryption key (base64-encoded) for SSE-C.
public string CustomerKeyId { get; set; } = "";
/// MD5 hash of the customer encryption key (base64-encoded) for SSE-C.
public string CustomerKeyMD5 { get; set; } = "";
// ── Presigned URLs ──────────────────────────────────────────────
///
/// Presigned URL expiration in milliseconds.
/// (default: 3600000 = 1 hour)
///
public long PresignedUrlExpiration { get; set; } = 3_600_000;
// The Streaming Upload Mode block (StreamingUploadMode, BatchMessageNumber, BatchSize,
// BufferSize, StreamingUploadTimeout, NamingStrategy) is gone since the options sweep.
// Six options and a DSL verb promised camel-style accumulate-and-flush, and NOTHING read them
// beyond Validate(): the mode was never implemented. Accumulate-then-write is the route's job
// in this framework, and the core Aggregate(...) EIP already does it with completion by
// count, size and timeout: .Aggregate(...).To(S3.Bucket(...)) - see the README recipe.
// ── Metadata ────────────────────────────────────────────────────
///
/// User metadata as comma-separated key=value pairs to attach to uploaded objects.
/// Example: author=redb,env=production.
///
public string Metadata { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// VALIDATION
// ═══════════════════════════════════════════════════════════════════
///
public override void Validate()
{
if (!string.IsNullOrEmpty(DoneFileName)
&& FileLanguage.FindUnknownKey(DoneFileName, StringComparison.OrdinalIgnoreCase) is { } key)
throw new InvalidOperationException($"doneFileName='{DoneFileName}': {FileLanguage.UnknownKeyMessage(key)}");
if (!UseDefaultCredentialsProvider
&& string.IsNullOrEmpty(ConnectionFactory)
&& string.IsNullOrEmpty(ProfileName)
&& (string.IsNullOrEmpty(AccessKey) || string.IsNullOrEmpty(SecretKey)))
{
throw new ArgumentException(
"S3 credentials required: provide AccessKey+SecretKey, set UseDefaultCredentialsProvider=true, " +
"specify ProfileName, or reference a ConnectionFactory.");
}
if (string.IsNullOrWhiteSpace(Region))
throw new ArgumentException("S3 Region must be specified.");
if (Delay < 0)
throw new ArgumentOutOfRangeException(nameof(Delay), Delay, "Delay cannot be negative.");
if (InitialDelay < 0)
throw new ArgumentOutOfRangeException(nameof(InitialDelay), InitialDelay, "InitialDelay cannot be negative.");
if (MaxMessagesPerPoll < 0)
throw new ArgumentOutOfRangeException(nameof(MaxMessagesPerPoll), MaxMessagesPerPoll,
"MaxMessagesPerPoll cannot be negative.");
if (MoveAfterRead && string.IsNullOrEmpty(DestinationBucket))
throw new InvalidOperationException("DestinationBucket is required when MoveAfterRead=true.");
if (MoveAfterRead && DeleteAfterRead && _deleteAfterReadSet)
throw new InvalidOperationException(
"Cannot set both MoveAfterRead=true and DeleteAfterRead=true. MoveAfterRead implies the object is moved, not deleted from source after move.");
if (MinAge < 0)
throw new ArgumentOutOfRangeException(nameof(MinAge), MinAge, "MinAge cannot be negative.");
if (MaxAge < 0)
throw new ArgumentOutOfRangeException(nameof(MaxAge), MaxAge, "MaxAge cannot be negative.");
if (ConnectionTimeout < 0)
throw new ArgumentOutOfRangeException(nameof(ConnectionTimeout), ConnectionTimeout,
"ConnectionTimeout cannot be negative.");
if (SocketTimeout < 0)
throw new ArgumentOutOfRangeException(nameof(SocketTimeout), SocketTimeout,
"SocketTimeout cannot be negative.");
if (MaxConnections < 1)
throw new ArgumentOutOfRangeException(nameof(MaxConnections), MaxConnections,
"MaxConnections must be at least 1.");
if (RetryCount < 0)
throw new ArgumentOutOfRangeException(nameof(RetryCount), RetryCount,
"RetryCount cannot be negative.");
if (PartSize < 5_242_880)
throw new ArgumentOutOfRangeException(nameof(PartSize), PartSize,
"PartSize must be at least 5 MB (5242880 bytes) for multipart upload.");
if (PresignedUrlExpiration <= 0)
throw new ArgumentOutOfRangeException(nameof(PresignedUrlExpiration), PresignedUrlExpiration,
"PresignedUrlExpiration must be positive.");
if (ServerSideEncryption == S3ServerSideEncryption.AwsKms && string.IsNullOrEmpty(KmsKeyId))
throw new ArgumentException("KmsKeyId is required when ServerSideEncryption=AwsKms.");
if (ServerSideEncryption == S3ServerSideEncryption.CustomerKey && string.IsNullOrEmpty(CustomerKeyId))
throw new ArgumentException("CustomerKeyId is required when ServerSideEncryption=CustomerKey.");
if (ProxyPort is < 0 or > 65535)
throw new ArgumentOutOfRangeException(nameof(ProxyPort), ProxyPort,
"ProxyPort must be 0–65535 (0 = no proxy).");
}
}