Skip to content
Snippets Groups Projects
Commit 12593859 authored by ale's avatar ale
Browse files

use current_app, not a specific app

parent e0439093
Branches
No related tags found
No related merge requests found
import functools import functools
import re import re
from flask import abort, request from flask import abort, request, current_app
from authserv import app
from authserv import protocol from authserv import protocol
...@@ -116,8 +115,8 @@ def ratelimit_http_request(key_fn, count=0, period=0): ...@@ -116,8 +115,8 @@ def ratelimit_http_request(key_fn, count=0, period=0):
@functools.wraps(fn) @functools.wraps(fn)
def _ratelimit(*args, **kwargs): def _ratelimit(*args, **kwargs):
key = _tostr(key_fn(fn.__name__, args)) key = _tostr(key_fn(fn.__name__, args))
if key and not rl.check(app.memcache, key): if key and not rl.check(current_app.memcache, key):
app.logger.debug('ratelimited: %s', key) current_app.logger.debug('ratelimited: %s', key)
abort(503) abort(503)
return fn(*args, **kwargs) return fn(*args, **kwargs)
return _ratelimit return _ratelimit
...@@ -167,12 +166,12 @@ def blacklist_on_auth_failure(key_fn, count=0, period=0, ttl=0, check_wl=False, ...@@ -167,12 +166,12 @@ def blacklist_on_auth_failure(key_fn, count=0, period=0, ttl=0, check_wl=False,
return fn(*args, **kwargs) return fn(*args, **kwargs)
if ((not check_wl or not whitelisted(key)) if ((not check_wl or not whitelisted(key))
and not bl.check(app.memcache, key)): and not bl.check(current_app.memcache, key)):
app.logger.debug('blacklisted %s', key) current_app.logger.debug('blacklisted %s', key)
return bl_return_value return bl_return_value
result = fn(*args, **kwargs) result = fn(*args, **kwargs)
if result != protocol.OK: if result != protocol.OK:
bl.incr(app.memcache, key) bl.incr(current_app.memcache, key)
return result return result
return _blacklist return _blacklist
return decoratorfn return decoratorfn
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment