elody 0.0.221__py3-none-any.whl → 0.0.223__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.
@@ -1,6 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from copy import deepcopy
3
3
  from elody.migration.base_object_migrator import BaseObjectMigrator
4
+ from os import getenv
4
5
 
5
6
 
6
7
  class BaseObjectConfiguration(ABC):
@@ -95,6 +96,16 @@ class BaseObjectConfiguration(ABC):
95
96
  except Exception:
96
97
  return None
97
98
 
99
+ def _is_request_from_internal_service(self):
100
+ try:
101
+ from flask import request # pyright: ignore
102
+
103
+ return request.headers.get("Authorization", "").removeprefix(
104
+ "Bearer "
105
+ ) == getenv("STATIC_JWT")
106
+ except Exception:
107
+ return False
108
+
98
109
  def _sanitize_document(self, *, document, **kwargs):
99
110
  sanitized_document = {}
100
111
  document_deepcopy = deepcopy(document)
@@ -51,7 +51,6 @@ class ElodyConfiguration(BaseObjectConfiguration):
51
51
  post_body if isinstance(post_body, dict) else {},
52
52
  )
53
53
  _id = document_defaults.get("_id", str(uuid4()))
54
- timestamp = datetime.now(timezone.utc)
55
54
 
56
55
  identifiers = (
57
56
  post_body.pop("identifiers", []) if isinstance(post_body, dict) else []
@@ -87,17 +86,6 @@ class ElodyConfiguration(BaseObjectConfiguration):
87
86
  document = {**template, **document_defaults, **post_body}
88
87
  else:
89
88
  document = {**template, **document_defaults}
90
- document = self._pre_crud_hook(
91
- crud="create",
92
- timestamp=timestamp,
93
- document=document,
94
- audit_override={
95
- "date_created": document_defaults.get("date_created"),
96
- "created_by": document_defaults.get("created_by"),
97
- "date_updated": document_defaults.get("date_updated"),
98
- "last_editor": document_defaults.get("last_editor"),
99
- },
100
- )
101
89
  return document
102
90
 
103
91
  def _document_content_patcher(self, *, document, content, overwrite=False, **_):
@@ -177,6 +165,9 @@ class ElodyConfiguration(BaseObjectConfiguration):
177
165
  return sanitized_document
178
166
 
179
167
  def __patch_document_audit_info(self, crud, document, timestamp, audit_override):
168
+ if self._is_request_from_internal_service():
169
+ return document
170
+
180
171
  document.update({f"date_{crud}d": timestamp})
181
172
  if email := self._get_user_context_id():
182
173
  label = f"{crud}d_by" if crud == "create" else "last_editor"
@@ -0,0 +1,34 @@
1
+ from configuration import get_object_configuration_mapper
2
+ from flask import Request
3
+ from inuits_policy_based_auth.authentication.base_authentication_policy import (
4
+ BaseAuthenticationPolicy,
5
+ )
6
+ from os import getenv
7
+ from storage.storagemanager import StorageManager
8
+
9
+
10
+ class XUserHeadersPolicy(BaseAuthenticationPolicy):
11
+ def authenticate(self, user_context, request_context):
12
+ request: Request = request_context.http_request
13
+
14
+ auth_header = request.headers.get("Authorization", "")
15
+ if auth_header.startswith("Bearer "):
16
+ token = auth_header.removeprefix("Bearer ")
17
+ static_jwt = getenv("STATIC_JWT")
18
+
19
+ if static_jwt and token == static_jwt:
20
+ user_email = request.headers.get("X-User-Email")
21
+ if user_email:
22
+ config = get_object_configuration_mapper().get("user")
23
+ storage_manager = StorageManager()
24
+ user = (
25
+ storage_manager.get_db_engine().get_item_from_collection_by_id(
26
+ config.crud()["collection"], user_email
27
+ )
28
+ )
29
+
30
+ if user:
31
+ user_context.id = user.get("_id", user.get("id"))
32
+ user_context.email = user_email
33
+
34
+ return user_context
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: elody
3
- Version: 0.0.221
3
+ Version: 0.0.223
4
4
  Summary: elody SDK for Python
5
5
  Author-email: Inuits <developers@inuits.eu>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -12,8 +12,8 @@ elody/validator.py,sha256=G7Ya538EJHCFzOxEri2OcFMabfLBCtTKxuf4os_KuNw,260
12
12
  elody/migration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  elody/migration/base_object_migrator.py,sha256=n8uvgGfjEUy60G47RD7Y-oxp1vHLOauwPMDl87LcxtU,436
14
14
  elody/object_configurations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- elody/object_configurations/base_object_configuration.py,sha256=AqOE0hCbXQDOdKFnDa9dbi-A-GRTUAaBZUe6_g0-Dc0,7573
16
- elody/object_configurations/elody_configuration.py,sha256=T_gyQykQWC1wdGTwQ9DujmumG8uqgQlH0vbZKmxtpfw,11049
15
+ elody/object_configurations/base_object_configuration.py,sha256=4lk6BmhRSYxwuD2qqGfE8d9H9ak7iwoOM5gqw7EntTI,7905
16
+ elody/object_configurations/elody_configuration.py,sha256=Bchwd1roBnrMDTdFkJUlUTS_FkrzhAq2kVdphLCdu2M,10621
17
17
  elody/object_configurations/job_configuration.py,sha256=T6QI2wE-u7ZcNpYE5XjmrCzIJglyKUGJsifaTn0WGyg,7512
18
18
  elody/object_configurations/saved_search_configuration.py,sha256=ddOry4EqYOeEKRF7q2M_fHoqZv8DXpQjFq8VaZ7jhVI,732
19
19
  elody/policies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -22,6 +22,7 @@ elody/policies/permission_handler.py,sha256=9vxiYjkPrnqIxWi8X9qoGwb09SQaZmQeF4f_
22
22
  elody/policies/authentication/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  elody/policies/authentication/base_user_tenant_validation_policy.py,sha256=p7draxPCqly1vy7vnJX-gpmRfDeyaTxt9Cf0YpH9PZI,5829
24
24
  elody/policies/authentication/multi_tenant_policy.py,sha256=g4ZYUQMmCjgLg09wj0-0lGKsJsRt7h4ppI25o1VdZHw,4039
25
+ elody/policies/authentication/x_user_headers_policy.py,sha256=AoOZH7cbVI9X7JTWmbH3HdXV2UUf0NJpAiuSI0qnQCI,1350
25
26
  elody/policies/authorization/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
27
  elody/policies/authorization/filter_generic_objects_policy.py,sha256=mF32moh8hRetBgG8vQW-rz4xjoRQD2yOxdI740SFSUo,6522
27
28
  elody/policies/authorization/filter_generic_objects_policy_v2.py,sha256=2IkESYMfne1bX1I8Yvn3yoNmlfn_Jm6zVlVBknoW1_c,6412
@@ -35,13 +36,13 @@ elody/policies/authorization/mediafile_derivatives_policy.py,sha256=OwNpbS8i7-Lz
35
36
  elody/policies/authorization/mediafile_download_policy.py,sha256=XMsKavBucmTh4W1kWOzpFWxJ_ZXgHVK1RS7JB4HjtQo,1979
36
37
  elody/policies/authorization/multi_tenant_policy.py,sha256=SA9H7SBjzuh8mY3gYN7pDG8TV7hdI3GEUtNeiZeNL3M,3164
37
38
  elody/policies/authorization/tenant_request_policy.py,sha256=dEgblwRAqwWVcE-O7Jn8hVL3OnwDlQhDEOcPlcElBrk,1185
38
- elody-0.0.221.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
39
+ elody-0.0.223.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
39
40
  tests/__init_.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
41
  tests/data.py,sha256=Q3oxduf-E3m-Z5G_p3fcs8jVy6g10I7zXKL1m94UVMI,2906
41
42
  tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
43
  tests/unit/test_csv.py,sha256=NQaOhehfQ4GuXku0Y1SA8DYjJeqqidbF50zEHAi8RZA,15923
43
44
  tests/unit/test_utils.py,sha256=g63szcEZyHhCOtrW4BnNbcgVca3oYPIOLjBdIzNwwN0,8784
44
- elody-0.0.221.dist-info/METADATA,sha256=uIEM5H42sBDimKD8UkKIatHIvjiFiNOIWfJ95lDEDVQ,23358
45
- elody-0.0.221.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
- elody-0.0.221.dist-info/top_level.txt,sha256=E0mImupLj0KmtUUCXRYEoLDRaSkuiGaOIIseAa0oQ-M,21
47
- elody-0.0.221.dist-info/RECORD,,
45
+ elody-0.0.223.dist-info/METADATA,sha256=u1QFifFzK7nwVddOPF0pfjnAdb51hP0OuNuGiMiwJac,23358
46
+ elody-0.0.223.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
47
+ elody-0.0.223.dist-info/top_level.txt,sha256=E0mImupLj0KmtUUCXRYEoLDRaSkuiGaOIIseAa0oQ-M,21
48
+ elody-0.0.223.dist-info/RECORD,,