Encryptors 2.22__tar.gz → 2.23__tar.gz
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.
- {encryptors-2.22 → encryptors-2.23}/PKG-INFO +1 -1
- {encryptors-2.22 → encryptors-2.23}/setup.py +1 -1
- {encryptors-2.22 → encryptors-2.23}/src/Encryptors.egg-info/PKG-INFO +1 -1
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Decorators/SecureResolver.py +22 -12
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Helpers/AuditDispatcher.py +5 -6
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/Response.py +3 -3
- {encryptors-2.22 → encryptors-2.23}/README.md +0 -0
- {encryptors-2.22 → encryptors-2.23}/setup.cfg +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Encryptors.egg-info/SOURCES.txt +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Encryptors.egg-info/dependency_links.txt +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Encryptors.egg-info/entry_points.txt +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Encryptors.egg-info/requires.txt +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Encryptors.egg-info/top_level.txt +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Cli/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Database/ISessionFactoryProvider.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Database/SessionFactoryProvider.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Database/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Decorators/Retry.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Decorators/SqlDataNormalizer.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Decorators/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/Aes.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/Argon2.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/Bcrypt.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/Jwt.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/Rsa.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/Sha512.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Encryptor/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Exception/ControlledException.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Exception/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Helpers/AuditLogHelper.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Helpers/KeyVaultService.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Helpers/MessageBus.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Helpers/ShardedQueryExecutor.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Helpers/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Messaging/AzureServiceBus.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Messaging/Kafka.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Messaging/RabbitMQ.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Messaging/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Middlewares/Security.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Middlewares/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/AuditConfig.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/Encryptor.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/GrpcResponse.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/Legacy.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/ShardResource.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/Token.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/_SecurityContext.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Models/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/GraphQLPayloadService.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/GraphQLRequestExtractor.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/Pipeline.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/TenantPolicy.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/TokenService.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/_Ports.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Pipeline/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/RedisCache/Redis.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/RedisCache/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/Code.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/Constant.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/FileType.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/GrahpqlOperation.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/Message.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/Profile.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/ShardQueryPolicy.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Enums/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Logger.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/CaseConverter.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/CodeGenerator.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/DataUtils.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/DateUtils.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/FileMetaData.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/HashValidator.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/Mapper.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/PasswordGenerator.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/QueryGenerator.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/TextProcessor.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/Utils/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Shared/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Storage/AzureBlobStorage.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Storage/S3Storage.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/Storage/__init__.py +0 -0
- {encryptors-2.22 → encryptors-2.23}/src/Osdental/__init__.py +0 -0
|
@@ -4,9 +4,17 @@ from functools import wraps
|
|
|
4
4
|
from typing import Callable, Dict, Any, Iterable
|
|
5
5
|
from graphql import GraphQLResolveInfo
|
|
6
6
|
from Osdental.Shared.Enums.Profile import Profile
|
|
7
|
-
from Osdental.Models.
|
|
7
|
+
from Osdental.Models.Response import Response
|
|
8
|
+
from Osdental.Encryptor.Aes import AES
|
|
9
|
+
from Osdental.Models._SecurityContext import SecurityContext
|
|
8
10
|
from Osdental.Exception.ControlledException import OSDException, UnauthorizedException
|
|
9
11
|
|
|
12
|
+
def _encrypt_if_needed(result: Response, security: SecurityContext) -> Response:
|
|
13
|
+
if result.data is not None and security.encryptor:
|
|
14
|
+
result.data = AES.encrypt(security.encryptor.aes_auth, result.data)
|
|
15
|
+
|
|
16
|
+
return result
|
|
17
|
+
|
|
10
18
|
def secure_resolver(allowed_roles: Iterable[str] | None = None):
|
|
11
19
|
def decorator(func: Callable):
|
|
12
20
|
|
|
@@ -16,8 +24,8 @@ def secure_resolver(allowed_roles: Iterable[str] | None = None):
|
|
|
16
24
|
@wraps(func)
|
|
17
25
|
async def wrapper(obj: Any, info: GraphQLResolveInfo, **rest_kwargs: Dict):
|
|
18
26
|
try:
|
|
19
|
-
security = info.context.security
|
|
20
|
-
token
|
|
27
|
+
security: SecurityContext = info.context.security
|
|
28
|
+
token = security.token
|
|
21
29
|
|
|
22
30
|
if allowed_roles:
|
|
23
31
|
if Profile(token.abbreviation) not in allowed_roles:
|
|
@@ -32,7 +40,9 @@ def secure_resolver(allowed_roles: Iterable[str] | None = None):
|
|
|
32
40
|
if payload:
|
|
33
41
|
rest_kwargs["data"] = payload
|
|
34
42
|
|
|
35
|
-
result = await func(obj, info, **rest_kwargs)
|
|
43
|
+
result: Response = await func(obj, info, **rest_kwargs)
|
|
44
|
+
result = _encrypt_if_needed(result, security)
|
|
45
|
+
|
|
36
46
|
_ = asyncio.create_task(
|
|
37
47
|
info.context.audit_dispatcher.dispatch(
|
|
38
48
|
security=security,
|
|
@@ -40,15 +50,15 @@ def secure_resolver(allowed_roles: Iterable[str] | None = None):
|
|
|
40
50
|
)
|
|
41
51
|
)
|
|
42
52
|
|
|
43
|
-
return result
|
|
53
|
+
return result.send()
|
|
44
54
|
|
|
45
55
|
except (Exception, OSDException) as e:
|
|
46
|
-
result =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
result = Response(
|
|
57
|
+
status=getattr(e, "status_code", "DB_ERROR_UNEXPECTED"),
|
|
58
|
+
message=getattr(e, "message", "Could not process request."),
|
|
59
|
+
error=getattr(e, "error", type(e).__name__),
|
|
60
|
+
data=None
|
|
61
|
+
)
|
|
52
62
|
|
|
53
63
|
_ = asyncio.create_task(
|
|
54
64
|
info.context.audit_dispatcher.dispatch(
|
|
@@ -57,7 +67,7 @@ def secure_resolver(allowed_roles: Iterable[str] | None = None):
|
|
|
57
67
|
)
|
|
58
68
|
)
|
|
59
69
|
|
|
60
|
-
return result
|
|
70
|
+
return result.send()
|
|
61
71
|
|
|
62
72
|
return wrapper
|
|
63
73
|
return decorator
|
|
@@ -4,6 +4,7 @@ from Osdental.Shared.Logger import logger
|
|
|
4
4
|
from Osdental.Helpers.AuditLogHelper import AuditLogHelper
|
|
5
5
|
from Osdental.Models.AuditConfig import AuditConfig
|
|
6
6
|
from Osdental.Messaging import IMessageQueue
|
|
7
|
+
from Osdental.Models.Response import Response
|
|
7
8
|
|
|
8
9
|
class AuditType(Enum):
|
|
9
10
|
RESPONSE = "RESPONSE"
|
|
@@ -65,7 +66,7 @@ class AuditDispatcher:
|
|
|
65
66
|
# Aquí vive toda la lógica fea
|
|
66
67
|
async def _process(self, payload):
|
|
67
68
|
security = payload["security"]
|
|
68
|
-
result = payload["result"]
|
|
69
|
+
result: Response = payload["result"]
|
|
69
70
|
|
|
70
71
|
operation_name = security.gql_request.operation_name
|
|
71
72
|
if operation_name == 'UnknownOperation':
|
|
@@ -76,16 +77,14 @@ class AuditDispatcher:
|
|
|
76
77
|
security, self.audit_config
|
|
77
78
|
)
|
|
78
79
|
|
|
79
|
-
status = result.
|
|
80
|
-
data = result.get("data")
|
|
81
|
-
error = result.get("error")
|
|
80
|
+
status = result.status
|
|
82
81
|
|
|
83
82
|
ERROR_PREFIXES = ("DB_ERROR", "DB_WARNING")
|
|
84
83
|
if status.upper().startswith(ERROR_PREFIXES):
|
|
85
84
|
payload = AuditLogHelper.build_final_payload(
|
|
86
85
|
type=AuditType.ERROR.value,
|
|
87
86
|
status_code=status,
|
|
88
|
-
error=error
|
|
87
|
+
error=result.error
|
|
89
88
|
)
|
|
90
89
|
|
|
91
90
|
audit_message = request_audit_payload | payload
|
|
@@ -94,7 +93,7 @@ class AuditDispatcher:
|
|
|
94
93
|
payload = AuditLogHelper.build_final_payload(
|
|
95
94
|
type=AuditType.RESPONSE.value,
|
|
96
95
|
status_code=status,
|
|
97
|
-
result=data
|
|
96
|
+
result=result.data
|
|
98
97
|
)
|
|
99
98
|
|
|
100
99
|
audit_message = request_audit_payload | payload
|
|
@@ -7,7 +7,7 @@ class Response(BaseModel):
|
|
|
7
7
|
status: str = Code.PROCESS_SUCCESS_CODE
|
|
8
8
|
message: str = Message.PROCESS_SUCCESS_MSG
|
|
9
9
|
data: Optional[Any] = None
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
error: Optional[str] = None
|
|
11
|
+
|
|
12
12
|
def send(self):
|
|
13
|
-
return self.model_dump()
|
|
13
|
+
return self.model_dump(exclude={"error"})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|