Browse Source

Rename OperationRateLimit to OperationRateLimiting

pull/25025/head
maliming 7 months ago
parent
commit
24af87ecd0
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 28
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Controllers/RateLimitDemoController.cs
  2. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj
  3. 10
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs
  4. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Pages/RateLimitDemo/Index.cshtml
  5. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json

28
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Controllers/RateLimitDemoController.cs

@ -3,16 +3,16 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.OperationRateLimit;
using Volo.Abp.OperationRateLimiting;
namespace MyCompanyName.MyProjectName.Web.Controllers;
[Route("api/rate-limit-demo")]
public class RateLimitDemoController : AbpController
{
private readonly IOperationRateLimitChecker _checker;
private readonly IOperationRateLimitingChecker _checker;
public RateLimitDemoController(IOperationRateLimitChecker checker)
public RateLimitDemoController(IOperationRateLimitingChecker checker)
{
_checker = checker;
}
@ -24,7 +24,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> SendSmsCode([FromBody] SendSmsCodeInput input)
{
await _checker.CheckAsync("Demo_SendSmsCode", new OperationRateLimitContext
await _checker.CheckAsync("Demo_SendSmsCode", new OperationRateLimitingContext
{
Parameter = input.PhoneNumber,
ExtraProperties =
@ -43,7 +43,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> LoginAttempt([FromBody] LoginAttemptInput input)
{
await _checker.CheckAsync("Demo_LoginAttempt", new OperationRateLimitContext
await _checker.CheckAsync("Demo_LoginAttempt", new OperationRateLimitingContext
{
ExtraProperties =
{
@ -97,7 +97,7 @@ public class RateLimitDemoController : AbpController
[Authorize]
public async Task<IActionResult> CompositeParamUser([FromBody] CompositeParamUserInput input)
{
await _checker.CheckAsync("Demo_Composite_ParamUser", new OperationRateLimitContext
await _checker.CheckAsync("Demo_Composite_ParamUser", new OperationRateLimitingContext
{
Parameter = input.Key
});
@ -112,7 +112,7 @@ public class RateLimitDemoController : AbpController
[Authorize]
public async Task<IActionResult> CompositeTriple([FromBody] CompositeTripleInput input)
{
await _checker.CheckAsync("Demo_Composite_Triple", new OperationRateLimitContext
await _checker.CheckAsync("Demo_Composite_Triple", new OperationRateLimitingContext
{
Parameter = input.Key
});
@ -127,7 +127,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> SubmitFeedback([FromBody] SubmitFeedbackInput input)
{
await _checker.CheckAsync("Demo_SubmitFeedback", new OperationRateLimitContext
await _checker.CheckAsync("Demo_SubmitFeedback", new OperationRateLimitingContext
{
Parameter = input.Email,
ExtraProperties =
@ -147,7 +147,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> LongHours([FromBody] LongHoursInput input)
{
await _checker.CheckAsync("Demo_LongHours", new OperationRateLimitContext
await _checker.CheckAsync("Demo_LongHours", new OperationRateLimitingContext
{
Parameter = input.Key
});
@ -174,7 +174,7 @@ public class RateLimitDemoController : AbpController
[Authorize]
public async Task<IActionResult> CustomMultiKey([FromBody] CustomMultiKeyInput input)
{
await _checker.CheckAsync("Demo_CustomMultiKey", new OperationRateLimitContext
await _checker.CheckAsync("Demo_CustomMultiKey", new OperationRateLimitingContext
{
Parameter = input.ResourceId
});
@ -190,7 +190,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> DemoTenantIsolated([FromBody] DemoTenantIsolatedInput input)
{
await _checker.CheckAsync("Demo_TenantIsolated", new OperationRateLimitContext
await _checker.CheckAsync("Demo_TenantIsolated", new OperationRateLimitingContext
{
Parameter = input.Key
});
@ -205,7 +205,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> GetStatus(string policyName, [FromQuery] string? parameter = null)
{
var context = new OperationRateLimitContext { Parameter = parameter };
var context = new OperationRateLimitingContext { Parameter = parameter };
var status = await _checker.GetStatusAsync(policyName, context);
return Ok(new
@ -225,7 +225,7 @@ public class RateLimitDemoController : AbpController
[AllowAnonymous]
public async Task<IActionResult> Reset(string policyName, [FromQuery] string? parameter = null)
{
var context = new OperationRateLimitContext { Parameter = parameter };
var context = new OperationRateLimitingContext { Parameter = parameter };
await _checker.ResetAsync(policyName, context);
return Ok(new { success = true, message = $"Policy '{policyName}' reset" });
@ -265,7 +265,7 @@ public class RateLimitDemoController : AbpController
{
try
{
await _checker.ResetAsync(policyName, new OperationRateLimitContext { Parameter = parameter });
await _checker.ResetAsync(policyName, new OperationRateLimitingContext { Parameter = parameter });
}
catch
{

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj

@ -58,7 +58,7 @@
<ProjectReference Include="..\MyCompanyName.MyProjectName.EntityFrameworkCore\MyCompanyName.MyProjectName.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Swashbuckle\Volo.Abp.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.OperationRateLimit\Volo.Abp.OperationRateLimit.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.OperationRateLimiting\Volo.Abp.OperationRateLimiting.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Serilog\Volo.Abp.AspNetCore.Serilog.csproj" />
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.Web\Volo.Abp.Identity.Web.csproj" />
<ProjectReference Include="..\..\..\..\..\modules\account\src\Volo.Abp.Account.Web.OpenIddict\Volo.Abp.Account.Web.OpenIddict.csproj" />

10
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs

@ -39,7 +39,7 @@ using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.UI;
using Volo.Abp.UI.Navigation;
using Volo.Abp.OperationRateLimit;
using Volo.Abp.OperationRateLimiting;
using Volo.Abp.VirtualFileSystem;
namespace MyCompanyName.MyProjectName.Web;
@ -56,7 +56,7 @@ namespace MyCompanyName.MyProjectName.Web;
typeof(AbpTenantManagementWebModule),
typeof(AbpAspNetCoreSerilogModule),
typeof(AbpSwashbuckleModule),
typeof(AbpOperationRateLimitModule)
typeof(AbpOperationRateLimitingModule)
)]
public class MyProjectNameWebModule : AbpModule
{
@ -116,12 +116,12 @@ public class MyProjectNameWebModule : AbpModule
context.Services.AddMapperlyObjectMapper<MyProjectNameWebModule>();
ConfigureOperationRateLimit();
ConfigureOperationRateLimiting();
}
private void ConfigureOperationRateLimit()
private void ConfigureOperationRateLimiting()
{
Configure<AbpOperationRateLimitOptions>(options =>
Configure<AbpOperationRateLimitingOptions>(options =>
{
// Demo 1: Public - rate limit by parameter (e.g. phone/email), no auth required
options.AddPolicy("Demo_SendSmsCode", policy =>

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Pages/RateLimitDemo/Index.cshtml

@ -267,7 +267,7 @@
<strong>Partition:</strong> <code>PartitionByParameter</code><br/>
<strong>Rule:</strong> 2 requests per email within <code>20 seconds</code><br/>
<strong>Custom error code:</strong> <code>App:Feedback:RateLimited</code><br/>
<strong>Note:</strong> Default error code is <code>Volo.Abp.OperationRateLimit:010001</code>. This policy uses <code>WithErrorCode()</code> to set a custom code so the frontend can handle it differently.
<strong>Note:</strong> Default error code is <code>Volo.Abp.OperationRateLimiting:010001</code>. This policy uses <code>WithErrorCode()</code> to set a custom code so the frontend can handle it differently.
</div>
<div class="mb-3">
<label class="form-label">Email</label>

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json

@ -3,7 +3,7 @@
"SelfUrl": "https://localhost:44303"
},
"ConnectionStrings": {
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=MyProjectName;Trusted_Connection=True;TrustServerCertificate=True"
"Default": "Server=localhost;Database=MyProjectName;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
},
"StringEncryption": {
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"

Loading…
Cancel
Save