Skip to content

Commit

Permalink
Settings timedelta env
Browse files Browse the repository at this point in the history
  • Loading branch information
mongkok committed Nov 6, 2017
1 parent 5caeb9d commit e875883
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions graphql_jwt/settings.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import datetime
import environ

from datetime import timedelta
from django.conf import settings

env = environ.Env()

class Env(environ.Env):

def timedelta(name, **defaults):
args = env.dict(name, default={})
def timedelta(self, var, default=environ.Env.NOTSET):

if args:
args = {k: int(v) for k, v in args.items()}
else:
args = defaults
return datetime.timedelta(**args)
def cast(value):
args = [val.split('=') for val in value.split(',') if val]
return timedelta(**{name: float(val) for name, val in args})

return self.get_value(var, cast=cast, default=default)


env = Env()

JWT_ALGORITHM = env('JWT_ALGORITHM', default='HS256')
JWT_AUDIENCE = env('JWT_AUDIENCE', default=None)
Expand All @@ -25,11 +26,17 @@ def timedelta(name, **defaults):

JWT_VERIFY = env.bool('JWT_VERIFY', True)
JWT_VERIFY_EXPIRATION = env.bool('JWT_VERIFY_EXPIRATION', False)
JWT_EXPIRATION_DELTA = timedelta('JWT_EXPIRATION_DELTA', seconds=60 * 5)

JWT_EXPIRATION_DELTA = env.timedelta(
'JWT_EXPIRATION_DELTA',
timedelta(seconds=60 * 5)
)

JWT_ALLOW_REFRESH = env.bool('JWT_ALLOW_REFRESH', True)
JWT_VERIFY_REFRESH_EXPIRATION =\
env.bool('JWT_VERIFY_REFRESH_EXPIRATION', True)

JWT_REFRESH_EXPIRATION_DELTA =\
timedelta('JWT_REFRESH_EXPIRATION_DELTA', days=7)
JWT_REFRESH_EXPIRATION_DELTA = env.timedelta(
'JWT_REFRESH_EXPIRATION_DELTA',
timedelta(days=7)
)

0 comments on commit e875883

Please sign in to comment.