ecodev-core 0.0.19__py3-none-any.whl → 0.0.21__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 +4 -3
- ecodev_core/app_user.py +0 -10
- ecodev_core/authentication.py +14 -0
- ecodev_core/backup.py +3 -3
- ecodev_core/safe_utils.py +8 -0
- {ecodev_core-0.0.19.dist-info → ecodev_core-0.0.21.dist-info}/METADATA +1 -1
- {ecodev_core-0.0.19.dist-info → ecodev_core-0.0.21.dist-info}/RECORD +9 -9
- {ecodev_core-0.0.19.dist-info → ecodev_core-0.0.21.dist-info}/LICENSE.md +0 -0
- {ecodev_core-0.0.19.dist-info → ecodev_core-0.0.21.dist-info}/WHEEL +0 -0
ecodev_core/__init__.py
CHANGED
|
@@ -10,7 +10,6 @@ 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
|
|
14
13
|
from ecodev_core.auth_configuration import AUTH
|
|
15
14
|
from ecodev_core.authentication import attempt_to_log
|
|
16
15
|
from ecodev_core.authentication import get_access_token
|
|
@@ -24,6 +23,7 @@ from ecodev_core.authentication import JwtAuth
|
|
|
24
23
|
from ecodev_core.authentication import safe_get_user
|
|
25
24
|
from ecodev_core.authentication import SCHEME
|
|
26
25
|
from ecodev_core.authentication import Token
|
|
26
|
+
from ecodev_core.authentication import upsert_new_user
|
|
27
27
|
from ecodev_core.backup import backup
|
|
28
28
|
from ecodev_core.check_dependencies import check_dependencies
|
|
29
29
|
from ecodev_core.check_dependencies import compute_dependencies
|
|
@@ -61,13 +61,13 @@ from ecodev_core.read_write import load_json_file
|
|
|
61
61
|
from ecodev_core.read_write import make_dir
|
|
62
62
|
from ecodev_core.read_write import write_json_file
|
|
63
63
|
from ecodev_core.safe_utils import boolify
|
|
64
|
+
from ecodev_core.safe_utils import datify
|
|
64
65
|
from ecodev_core.safe_utils import floatify
|
|
65
66
|
from ecodev_core.safe_utils import intify
|
|
66
67
|
from ecodev_core.safe_utils import safe_clt
|
|
67
68
|
from ecodev_core.safe_utils import SafeTestCase
|
|
68
69
|
from ecodev_core.safe_utils import SimpleReturn
|
|
69
70
|
from ecodev_core.safe_utils import stringify
|
|
70
|
-
|
|
71
71
|
__all__ = [
|
|
72
72
|
'AUTH', 'Token', 'get_app_services', 'attempt_to_log', 'get_current_user', 'is_admin_user',
|
|
73
73
|
'write_json_file', 'load_json_file', 'make_dir', 'check_dependencies', 'compute_dependencies',
|
|
@@ -79,4 +79,5 @@ __all__ = [
|
|
|
79
79
|
'enum_converter', 'ServerSideFilter', 'get_rows', 'count_rows', 'ServerSideField', 'get_raw_df',
|
|
80
80
|
'generic_insertion', 'custom_equal', 'is_authorized_user', 'get_method', 'AppActivity',
|
|
81
81
|
'fastapi_monitor', 'dash_monitor', 'is_monitoring_user', 'get_recent_activities', 'select_user',
|
|
82
|
-
'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user'
|
|
82
|
+
'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user',
|
|
83
|
+
'datify']
|
ecodev_core/app_user.py
CHANGED
|
@@ -90,13 +90,3 @@ 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
|
@@ -221,6 +221,20 @@ def is_monitoring_user(token: str = Depends(SCHEME)) -> AppUser:
|
|
|
221
221
|
detail=MONITORING_ERROR, headers={'WWW-Authenticate': 'Bearer'})
|
|
222
222
|
|
|
223
223
|
|
|
224
|
+
def upsert_new_user(token: str, user: str, password: str = '') -> None:
|
|
225
|
+
"""
|
|
226
|
+
Upsert a new user if not already present in db.
|
|
227
|
+
|
|
228
|
+
NB: this method RAISES a http error if he token is invalid
|
|
229
|
+
"""
|
|
230
|
+
user_id = _verify_access_token(token).id
|
|
231
|
+
with Session(engine) as session:
|
|
232
|
+
if not session.exec(select(AppUser).where(col(AppUser.id) == user_id)).first():
|
|
233
|
+
session.add(AppUser(user=user, password=password, permission=Permission.Consultant,
|
|
234
|
+
id=user_id))
|
|
235
|
+
session.commit()
|
|
236
|
+
|
|
237
|
+
|
|
224
238
|
def _create_access_token(data: Dict, tfa_value: Optional[str] = None) -> str:
|
|
225
239
|
"""
|
|
226
240
|
Create an access token out of the passed data. Only called if credentials are valid
|
ecodev_core/backup.py
CHANGED
|
@@ -34,13 +34,13 @@ BCK = BackUpSettings()
|
|
|
34
34
|
BACKUP_URL = f'ftp://{BCK.backup_username}:{BCK.backup_password}@{BCK.backup_url}'
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def backup(backed_folder: Path, nb_saves: int = 5) -> None:
|
|
37
|
+
def backup(backed_folder: Path, nb_saves: int = 5, additional_id: str = 'default') -> None:
|
|
38
38
|
"""
|
|
39
39
|
Backup db and backed_folder: write the dump/tar on the backup server and erase old copies
|
|
40
40
|
"""
|
|
41
41
|
timestamp = datetime.now().strftime('%Y_%m_%d_%Hh_%Mmn_%Ss')
|
|
42
|
-
_backup_db(Path.cwd() / f'
|
|
43
|
-
_backup_files(backed_folder, Path.cwd() / f'
|
|
42
|
+
_backup_db(Path.cwd() / f'{additional_id}_db.{timestamp}.dump', nb_saves)
|
|
43
|
+
_backup_files(backed_folder, Path.cwd() / f'{additional_id}_files.{timestamp}.tgz', nb_saves)
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def _backup_db(db_dump_path: Path, nb_saves: int) -> None:
|
ecodev_core/safe_utils.py
CHANGED
|
@@ -4,6 +4,7 @@ This boilerplate code is not to be touched under any circumstances.
|
|
|
4
4
|
"""
|
|
5
5
|
import contextlib
|
|
6
6
|
import shutil
|
|
7
|
+
from datetime import datetime
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from typing import Any
|
|
9
10
|
from typing import Callable
|
|
@@ -170,6 +171,13 @@ def floatify(x: Union[str, float]) -> Union[float, None]:
|
|
|
170
171
|
return _transformify(x, float)
|
|
171
172
|
|
|
172
173
|
|
|
174
|
+
def datify(date: str, date_format: str) -> Union[datetime, None]:
|
|
175
|
+
"""
|
|
176
|
+
Safe conversion to a date format
|
|
177
|
+
"""
|
|
178
|
+
return _transformify(date, lambda x: datetime.strptime(x, date_format))
|
|
179
|
+
|
|
180
|
+
|
|
173
181
|
def _transformify(x: Union[Any, float], transformation: Callable) -> Union[Any, None]:
|
|
174
182
|
"""
|
|
175
183
|
Safe conversion of a (Any, np.nan) value into a (Any,None) one thanks to transformation
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
ecodev_core/__init__.py,sha256=
|
|
1
|
+
ecodev_core/__init__.py,sha256=LssQSv0CD5SyuHK07j-0i_Dgawj-6tZghtzsnHTwpX0,4497
|
|
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=r1bqA4H08x53XmxmjwyGKl_PFjYQazzBbVErdkztqeE,2947
|
|
5
5
|
ecodev_core/auth_configuration.py,sha256=ZjEB-N5HTo2jaEljwrh6q64Lh5qZ1NuKk8bbpIEcdYc,433
|
|
6
|
-
ecodev_core/authentication.py,sha256=
|
|
7
|
-
ecodev_core/backup.py,sha256=
|
|
6
|
+
ecodev_core/authentication.py,sha256=XL_hPRw_jd1jFxASFmxB1GJqCeg8zY8S8GFt2Y1XoGE,10278
|
|
7
|
+
ecodev_core/backup.py,sha256=8fwBHic6hE8swNESIayZqqWZFHFz5f-puBWSt5f_ZLw,3119
|
|
8
8
|
ecodev_core/check_dependencies.py,sha256=aFn8GI4eBbuJT8RxsfhSSnlpNYYj_LPOH-tZF0EqfKQ,6917
|
|
9
9
|
ecodev_core/custom_equal.py,sha256=2gRn0qpyJ8-Kw9GQSueu0nLngLrRrwyMPlP6zqPac0U,899
|
|
10
10
|
ecodev_core/db_connection.py,sha256=ha2YVVQQwQ5WCyrUnaKq4LSaXoPGGbh19xKRbr438U8,1773
|
|
@@ -18,8 +18,8 @@ ecodev_core/pandas_utils.py,sha256=bkobhqj_tWrFCgBGQwPJLwN59HJunNDeBKhnctWCUBE,1
|
|
|
18
18
|
ecodev_core/permissions.py,sha256=dMaRQyjrF8Y51gkbkFvFsGVdzQGLZtA72IQ7REYamxg,320
|
|
19
19
|
ecodev_core/pydantic_utils.py,sha256=e3GH50JmcpTmd2UgrB94QSwWOlOCW3WIlVdyX9C4T-U,741
|
|
20
20
|
ecodev_core/read_write.py,sha256=auJ5bBJTVGkLRkiP_vZxVCX64B0Y-9qpsaDhovHmbas,996
|
|
21
|
-
ecodev_core/safe_utils.py,sha256=
|
|
22
|
-
ecodev_core-0.0.
|
|
23
|
-
ecodev_core-0.0.
|
|
24
|
-
ecodev_core-0.0.
|
|
25
|
-
ecodev_core-0.0.
|
|
21
|
+
ecodev_core/safe_utils.py,sha256=JCfxo6fcznjsL-XHNJ1TKo1UvfJB83WT5jpTFmtJwsE,6160
|
|
22
|
+
ecodev_core-0.0.21.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
|
|
23
|
+
ecodev_core-0.0.21.dist-info/METADATA,sha256=Y6_S-i86wPWNmp8Mbew1ucWsQJeeK0TB5dr6YeG4WSs,3291
|
|
24
|
+
ecodev_core-0.0.21.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
25
|
+
ecodev_core-0.0.21.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|