💚 Add wrapper around limit decorator to fix pytest discovery
This commit is contained in:
1 parent
3e3c11811e
commit
6af0ce48dc
2 files changed
+20
-1
No files matched your search
@@ -35,6 +35,7 @@ from octoprint.server.util import (
|
||||
from octoprint.server.util.flask import (
|
||||
get_json_command_from_request,
|
||||
get_remote_address,
|
||||
limit,
|
||||
no_firstrun_access,
|
||||
passive_login,
|
||||
)
|
||||
@@ -281,7 +282,7 @@ def serverStatus():
|
||||
|
||||
|
||||
@api.route("/login", methods=["POST"])
|
||||
@octoprint.server.limiter.limit(
|
||||
@limit(
|
||||
"3/minute;5/10 minutes;10/hour",
|
||||
deduct_when=lambda response: response.status_code == 403,
|
||||
error_message="You have made too many failed login attempts. Please try again later.",
|
||||
|
||||
@@ -669,6 +669,24 @@ def passive_login():
|
||||
return flask.jsonify(response)
|
||||
|
||||
|
||||
# ~~ rate limiting helper
|
||||
|
||||
|
||||
def limit(*args, **kwargs):
|
||||
if octoprint.server.limiter:
|
||||
return octoprint.server.limiter.limit(*args, **kwargs)
|
||||
else:
|
||||
|
||||
def decorator(f):
|
||||
@functools.wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return decorated_function
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
# ~~ cache decorator for cacheable views
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user