feat(auth): add account import/export cycle detection and JetStream limits (E4+E5)

E4: AccountImportExport with DFS cycle detection for service imports,
RemoveServiceImport/RemoveStreamImport, and ValidateImport authorization.
E5: AccountLimits record with MaxStorage/MaxConsumers/MaxAckPending,
TryReserveConsumer/ReleaseConsumer, TrackStorageDelta on Account.
20 new tests, all passing.
This commit is contained in:
Joseph Doherty
2026-02-24 15:25:12 -05:00
parent efd053ba60
commit 235971ddcc
5 changed files with 572 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
// Per-account JetStream resource limits.
// Go reference: accounts.go JetStreamAccountLimits struct.
namespace NATS.Server.Auth;
/// <summary>
/// Per-account limits on JetStream resources: storage, streams, consumers, and ack pending.
/// A value of 0 means unlimited for all fields.
/// </summary>
public sealed record AccountLimits
{
/// <summary>Maximum total storage in bytes (0 = unlimited).</summary>
public long MaxStorage { get; init; }
/// <summary>Maximum number of streams (0 = unlimited).</summary>
public int MaxStreams { get; init; }
/// <summary>Maximum number of consumers (0 = unlimited).</summary>
public int MaxConsumers { get; init; }
/// <summary>Maximum pending ack count per consumer (0 = unlimited).</summary>
public int MaxAckPending { get; init; }
/// <summary>Maximum memory-based storage in bytes (0 = unlimited).</summary>
public long MaxMemoryStorage { get; init; }
/// <summary>Maximum disk-based storage in bytes (0 = unlimited).</summary>
public long MaxDiskStorage { get; init; }
/// <summary>Default instance with all limits set to unlimited (0).</summary>
public static AccountLimits Unlimited { get; } = new();
}