Make TokenRedis optional
Most installations will not have redis or simplejson installed, so avoid having them as a hard requirement unless actually using the TokenRedis plugin.
This commit is contained in:
parent
70911c6d6e
commit
01a184f4a9
|
@ -135,17 +135,18 @@ class JWTTokenApi(BasePlugin):
|
||||||
print("package jwcrypto not found, are you sure you've installed it correctly?", file=sys.stderr)
|
print("package jwcrypto not found, are you sure you've installed it correctly?", file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
import sys
|
class TokenRedis(object):
|
||||||
|
|
||||||
if sys.version_info >= (2, 7):
|
|
||||||
import redis
|
|
||||||
import simplejson
|
|
||||||
|
|
||||||
class TokenRedis(object):
|
|
||||||
def __init__(self, src):
|
def __init__(self, src):
|
||||||
self._server, self._port = src.split(":")
|
self._server, self._port = src.split(":")
|
||||||
|
|
||||||
def lookup(self, token):
|
def lookup(self, token):
|
||||||
|
try:
|
||||||
|
import redis
|
||||||
|
import simplejson
|
||||||
|
except ImportError as e:
|
||||||
|
print("package redis or simplejson not found, are you sure you've installed them correctly?", file=sys.stderr)
|
||||||
|
return None
|
||||||
|
|
||||||
client = redis.Redis(host=self._server,port=self._port)
|
client = redis.Redis(host=self._server,port=self._port)
|
||||||
stuff = client.get(token)
|
stuff = client.get(token)
|
||||||
if stuff is None:
|
if stuff is None:
|
||||||
|
|
Loading…
Reference in New Issue