ecodev-core 0.0.17__py3-none-any.whl → 0.0.19__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 ecodev-core might be problematic. Click here for more details.
- ecodev_core/__init__.py +2 -1
- ecodev_core/app_user.py +12 -2
- ecodev_core/authentication.py +9 -9
- {ecodev_core-0.0.17.dist-info → ecodev_core-0.0.19.dist-info}/METADATA +1 -1
- {ecodev_core-0.0.17.dist-info → ecodev_core-0.0.19.dist-info}/RECORD +7 -7
- {ecodev_core-0.0.17.dist-info → ecodev_core-0.0.19.dist-info}/LICENSE.md +0 -0
- {ecodev_core-0.0.17.dist-info → ecodev_core-0.0.19.dist-info}/WHEEL +0 -0
ecodev_core/__init__.py
CHANGED
|
@@ -10,6 +10,7 @@ from ecodev_core.app_rights import AppRight
|
|
|
10
10
|
from ecodev_core.app_user import AppUser
|
|
11
11
|
from ecodev_core.app_user import select_user
|
|
12
12
|
from ecodev_core.app_user import upsert_app_users
|
|
13
|
+
from ecodev_core.app_user import upsert_new_user
|
|
13
14
|
from ecodev_core.auth_configuration import AUTH
|
|
14
15
|
from ecodev_core.authentication import attempt_to_log
|
|
15
16
|
from ecodev_core.authentication import get_access_token
|
|
@@ -78,4 +79,4 @@ __all__ = [
|
|
|
78
79
|
'enum_converter', 'ServerSideFilter', 'get_rows', 'count_rows', 'ServerSideField', 'get_raw_df',
|
|
79
80
|
'generic_insertion', 'custom_equal', 'is_authorized_user', 'get_method', 'AppActivity',
|
|
80
81
|
'fastapi_monitor', 'dash_monitor', 'is_monitoring_user', 'get_recent_activities', 'select_user',
|
|
81
|
-
'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile']
|
|
82
|
+
'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user']
|
ecodev_core/app_user.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Module implementing the sqlmodel orm part of the user table
|
|
3
3
|
"""
|
|
4
4
|
from pathlib import Path
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Any
|
|
6
6
|
from typing import List
|
|
7
7
|
from typing import Optional
|
|
8
8
|
from typing import TYPE_CHECKING
|
|
@@ -39,7 +39,7 @@ class AppUser(SQLModel, table=True): # type: ignore
|
|
|
39
39
|
rights: List['AppRight'] = Relationship(back_populates='user')
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
def user_convertor(df: pd.DataFrame) -> List[
|
|
42
|
+
def user_convertor(df: pd.DataFrame) -> List[Any]:
|
|
43
43
|
"""
|
|
44
44
|
Dummy user convertor
|
|
45
45
|
"""
|
|
@@ -90,3 +90,13 @@ def select_user(username: str, session: Session) -> AppUser:
|
|
|
90
90
|
sqlalchemy.exc.MultipleResultsFound: Should normally never be an issue.
|
|
91
91
|
"""
|
|
92
92
|
return session.exec(select(AppUser).where(col(AppUser.user) == username)).one()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def upsert_new_user(user_id: int, user: str, session: Session, password: str = '') -> None:
|
|
96
|
+
"""
|
|
97
|
+
Upsert a new user if not already present in db
|
|
98
|
+
"""
|
|
99
|
+
if not session.exec(select(AppUser).where(col(AppUser.id) == user_id)).first():
|
|
100
|
+
session.add(AppUser(user=user, password=password, permission=Permission.Consultant,
|
|
101
|
+
id=user_id))
|
|
102
|
+
session.commit()
|
ecodev_core/authentication.py
CHANGED
|
@@ -93,20 +93,23 @@ class JwtAuth(AuthenticationBackend):
|
|
|
93
93
|
request.session.update(token)
|
|
94
94
|
return True if token else False
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
def authorized(form: Any):
|
|
96
|
+
def authorized(self, form: Any):
|
|
98
97
|
"""
|
|
99
98
|
Check that the user information contained in the form corresponds to an admin user
|
|
100
99
|
"""
|
|
101
100
|
with Session(engine) as session:
|
|
102
101
|
try:
|
|
103
|
-
|
|
104
|
-
if is_admin_user(token['access_token']):
|
|
105
|
-
return token
|
|
106
|
-
return None
|
|
102
|
+
return self.admin_token(form, session)
|
|
107
103
|
except HTTPException:
|
|
108
104
|
return None
|
|
109
105
|
|
|
106
|
+
def admin_token(self, form: Any, session: Session) -> Union[Dict[str, str], None]:
|
|
107
|
+
"""
|
|
108
|
+
Unsafe attempt to retrieve the token, only return it if admin rights
|
|
109
|
+
"""
|
|
110
|
+
token = attempt_to_log(form.get('username', ''), form.get('password', ''), session)
|
|
111
|
+
return token if is_admin_user(token['access_token']) else None
|
|
112
|
+
|
|
110
113
|
async def logout(self, request: Request) -> bool:
|
|
111
114
|
"""
|
|
112
115
|
Logout procedure: clears the cache
|
|
@@ -238,8 +241,6 @@ def _verify_access_token(token: str,
|
|
|
238
241
|
"""
|
|
239
242
|
try:
|
|
240
243
|
payload = jwt.decode(token, AUTH.secret_key, algorithms=[AUTH.algorithm])
|
|
241
|
-
log.critical(tfa_value)
|
|
242
|
-
log.critical(payload.get('tfa'))
|
|
243
244
|
if tfa_check and (not tfa_value or not _check_password(tfa_value, payload.get('tfa'))):
|
|
244
245
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=INVALID_TFA,
|
|
245
246
|
headers={'WWW-Authenticate': 'Bearer'})
|
|
@@ -264,4 +265,3 @@ def _check_password(plain_password: Optional[str], hashed_password: str) -> bool
|
|
|
264
265
|
Check the passed password (compare it to the passed encoded one).
|
|
265
266
|
"""
|
|
266
267
|
return CONTEXT.verify(plain_password, hashed_password)
|
|
267
|
-
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
ecodev_core/__init__.py,sha256=
|
|
1
|
+
ecodev_core/__init__.py,sha256=Fhwb5DHVqYrljLMblgI_OiP0Oas_rsx7DEfMAwGnwKk,4436
|
|
2
2
|
ecodev_core/app_activity.py,sha256=_rU5uPfttHxXX5IaCuTA7K9We5w2qluJ3Xpf6i12HhY,3763
|
|
3
3
|
ecodev_core/app_rights.py,sha256=RZPdDtydFqc_nFj96huKAc56BS0qS6ScKv4Kghqd6lc,726
|
|
4
|
-
ecodev_core/app_user.py,sha256=
|
|
4
|
+
ecodev_core/app_user.py,sha256=eg3MCIyjLOtQF7qf1Lpgnu_FX7zl94PxM4YT7qY3DTE,3350
|
|
5
5
|
ecodev_core/auth_configuration.py,sha256=ZjEB-N5HTo2jaEljwrh6q64Lh5qZ1NuKk8bbpIEcdYc,433
|
|
6
|
-
ecodev_core/authentication.py,sha256=
|
|
6
|
+
ecodev_core/authentication.py,sha256=Algt1YeF6wb5X34av4AB3v2IlEyrsgQjPBQh_IU7ELI,9732
|
|
7
7
|
ecodev_core/backup.py,sha256=9YZ79LkbLMSSoBJFmTr8u9_OPBbDmwasrmCJpqb7lkg,3055
|
|
8
8
|
ecodev_core/check_dependencies.py,sha256=aFn8GI4eBbuJT8RxsfhSSnlpNYYj_LPOH-tZF0EqfKQ,6917
|
|
9
9
|
ecodev_core/custom_equal.py,sha256=2gRn0qpyJ8-Kw9GQSueu0nLngLrRrwyMPlP6zqPac0U,899
|
|
@@ -19,7 +19,7 @@ ecodev_core/permissions.py,sha256=dMaRQyjrF8Y51gkbkFvFsGVdzQGLZtA72IQ7REYamxg,32
|
|
|
19
19
|
ecodev_core/pydantic_utils.py,sha256=e3GH50JmcpTmd2UgrB94QSwWOlOCW3WIlVdyX9C4T-U,741
|
|
20
20
|
ecodev_core/read_write.py,sha256=auJ5bBJTVGkLRkiP_vZxVCX64B0Y-9qpsaDhovHmbas,996
|
|
21
21
|
ecodev_core/safe_utils.py,sha256=uTHzLnKBoV_MiFsI65X-WYmgzLpIBH5Cio80KSLd6wg,5933
|
|
22
|
-
ecodev_core-0.0.
|
|
23
|
-
ecodev_core-0.0.
|
|
24
|
-
ecodev_core-0.0.
|
|
25
|
-
ecodev_core-0.0.
|
|
22
|
+
ecodev_core-0.0.19.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
|
|
23
|
+
ecodev_core-0.0.19.dist-info/METADATA,sha256=fjHBOZeMfAxBcBgqvAEy5RGdm3S3Ws-5jviah0Ih7Hk,3291
|
|
24
|
+
ecodev_core-0.0.19.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
25
|
+
ecodev_core-0.0.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|