Adding the new rewrite
This commit is contained in:
1 parent
4aca9f08d1
commit
9b48b01d1d
62 files changed
+4510
-1406
No files matched your search
@@ -0,0 +1,27 @@
|
||||
"""Rate limiting via slowapi with Redis-backed storage."""
|
||||
from __future__ import annotations
|
||||
|
||||
from slowapi import Limiter
|
||||
from slowapi.util import get_remote_address
|
||||
|
||||
from .settings import settings
|
||||
|
||||
|
||||
def _enabled_swallow(f):
|
||||
"""Return original limiter decorator or a no-op when rate limiting disabled."""
|
||||
if settings.rate_limit_enabled:
|
||||
return f
|
||||
|
||||
def _noop(*args, **kwargs):
|
||||
def wrapper(fn):
|
||||
return fn
|
||||
return wrapper
|
||||
return _noop
|
||||
|
||||
|
||||
limiter = Limiter(
|
||||
key_func=get_remote_address,
|
||||
storage_uri=settings.redis_url,
|
||||
enabled=settings.rate_limit_enabled,
|
||||
default_limits=[],
|
||||
)
|
||||
Reference in new issue
Block a user