Interface IAuditPurgeCapability
- Namespace
- Excalibur.Compliance
- Assembly
- Excalibur.Compliance.Abstractions.dll
Exposes destructive purge of stored audit events on an IAuditStore that supports it, so a consumer can satisfy a retention or erasure obligation without depending on a concrete store type.
public interface IAuditPurgeCapability
Remarks
This is a capability, not a member of IAuditStore, and the distinction is deliberate. A store backed by append-only or write-once media cannot delete, and a mandatory delete member would oblige it to supply one — in practice a throwing stub or, worse, a silent no-op that reports success. Discovery answers honestly instead: a store that cannot purge does not offer the capability, and GetService(Type) returns null.
A null result MUST fail loudly at the caller. Retention that cannot find this capability has not "completed with nothing to do" — it has failed to run, and reporting it as success is how a retention policy comes to be believed enforced while no data is ever removed.
Resolve it, never cast to it, so the capability survives decoration:
var purge = auditStore.GetService(typeof(IAuditPurgeCapability)) as IAuditPurgeCapability
?? throw new NotSupportedException("The configured audit store cannot purge events.");
var removed = await purge.PurgeExpiredAsync(cutoff, tenant, cancellationToken);
Methods
PurgeExpiredAsync(DateTimeOffset, CancellationToken)
Permanently removes every audit event older than cutoff, across all tenants,
together with every record that exists only to describe them.
Task<int> PurgeExpiredAsync(DateTimeOffset cutoff, CancellationToken cancellationToken)
Parameters
cutoffDateTimeOffsetEvents with an earlier timestamp are removed.
cancellationTokenCancellationTokenPropagates notification that the operation should be canceled.
Returns
Remarks
This operation is estate-wide by contract, and the absence of a tenant parameter is the contract rather than an omission. Retention answers "how long may anything be kept", which is a property of the data and its policy — not of who may read it. A retention pass that swept only one tenant would leave every other tenant's expired data in place while reporting a completed pass, so restricting this member to a partition would defeat the obligation it exists to discharge.
It is deliberately a separate, differently-named member from PurgeTenantAsync(DateTimeOffset, KeyedTenantPartition, CancellationToken) rather than an overload with the tenant omitted. A caller cannot reach an estate-wide delete by leaving an argument out, forgetting one, or passing a value that happens to widen — they must name this operation. The unscoped sweep is expressible, and only by asking for it.
Implementations MUST remove an event and its dependent records atomically. A record whose owning event has been deleted is not merely orphaned: where its tenant is derived by joining to that event, the survivor's tenant becomes underivable, so it is simultaneously unreadable by its true owner and at risk of being read as un-tenanted. Partial application is not a degraded outcome but a defect.
PurgeTenantAsync(DateTimeOffset, KeyedTenantPartition, CancellationToken)
Permanently removes audit events older than cutoff within a single tenant
partition, together with every record that exists only to describe them.
Task<int> PurgeTenantAsync(DateTimeOffset cutoff, KeyedTenantPartition tenant, CancellationToken cancellationToken)
Parameters
cutoffDateTimeOffsetEvents with an earlier timestamp are removed.
tenantKeyedTenantPartitionThe partition to purge. Required, and has no empty inhabitant: purging the un-tenanted partition is expressed by passing the reserved un-tenanted partition explicitly, never by omitting a tenant.
cancellationTokenCancellationTokenPropagates notification that the operation should be canceled.
Returns
Remarks
This serves a targeted erasure — a subject request, a tenant offboarding — where the caller means exactly one partition. For scheduled retention use PurgeExpiredAsync(DateTimeOffset, CancellationToken); using this member on a timer would purge one tenant and silently abandon the rest. The atomicity requirement stated on PurgeExpiredAsync(DateTimeOffset, CancellationToken) applies here unchanged.