bad_request_rate_limiter.py 764 Bytes
Newer Older
1 2 3 4 5 6
"""
A utility class which wraps the RateLimitMixin 3rd party class to do bad request counting
which can be used for rate limiting
"""
from ratelimitbackend.backends import RateLimitMixin

7

8 9 10 11 12
class BadRequestRateLimiter(RateLimitMixin):
    """
    Use the 3rd party RateLimitMixin to help do rate limiting on the Password Reset flows
    """

13
    def is_rate_limit_exceeded(self, request):
14 15 16 17 18 19 20 21 22 23 24
        """
        Returns if the client has been rated limited
        """
        counts = self.get_counters(request)
        return sum(counts.values()) >= self.requests

    def tick_bad_request_counter(self, request):
        """
        Ticks any counters used to compute when rate limt has been reached
        """
        self.cache_incr(self.get_cache_key(request))