36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
// -----------------------------------------------------------------------------
|
|
// RateLimitRule.cs
|
|
// Sprint: SPRINT_1200_001_003_router_rate_limiting_rule_stacking
|
|
// Task: 3.1 - Extend Configuration for Rule Arrays
|
|
// Description: Single rate limit rule definition (window + max requests)
|
|
// -----------------------------------------------------------------------------
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace StellaOps.Router.Gateway.RateLimit;
|
|
|
|
/// <summary>
|
|
/// A single rate limit rule (window + max requests).
|
|
/// </summary>
|
|
public sealed class RateLimitRule
|
|
{
|
|
[ConfigurationKeyName("per_seconds")]
|
|
public int PerSeconds { get; set; }
|
|
|
|
[ConfigurationKeyName("max_requests")]
|
|
public int MaxRequests { get; set; }
|
|
|
|
[ConfigurationKeyName("name")]
|
|
public string? Name { get; set; }
|
|
|
|
public void Validate(string path)
|
|
{
|
|
if (PerSeconds <= 0)
|
|
throw new ArgumentException($"{path}: per_seconds must be > 0");
|
|
|
|
if (MaxRequests <= 0)
|
|
throw new ArgumentException($"{path}: max_requests must be > 0");
|
|
}
|
|
}
|
|
|