the37lab-authlib 0.1.1751371611__py3-none-any.whl → 0.1.1756367559__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of the37lab-authlib might be problematic. Click here for more details.
- the37lab_authlib/auth.py +7 -2
- the37lab_authlib/db.py +21 -4
- {the37lab_authlib-0.1.1751371611.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/METADATA +1 -1
- the37lab_authlib-0.1.1756367559.dist-info/RECORD +10 -0
- the37lab_authlib-0.1.1751371611.dist-info/RECORD +0 -10
- {the37lab_authlib-0.1.1751371611.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/WHEEL +0 -0
- {the37lab_authlib-0.1.1751371611.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/top_level.txt +0 -0
the37lab_authlib/auth.py
CHANGED
|
@@ -11,6 +11,7 @@ import bcrypt
|
|
|
11
11
|
import logging
|
|
12
12
|
import os
|
|
13
13
|
from functools import wraps
|
|
14
|
+
from isodate import parse_duration
|
|
14
15
|
|
|
15
16
|
logging.basicConfig(level=logging.DEBUG)
|
|
16
17
|
logger = logging.getLogger(__name__)
|
|
@@ -40,6 +41,10 @@ class AuthManager:
|
|
|
40
41
|
user_override_env = os.getenv(f'{prefix}USER_OVERRIDE')
|
|
41
42
|
if user_override_env:
|
|
42
43
|
self.user_override = user_override_env
|
|
44
|
+
else:
|
|
45
|
+
prefix = ''
|
|
46
|
+
|
|
47
|
+
self.expiry_time = parse_duration(os.getenv(f'{prefix}JWT_TOKEN_EXPIRY_TIME', 'PT1H'))
|
|
43
48
|
if self.user_override and (api_tokens or db_dsn):
|
|
44
49
|
raise ValueError('Cannot set user_override together with api_tokens or db_dsn')
|
|
45
50
|
if api_tokens and db_dsn:
|
|
@@ -487,12 +492,12 @@ class AuthManager:
|
|
|
487
492
|
def _create_token(self, user):
|
|
488
493
|
payload = {
|
|
489
494
|
'sub': str(user['id']),
|
|
490
|
-
'exp': datetime.utcnow() +
|
|
495
|
+
'exp': datetime.utcnow() + self.expiry_time,
|
|
491
496
|
'iat': datetime.utcnow()
|
|
492
497
|
}
|
|
493
498
|
logger.debug(f"Creating token with payload: {payload}")
|
|
494
499
|
token = jwt.encode(payload, self.jwt_secret, algorithm='HS256')
|
|
495
|
-
logger.
|
|
500
|
+
logger.info(f"Created token: {token}")
|
|
496
501
|
return token
|
|
497
502
|
|
|
498
503
|
def _create_refresh_token(self, user):
|
the37lab_authlib/db.py
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import psycopg2
|
|
2
2
|
from psycopg2.extras import RealDictCursor
|
|
3
|
+
from psycopg2 import pool
|
|
3
4
|
from contextlib import contextmanager
|
|
4
5
|
from .models import UUIDGenerator, IntegerGenerator
|
|
5
6
|
|
|
6
7
|
class Database:
|
|
7
|
-
def __init__(self, dsn, id_type='uuid'):
|
|
8
|
+
def __init__(self, dsn, id_type='uuid', min_conn=1, max_conn=10):
|
|
8
9
|
self.dsn = dsn
|
|
9
10
|
self.id_generator = UUIDGenerator() if id_type == 'uuid' else IntegerGenerator()
|
|
10
11
|
self.id_type = id_type
|
|
12
|
+
self.min_conn = min_conn
|
|
13
|
+
self.max_conn = max_conn
|
|
14
|
+
self._pool = None
|
|
15
|
+
self._init_pool()
|
|
11
16
|
self._init_db()
|
|
12
17
|
|
|
18
|
+
def _init_pool(self):
|
|
19
|
+
self._pool = pool.ThreadedConnectionPool(
|
|
20
|
+
self.min_conn,
|
|
21
|
+
self.max_conn,
|
|
22
|
+
self.dsn,
|
|
23
|
+
cursor_factory=RealDictCursor
|
|
24
|
+
)
|
|
25
|
+
|
|
13
26
|
def _init_db(self):
|
|
14
27
|
with self.get_connection() as conn:
|
|
15
28
|
with conn.cursor() as cur:
|
|
@@ -54,7 +67,7 @@ class Database:
|
|
|
54
67
|
|
|
55
68
|
@contextmanager
|
|
56
69
|
def get_connection(self):
|
|
57
|
-
conn =
|
|
70
|
+
conn = self._pool.getconn()
|
|
58
71
|
try:
|
|
59
72
|
yield conn
|
|
60
73
|
conn.commit()
|
|
@@ -62,7 +75,7 @@ class Database:
|
|
|
62
75
|
conn.rollback()
|
|
63
76
|
raise
|
|
64
77
|
finally:
|
|
65
|
-
|
|
78
|
+
self._pool.putconn(conn)
|
|
66
79
|
|
|
67
80
|
@contextmanager
|
|
68
81
|
def get_cursor(self):
|
|
@@ -71,4 +84,8 @@ class Database:
|
|
|
71
84
|
yield cur
|
|
72
85
|
|
|
73
86
|
def get_id_generator(self):
|
|
74
|
-
return self.id_generator
|
|
87
|
+
return self.id_generator
|
|
88
|
+
|
|
89
|
+
def close(self):
|
|
90
|
+
if self._pool:
|
|
91
|
+
self._pool.closeall()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
|
|
2
|
+
the37lab_authlib/auth.py,sha256=eAeyS9wBO7euMkbnRZH8mvaUzy06KbQ3qwckOtmjhkw,23536
|
|
3
|
+
the37lab_authlib/db.py,sha256=cmnmykKvq6V5e-D0HGiRN4DjFBOGB-SL1HpFjR5uyCw,3162
|
|
4
|
+
the37lab_authlib/decorators.py,sha256=L-gJUUwDUT2JXTptQ6XEey1LkI5RprbqzEfArWI7F8Y,1305
|
|
5
|
+
the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
|
|
6
|
+
the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
|
|
7
|
+
the37lab_authlib-0.1.1756367559.dist-info/METADATA,sha256=KJPNMX0OzIex4uWlzA96p3nr7gSB51DCxj3zKRNNbUI,8319
|
|
8
|
+
the37lab_authlib-0.1.1756367559.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
the37lab_authlib-0.1.1756367559.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
|
|
10
|
+
the37lab_authlib-0.1.1756367559.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
|
|
2
|
-
the37lab_authlib/auth.py,sha256=NKQ-k2QDB4ddw6QKO76RL5WeRpX2gNcpVr6VSHX2yrc,23358
|
|
3
|
-
the37lab_authlib/db.py,sha256=fTXxnfju0lmbFGPVbXpTMeDmJMeBgURVZTndyxyRyCc,2734
|
|
4
|
-
the37lab_authlib/decorators.py,sha256=L-gJUUwDUT2JXTptQ6XEey1LkI5RprbqzEfArWI7F8Y,1305
|
|
5
|
-
the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
|
|
6
|
-
the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
|
|
7
|
-
the37lab_authlib-0.1.1751371611.dist-info/METADATA,sha256=J3mleZGwizcERDRBfrFnBW-21tTRh4nzfmWR575z3Bk,8319
|
|
8
|
-
the37lab_authlib-0.1.1751371611.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
the37lab_authlib-0.1.1751371611.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
|
|
10
|
-
the37lab_authlib-0.1.1751371611.dist-info/RECORD,,
|
{the37lab_authlib-0.1.1751371611.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|