Example #1
0
 public AuthTypeResolveContributor(IHttpContextAccessor httpContextAccessor, IClientPolicyStore clientPolicyStore, ClientRateLimitOptions clientOptions, ClientRateLimitPolicies clientPolicies)
 {
     _clientOptions       = clientOptions;
     _clientPolicies      = clientPolicies;
     _httpContextAccessor = httpContextAccessor;
     _clientPolicyStore   = clientPolicyStore;
 }
 public MemoryCacheClientPolicyStore(
     IMemoryCache cache,
     ClientRateLimitOptions options   = null,
     ClientRateLimitPolicies policies = null) : base(cache)
 {
     _options  = options;
     _policies = policies;
 }
Example #3
0
 public ClientPolicyStore(
     ICacheManager cacheManager,
     IOptions <ClientRateLimitOptions> options   = null,
     IOptions <ClientRateLimitPolicies> policies = null)
 {
     _cacheManager = cacheManager;
     _options      = options?.Value;
     _policies     = policies?.Value;
 }
Example #4
0
 public CustomRateLimitConfiguration(IHttpContextAccessor httpContextAccessor, IClientPolicyStore clientPolicyStore, IOptions <IpRateLimitOptions> ipOptions, IOptions <ClientRateLimitOptions> clientOptions, IOptions <ClientRateLimitPolicies> clientPolicies)
 {
     IpRateLimitOptions      = ipOptions?.Value;
     ClientRateLimitOptions  = clientOptions?.Value;
     ClientRateLimitPolicies = clientPolicies?.Value;
     HttpContextAccessor     = httpContextAccessor;
     ClientPolicyStore       = clientPolicyStore;
     ClientResolvers         = new List <IClientResolveContributor>();
     IpResolvers             = new List <IIpResolveContributor>();
     RegisterResolvers();
 }
        public MemoryCacheClientPolicyStore(IMemoryCache memoryCache,
                                            ClientRateLimitOptions options,
                                            ClientRateLimitPolicies policies)
        {
            _memoryCache = memoryCache;

            //save client rules defined in appsettings in cache on startup
            if (options != null && policies != null && policies != null && policies.ClientRules != null)
            {
                foreach (var rule in policies.ClientRules)
                {
                    Set($"{options.ClientPolicyPrefix}_{rule.ClientId}", new ClientRateLimitPolicy {
                        ClientId = rule.ClientId, Rules = rule.Rules
                    });
                }
            }
        }
        static ClientRateLimit()
        {
            if (Setting.Configuration?.IpRateLimiting == null)
            {
                return;
            }

            Logger = Factory.Logger.Value;

            Options = Setting.Configuration.ClientRateLimiting;

            Policies = Setting.Configuration.ClientRateLimitPolicies;

            MemoryCache = new MemoryCacheManager();

            var rateLimitCounterStore = Factory.RateLimitCounterStore.Value;

            IClientPolicyStore clientPolicyStore = new MemoryCacheClientPolicyStore(MemoryCache, Options, Policies);

            Processor = new ClientRateLimitProcessor(Options, rateLimitCounterStore, clientPolicyStore);

            Configurationed = true;
        }