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:
Pierre Ossman 2019-05-24 12:56:23 +02:00
parent 70911c6d6e
commit 01a184f4a9
1 changed files with 18 additions and 17 deletions

View File

@ -135,22 +135,23 @@ 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):
def __init__(self, src):
self._server, self._port = src.split(":")
if sys.version_info >= (2, 7): def lookup(self, token):
import redis try:
import simplejson 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
class TokenRedis(object): client = redis.Redis(host=self._server,port=self._port)
def __init__(self, src): stuff = client.get(token)
self._server, self._port = src.split(":") if stuff is None:
return None
def lookup(self, token): else:
client = redis.Redis(host=self._server,port=self._port) combo = simplejson.loads(stuff.decode("utf-8"))
stuff = client.get(token) pair = combo["host"]
if stuff is None: return pair.split(':')
return None
else:
combo = simplejson.loads(stuff.decode("utf-8"))
pair = combo["host"]
return pair.split(':')