|
|
|
@ -147,6 +147,11 @@ public class OperationRateLimitingChecker : IOperationRateLimitingChecker, ITran |
|
|
|
|
|
|
|
public virtual async Task ResetAsync(string policyName, OperationRateLimitingContext? context = null) |
|
|
|
{ |
|
|
|
if (!Options.IsEnabled) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
context = EnsureContext(context); |
|
|
|
var policy = await PolicyProvider.GetAsync(policyName); |
|
|
|
var rules = CreateRules(policy); |
|
|
|
@ -168,12 +173,11 @@ public class OperationRateLimitingChecker : IOperationRateLimitingChecker, ITran |
|
|
|
{ |
|
|
|
var rules = new List<IOperationRateLimitingRule>(); |
|
|
|
|
|
|
|
for (var i = 0; i < policy.Rules.Count; i++) |
|
|
|
foreach (var ruleDefinition in policy.Rules) |
|
|
|
{ |
|
|
|
rules.Add(new FixedWindowOperationRateLimitingRule( |
|
|
|
policy.Name, |
|
|
|
i, |
|
|
|
policy.Rules[i], |
|
|
|
ruleDefinition, |
|
|
|
Store, |
|
|
|
CurrentUser, |
|
|
|
CurrentTenant, |
|
|
|
@ -203,7 +207,7 @@ public class OperationRateLimitingChecker : IOperationRateLimitingChecker, ITran |
|
|
|
IsAllowed = isAllowed, |
|
|
|
RemainingCount = mostRestrictive.RemainingCount, |
|
|
|
MaxCount = mostRestrictive.MaxCount, |
|
|
|
CurrentCount = mostRestrictive.MaxCount - mostRestrictive.RemainingCount, |
|
|
|
CurrentCount = mostRestrictive.CurrentCount, |
|
|
|
RetryAfter = ruleResults.Any(r => !r.IsAllowed && r.RetryAfter.HasValue) |
|
|
|
? ruleResults |
|
|
|
.Where(r => !r.IsAllowed && r.RetryAfter.HasValue) |
|
|
|
@ -248,7 +252,7 @@ public class OperationRateLimitingChecker : IOperationRateLimitingChecker, ITran |
|
|
|
["IsAllowed"] = ruleResult.IsAllowed, |
|
|
|
["MaxCount"] = ruleResult.MaxCount, |
|
|
|
["RemainingCount"] = ruleResult.RemainingCount, |
|
|
|
["CurrentCount"] = ruleResult.MaxCount - ruleResult.RemainingCount, |
|
|
|
["CurrentCount"] = ruleResult.CurrentCount, |
|
|
|
["WindowDurationSeconds"] = (int)ruleResult.WindowDuration.TotalSeconds, |
|
|
|
["WindowDescription"] = ruleResult.WindowDuration > TimeSpan.Zero |
|
|
|
? formatter.Format(ruleResult.WindowDuration) |
|
|
|
|