last ...
This commit is contained in:
@@ -14,6 +14,7 @@ using IdentityServer4.Extensions;
|
||||
using xIdentityModels.Extensions;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using AutoMapper;
|
||||
|
||||
namespace xIds.Providers
|
||||
{
|
||||
@@ -28,6 +29,7 @@ namespace xIds.Providers
|
||||
private readonly IXIdentityManager identityManager;
|
||||
private readonly XDataServiceConfiguration configuration;
|
||||
private readonly XApiKeyConfiguration apiKeyConfiguration;
|
||||
private readonly Action<IMapperConfigurationExpression> mapperConfigurationExp;
|
||||
|
||||
public XApplicationProvider(
|
||||
IMemoryCache cache,
|
||||
@@ -45,6 +47,23 @@ namespace xIds.Providers
|
||||
this.configuration = configuration;
|
||||
this.identityManager = identityManager;
|
||||
this.apiKeyConfiguration = apiKeyConfiguration;
|
||||
|
||||
//
|
||||
// Configure Mapper Options ...
|
||||
mapperConfigurationExp = cfg =>
|
||||
{
|
||||
//
|
||||
cfg.CreateMap<XApiKey, XApiKeyDto>()
|
||||
.ReverseMap();
|
||||
|
||||
//
|
||||
cfg.CreateMap<XApplication, XApplicationDto>()
|
||||
.ReverseMap();
|
||||
|
||||
//
|
||||
cfg.CreateMap<XApiKeyUsage, XApiKeyUsageDto>()
|
||||
.ReverseMap();
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -288,14 +307,14 @@ namespace xIds.Providers
|
||||
/// <param name="limitPerMinute"></param>
|
||||
/// <returns></returns>
|
||||
private bool CheckRateLimit(
|
||||
Guid apiKeyId,
|
||||
Guid apiKeyId,
|
||||
int limitPerMinute
|
||||
)
|
||||
{
|
||||
//
|
||||
var cacheKey = $"ratelimit:{apiKeyId}";
|
||||
var currentCount = cache.GetOrCreate(
|
||||
cacheKey,
|
||||
cacheKey,
|
||||
entry =>
|
||||
{
|
||||
//
|
||||
@@ -305,14 +324,15 @@ namespace xIds.Providers
|
||||
);
|
||||
|
||||
//
|
||||
if (currentCount >= limitPerMinute) {
|
||||
if (currentCount >= limitPerMinute)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
cache.Set(
|
||||
cacheKey,
|
||||
currentCount + 1,
|
||||
cacheKey,
|
||||
currentCount + 1,
|
||||
TimeSpan.FromMinutes(1)
|
||||
);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace xIds.Providers
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = source.MapConvert<XApiKeyDto, XApiKey>();
|
||||
var result = source.MapConvert<XApiKeyDto, XApiKey>(mapperConfigurationExp);
|
||||
result = await EnrichAsync(
|
||||
source: result,
|
||||
cancellationToken: cancellationToken
|
||||
@@ -88,7 +88,7 @@ namespace xIds.Providers
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = source.MapConvert<XApiKeyUsageDto, XApiKeyUsage>();
|
||||
var result = source.MapConvert<XApiKeyUsageDto, XApiKeyUsage>(mapperConfigurationExp);
|
||||
result = await EnrichAsync(
|
||||
source: result,
|
||||
cancellationToken: cancellationToken
|
||||
@@ -110,7 +110,7 @@ namespace xIds.Providers
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = source.MapConvert<XApplicationDto, XApplication>();
|
||||
var result = source.MapConvert<XApplicationDto, XApplication>(mapperConfigurationExp);
|
||||
result = await EnrichAsync(
|
||||
source: result,
|
||||
cancellationToken: cancellationToken
|
||||
|
||||
Reference in New Issue
Block a user