We are accessing the limit variables outside of this function, so we
will have to reset limit. This is slightly annoying, but we cannot
perform any authentication checks in __init__().
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
"""
Returns True if the request is prohibited by the rate limiter
"""
- limit = self.limit
-
# Fetch the API key
if self.api_key:
# Fetch the API key
# If authenticated users have a different limit set,
# we change the checked limit to that
if self.auth_limit:
- limit = self.auth_limit
+ self.limit = self.auth_limit
# Fetch the number of past requests
self.requests = await self.get_requests()
- # Assert that some limit has been set
- assert limit
-
# The client is rate-limited when more requests have been received than allowed
- if self.requests >= limit:
+ if self.requests >= self.limit:
return True
# Increment the request counter