Path: redb-route/redb.Route.Firebase/Storage/FirebaseStorageEndpointOptions.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.Firebase/Storage/FirebaseStorageEndpointOptions.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Firebase;
///
/// Endpoint options for the Firebase Storage component.
/// Supports producer (upload/download/delete/list/metadata) and consumer (polling) modes.
/// Firebase Storage = GCS bucket — compatible with Google.Cloud.Storage.V1.
///
public sealed class FirebaseStorageEndpointOptions : EndpointOptions
{
// ── Auth ──
/// Path to the Firebase service-account JSON file.
public string? CredentialPath { get; set; }
/// Firebase/GCP project ID.
public string? ProjectId { get; set; }
/// Named reference from the registry.
[RegistryReference(typeof(IFirebaseCredentialProvider))]
public string? ConnectionFactory { get; set; }
// ── Target ──
/// Producer operation type. Default: .
public FirebaseStorageOperationType Operation { get; set; } = FirebaseStorageOperationType.Upload;
/// Override bucket name (default from URI path).
public string? BucketName { get; set; }
// ── Upload ──
/// Object name/key. Supports ${...} expressions.
public DynamicValue? ObjectName { get; set; }
/// MIME content type override.
public string? ContentType { get; set; }
/// Cache-Control header (e.g. "public, max-age=3600").
public string? CacheControl { get; set; }
// ── Copy ──
/// Destination object name for the Copy operation. Supports ${...} expressions.
public DynamicValue? DestinationObjectName { get; set; }
/// Destination bucket for the Copy operation (default: source bucket).
public string? DestinationBucket { get; set; }
// ── Signed URLs ──
/// TTL for CreateDownloadLink signed URLs, in milliseconds. Default: 1 hour.
public long SignedUrlExpiration { get; set; } = 3_600_000;
// ── Download ──
/// Download body as Stream (true) or byte[] (false).
public bool StreamBody { get; set; }
// ── Consumer: Polling ──
/// Poll interval (ms). Default: 5000.
public int Delay { get; set; } = 5000;
/// Initial delay (ms) before first poll. Default: 1000.
public int InitialDelay { get; set; } = 1000;
/// Object name prefix filter for listing.
public string? Prefix { get; set; }
/// Maximum number of objects to process per poll cycle.
public int MaxMessagesPerPoll { get; set; } = 10;
/// Download object body into exchange (default: true).
public bool IncludeBody { get; set; } = true;
/// Delete object after successful consumer processing.
public bool DeleteAfterRead { get; set; }
/// Move objects to this prefix after processing (copy + delete).
public string? MoveAfterRead { get; set; }
///
/// Move objects whose processing FAILED (an unhandled exception, or an exchange marked rollback-only) to this
/// prefix (copy + delete) — a quarantine
/// pocket so the poll loop stops retrying them. When unset, a failed object stays in
/// place and is offered again on the next poll.
///
public string? MoveFailed { get; set; }
/// Skip previously processed objects (in-memory idempotent repository).
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; }
///
/// Create the bucket on consumer start when it does not exist (requires
/// or FIREBASE_PROJECT). Default: false.
///
public bool AutoCreateBucket { get; set; }
// ── Consumer: Filtering ──
/// Include glob pattern for object names.
public string? Include { get; set; }
/// Exclude glob pattern for object names.
public string? Exclude { get; set; }
///
public override void Validate()
{
// STORAGE_EMULATOR_HOST is the env var Google.Cloud.Storage.V1 actually honors
// (FIREBASE_STORAGE_EMULATOR_HOST belongs to the Firebase client SDKs, not this one).
if (string.IsNullOrWhiteSpace(CredentialPath)
&& string.IsNullOrWhiteSpace(ConnectionFactory)
&& string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"))
&& string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("STORAGE_EMULATOR_HOST")))
throw new ArgumentOutOfRangeException(nameof(CredentialPath),
"CredentialPath, ConnectionFactory, GOOGLE_APPLICATION_CREDENTIALS, or STORAGE_EMULATOR_HOST required");
if (Delay < 100)
throw new ArgumentOutOfRangeException(nameof(Delay), "Delay must be >= 100ms");
if (MaxMessagesPerPoll < 1)
throw new ArgumentOutOfRangeException(nameof(MaxMessagesPerPoll), "MaxMessagesPerPoll must be >= 1");
// The file keys of the move prefixes, checked here so a wrong key fails when the endpoint is created.
ValidateFileKeys("moveAfterRead", MoveAfterRead);
ValidateFileKeys("moveFailed", MoveFailed);
}
private static void ValidateFileKeys(string option, string? prefix)
{
if (!string.IsNullOrEmpty(prefix)
&& redb.Route.Expressions.FileLanguage.FindUnknownKey(prefix, StringComparison.OrdinalIgnoreCase) is { } key)
throw new InvalidOperationException($"{option}='{prefix}': {redb.Route.Expressions.FileLanguage.UnknownKeyMessage(key)}");
}
}