add: api for rate control
This commit is contained in:
@@ -100,6 +100,21 @@ def require_auth(roles=[]):
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
rate_limits = {}
|
||||
default_rate_limit = "60 per minute"
|
||||
def init_rate_limits(app):
|
||||
global rate_limits
|
||||
rate_limits = {
|
||||
f"{rule.rule} : {method}": default_rate_limit
|
||||
for rule in app.url_map.iter_rules()
|
||||
for method in rule.methods
|
||||
}
|
||||
|
||||
|
||||
def get_rate_limit():
|
||||
key = f"{request.path} : {request.method}"
|
||||
return rate_limits.get(key, default_rate_limit)
|
||||
|
||||
|
||||
limiter = Limiter(
|
||||
key_func=get_remote_address,
|
||||
@@ -117,4 +132,6 @@ def register_blueprints(app):
|
||||
for attr in dir(module):
|
||||
bp = getattr(module, attr)
|
||||
if isinstance(bp, Blueprint):
|
||||
app.register_blueprint(bp)
|
||||
app.register_blueprint(bp)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user