maleo-identity 0.0.77__py3-none-any.whl → 0.0.79__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 maleo-identity might be problematic. Click here for more details.
- maleo/identity/client/manager.py +154 -154
- maleo/identity/client/services/organization.py +1944 -1944
- maleo/identity/client/services/organization_registration_code.py +470 -470
- maleo/identity/client/services/organization_role.py +254 -254
- maleo/identity/client/services/user.py +1559 -1559
- maleo/identity/client/services/user_organization.py +254 -254
- maleo/identity/client/services/user_organization_role.py +256 -256
- maleo/identity/client/services/user_profile.py +254 -254
- maleo/identity/client/services/user_system_role.py +254 -254
- maleo/identity/mixins/organization_registration_code.py +5 -0
- maleo/identity/schemas/parameter/general/organization_registration_code.py +33 -9
- {maleo_identity-0.0.77.dist-info → maleo_identity-0.0.79.dist-info}/METADATA +3 -3
- {maleo_identity-0.0.77.dist-info → maleo_identity-0.0.79.dist-info}/RECORD +15 -15
- {maleo_identity-0.0.77.dist-info → maleo_identity-0.0.79.dist-info}/WHEEL +0 -0
- {maleo_identity-0.0.77.dist-info → maleo_identity-0.0.79.dist-info}/top_level.txt +0 -0
|
@@ -1,278 +1,278 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from copy import deepcopy
|
|
3
|
-
from Crypto.PublicKey.RSA import RsaKey
|
|
4
|
-
from datetime import datetime, timezone
|
|
5
|
-
from redis.asyncio.client import Redis
|
|
6
|
-
from typing import Dict, List, Optional
|
|
7
|
-
from uuid import UUID
|
|
8
|
-
from maleo.soma.authorization import BearerAuth
|
|
9
|
-
from maleo.soma.dtos.configurations.cache.redis import RedisCacheNamespaces
|
|
10
|
-
from maleo.soma.enums.environment import Environment
|
|
11
|
-
from maleo.soma.enums.expiration import Expiration
|
|
12
|
-
from maleo.soma.enums.logging import LogLevel
|
|
13
|
-
from maleo.soma.enums.operation import OperationTarget
|
|
14
|
-
from maleo.soma.managers.client.maleo import MaleoClientService
|
|
15
|
-
from maleo.soma.managers.client.http import HTTPClientManager
|
|
16
|
-
from maleo.soma.managers.credential import CredentialManager
|
|
17
|
-
from maleo.soma.schemas.authentication import Authentication
|
|
18
|
-
from maleo.soma.schemas.authorization import Authorization
|
|
19
|
-
from maleo.soma.schemas.data import DataPair
|
|
20
|
-
from maleo.soma.schemas.operation.context import (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
from maleo.soma.schemas.operation.resource import (
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
from maleo.soma.schemas.operation.resource.action import ReadResourceOperationAction
|
|
30
|
-
from maleo.soma.schemas.operation.resource.result import (
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
from maleo.soma.schemas.operation.timestamp import OperationTimestamp
|
|
34
|
-
from maleo.soma.schemas.pagination import StrictPagination
|
|
35
|
-
from maleo.soma.schemas.request import RequestContext
|
|
36
|
-
from maleo.soma.schemas.response import (
|
|
37
|
-
|
|
38
|
-
)
|
|
39
|
-
from maleo.soma.schemas.service import ServiceContext
|
|
40
|
-
from maleo.soma.utils.cache import build_key
|
|
41
|
-
from maleo.soma.utils.logging import ClientLogger
|
|
42
|
-
from maleo.soma.utils.merger import merge_dicts
|
|
43
|
-
from maleo.soma.utils.token import reencode
|
|
44
|
-
from maleo.identity.constants.user_organization_role import RESOURCE
|
|
45
|
-
from maleo.identity.schemas.data.user_organization_role import (
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
from maleo.identity.schemas.parameter.client.user_organization_role import (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)
|
|
1
|
+
# import json
|
|
2
|
+
# from copy import deepcopy
|
|
3
|
+
# from Crypto.PublicKey.RSA import RsaKey
|
|
4
|
+
# from datetime import datetime, timezone
|
|
5
|
+
# from redis.asyncio.client import Redis
|
|
6
|
+
# from typing import Dict, List, Optional
|
|
7
|
+
# from uuid import UUID
|
|
8
|
+
# from maleo.soma.authorization import BearerAuth
|
|
9
|
+
# from maleo.soma.dtos.configurations.cache.redis import RedisCacheNamespaces
|
|
10
|
+
# from maleo.soma.enums.environment import Environment
|
|
11
|
+
# from maleo.soma.enums.expiration import Expiration
|
|
12
|
+
# from maleo.soma.enums.logging import LogLevel
|
|
13
|
+
# from maleo.soma.enums.operation import OperationTarget
|
|
14
|
+
# from maleo.soma.managers.client.maleo import MaleoClientService
|
|
15
|
+
# from maleo.soma.managers.client.http import HTTPClientManager
|
|
16
|
+
# from maleo.soma.managers.credential import CredentialManager
|
|
17
|
+
# from maleo.soma.schemas.authentication import Authentication
|
|
18
|
+
# from maleo.soma.schemas.authorization import Authorization
|
|
19
|
+
# from maleo.soma.schemas.data import DataPair
|
|
20
|
+
# from maleo.soma.schemas.operation.context import (
|
|
21
|
+
# OperationContextSchema,
|
|
22
|
+
# OperationOriginSchema,
|
|
23
|
+
# OperationLayerSchema,
|
|
24
|
+
# OperationTargetSchema,
|
|
25
|
+
# )
|
|
26
|
+
# from maleo.soma.schemas.operation.resource import (
|
|
27
|
+
# ReadMultipleResourceOperationSchema,
|
|
28
|
+
# )
|
|
29
|
+
# from maleo.soma.schemas.operation.resource.action import ReadResourceOperationAction
|
|
30
|
+
# from maleo.soma.schemas.operation.resource.result import (
|
|
31
|
+
# ReadMultipleResourceOperationResult,
|
|
32
|
+
# )
|
|
33
|
+
# from maleo.soma.schemas.operation.timestamp import OperationTimestamp
|
|
34
|
+
# from maleo.soma.schemas.pagination import StrictPagination
|
|
35
|
+
# from maleo.soma.schemas.request import RequestContext
|
|
36
|
+
# from maleo.soma.schemas.response import (
|
|
37
|
+
# MultipleDataResponseSchema,
|
|
38
|
+
# )
|
|
39
|
+
# from maleo.soma.schemas.service import ServiceContext
|
|
40
|
+
# from maleo.soma.utils.cache import build_key
|
|
41
|
+
# from maleo.soma.utils.logging import ClientLogger
|
|
42
|
+
# from maleo.soma.utils.merger import merge_dicts
|
|
43
|
+
# from maleo.soma.utils.token import reencode
|
|
44
|
+
# from maleo.identity.constants.user_organization_role import RESOURCE
|
|
45
|
+
# from maleo.identity.schemas.data.user_organization_role import (
|
|
46
|
+
# UserOrganizationRoleDataSchema,
|
|
47
|
+
# )
|
|
48
|
+
# from maleo.identity.schemas.parameter.client.user_organization_role import (
|
|
49
|
+
# ReadMultipleParameter,
|
|
50
|
+
# ReadMultipleQueryParameter,
|
|
51
|
+
# )
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
class UserOrganizationRoleClientService(MaleoClientService):
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
54
|
+
# class UserOrganizationRoleClientService(MaleoClientService):
|
|
55
|
+
# def __init__(
|
|
56
|
+
# self,
|
|
57
|
+
# environment: Environment,
|
|
58
|
+
# key: str,
|
|
59
|
+
# url: str,
|
|
60
|
+
# operation_origin: OperationOriginSchema,
|
|
61
|
+
# logger: ClientLogger,
|
|
62
|
+
# credential_manager: CredentialManager,
|
|
63
|
+
# http_client_manager: HTTPClientManager,
|
|
64
|
+
# private_key: RsaKey,
|
|
65
|
+
# redis: Redis,
|
|
66
|
+
# redis_namespaces: RedisCacheNamespaces,
|
|
67
|
+
# service_context: ServiceContext,
|
|
68
|
+
# ):
|
|
69
|
+
# super().__init__(
|
|
70
|
+
# environment,
|
|
71
|
+
# key,
|
|
72
|
+
# url,
|
|
73
|
+
# operation_origin,
|
|
74
|
+
# logger,
|
|
75
|
+
# credential_manager,
|
|
76
|
+
# http_client_manager,
|
|
77
|
+
# private_key,
|
|
78
|
+
# redis,
|
|
79
|
+
# redis_namespaces,
|
|
80
|
+
# service_context,
|
|
81
|
+
# )
|
|
82
|
+
# # self._controllers = controllers
|
|
83
|
+
# self._namespace = self._redis_namespaces.create(
|
|
84
|
+
# self._key,
|
|
85
|
+
# RESOURCE.aggregate(),
|
|
86
|
+
# origin=self._CACHE_ORIGIN,
|
|
87
|
+
# layer=self._CACHE_LAYER,
|
|
88
|
+
# )
|
|
89
|
+
# self._default_operation_context = OperationContextSchema(
|
|
90
|
+
# origin=self._operation_origin,
|
|
91
|
+
# layer=OperationLayerSchema(type=self._OPERATION_LAYER_TYPE, details=None),
|
|
92
|
+
# target=OperationTargetSchema(
|
|
93
|
+
# type=self._OPERATION_TARGET_TYPE, details=None
|
|
94
|
+
# ),
|
|
95
|
+
# )
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
# async def read_user_organization_roles(
|
|
98
|
+
# self,
|
|
99
|
+
# operation_id: UUID,
|
|
100
|
+
# request_context: RequestContext,
|
|
101
|
+
# authentication: Authentication,
|
|
102
|
+
# parameters: ReadMultipleParameter,
|
|
103
|
+
# authorization: Optional[Authorization] = None,
|
|
104
|
+
# headers: Optional[Dict[str, str]] = None,
|
|
105
|
+
# ) -> ReadMultipleResourceOperationResult[
|
|
106
|
+
# UserOrganizationRoleDataSchema, StrictPagination, None
|
|
107
|
+
# ]:
|
|
108
|
+
# """Retrieve user organization roles from MaleoIdentity"""
|
|
109
|
+
# operation_action = ReadResourceOperationAction()
|
|
110
|
+
# executed_at = datetime.now(tz=timezone.utc)
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
# # Get function identifier
|
|
113
|
+
# func = self.__class__
|
|
114
|
+
# module, qualname = func.__module__, func.__qualname__
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
# # Define arguments being used in this function
|
|
117
|
+
# positional_arguments = []
|
|
118
|
+
# keyword_arguments = {
|
|
119
|
+
# "authentication": authentication.model_dump(
|
|
120
|
+
# mode="json",
|
|
121
|
+
# exclude={
|
|
122
|
+
# "credentials": {
|
|
123
|
+
# "token": {
|
|
124
|
+
# "payload": {
|
|
125
|
+
# "iat_dt",
|
|
126
|
+
# "iat",
|
|
127
|
+
# "exp_dt",
|
|
128
|
+
# "exp",
|
|
129
|
+
# }
|
|
130
|
+
# }
|
|
131
|
+
# }
|
|
132
|
+
# },
|
|
133
|
+
# ),
|
|
134
|
+
# "parameters": parameters.model_dump(mode="json"),
|
|
135
|
+
# }
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
# # Define full function string
|
|
138
|
+
# function = f"{qualname}({json.dumps(positional_arguments)}|{json.dumps(keyword_arguments)})"
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
# # Define full cache key
|
|
141
|
+
# cache_key = build_key(module, function, namespace=self._namespace)
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
# if parameters.use_cache:
|
|
144
|
+
# operation_context = deepcopy(self._default_operation_context)
|
|
145
|
+
# operation_context.target.type = OperationTarget.CACHE
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
# # Check redis for data
|
|
148
|
+
# result_str = await self._redis.get(cache_key)
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
150
|
+
# if result_str is not None:
|
|
151
|
+
# completed_at = datetime.now(tz=timezone.utc)
|
|
152
|
+
# result = ReadMultipleResourceOperationResult[
|
|
153
|
+
# UserOrganizationRoleDataSchema, StrictPagination, None
|
|
154
|
+
# ].model_validate(json.loads(result_str))
|
|
155
|
+
# ReadMultipleResourceOperationSchema[
|
|
156
|
+
# UserOrganizationRoleDataSchema, StrictPagination, None
|
|
157
|
+
# ](
|
|
158
|
+
# service_context=self._service_context,
|
|
159
|
+
# id=operation_id,
|
|
160
|
+
# context=operation_context,
|
|
161
|
+
# timestamp=OperationTimestamp(
|
|
162
|
+
# executed_at=executed_at,
|
|
163
|
+
# completed_at=completed_at,
|
|
164
|
+
# duration=(completed_at - executed_at).total_seconds(),
|
|
165
|
+
# ),
|
|
166
|
+
# summary="Successfully retrieved multiple user organization roles from cache",
|
|
167
|
+
# request_context=request_context,
|
|
168
|
+
# authentication=authentication,
|
|
169
|
+
# action=operation_action,
|
|
170
|
+
# resource=RESOURCE,
|
|
171
|
+
# result=result,
|
|
172
|
+
# ).log(
|
|
173
|
+
# self._logger, level=LogLevel.INFO
|
|
174
|
+
# )
|
|
175
|
+
# return result
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
# operation_context = deepcopy(self._default_operation_context)
|
|
178
|
+
# async with self._http_client_manager.get() as http_client:
|
|
179
|
+
# url = f"{self._url}/v1/{RESOURCE.identifiers[0].url_slug}/"
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
# # Parse parameters to query params
|
|
182
|
+
# params = ReadMultipleQueryParameter.model_validate(
|
|
183
|
+
# parameters.model_dump()
|
|
184
|
+
# ).model_dump(exclude={"sort_columns", "date_filters"}, exclude_none=True)
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
# # Create headers
|
|
187
|
+
# base_headers = {
|
|
188
|
+
# "Content-Type": "application/json",
|
|
189
|
+
# "X-Operation_Id": str(operation_id),
|
|
190
|
+
# }
|
|
191
|
+
# if headers is not None:
|
|
192
|
+
# headers = merge_dicts(base_headers, headers)
|
|
193
|
+
# else:
|
|
194
|
+
# headers = base_headers
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
# # Create auth
|
|
197
|
+
# token = None
|
|
198
|
+
# if authentication.credentials.token is not None:
|
|
199
|
+
# try:
|
|
200
|
+
# token = reencode(
|
|
201
|
+
# payload=authentication.credentials.token.payload,
|
|
202
|
+
# key=self._private_key,
|
|
203
|
+
# )
|
|
204
|
+
# except Exception:
|
|
205
|
+
# pass
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
# if (
|
|
208
|
+
# token is None
|
|
209
|
+
# and authorization is not None
|
|
210
|
+
# and authorization.scheme == "Bearer"
|
|
211
|
+
# ):
|
|
212
|
+
# token = authorization.credentials
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
# if token is None:
|
|
215
|
+
# token = self._credential_manager.token
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
# auth = BearerAuth(token) if token is not None else None
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
219
|
+
# # Send request and wait for response
|
|
220
|
+
# response = await http_client.get(
|
|
221
|
+
# url=url, params=params, headers=headers, auth=auth
|
|
222
|
+
# )
|
|
223
223
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
224
|
+
# if response.is_success:
|
|
225
|
+
# completed_at = datetime.now(tz=timezone.utc)
|
|
226
|
+
# validated_response = MultipleDataResponseSchema[
|
|
227
|
+
# UserOrganizationRoleDataSchema, StrictPagination, None
|
|
228
|
+
# ].model_validate(response.json())
|
|
229
|
+
# data = DataPair[List[UserOrganizationRoleDataSchema], None](
|
|
230
|
+
# old=validated_response.data,
|
|
231
|
+
# new=None,
|
|
232
|
+
# )
|
|
233
|
+
# result = ReadMultipleResourceOperationResult[
|
|
234
|
+
# UserOrganizationRoleDataSchema, StrictPagination, None
|
|
235
|
+
# ](
|
|
236
|
+
# data=data,
|
|
237
|
+
# pagination=validated_response.pagination,
|
|
238
|
+
# metadata=None,
|
|
239
|
+
# other=None,
|
|
240
|
+
# )
|
|
241
|
+
# ReadMultipleResourceOperationSchema[
|
|
242
|
+
# UserOrganizationRoleDataSchema, StrictPagination, None
|
|
243
|
+
# ](
|
|
244
|
+
# service_context=self._service_context,
|
|
245
|
+
# id=operation_id,
|
|
246
|
+
# context=operation_context,
|
|
247
|
+
# timestamp=OperationTimestamp(
|
|
248
|
+
# executed_at=executed_at,
|
|
249
|
+
# completed_at=completed_at,
|
|
250
|
+
# duration=(completed_at - executed_at).total_seconds(),
|
|
251
|
+
# ),
|
|
252
|
+
# summary="Successfully retrieved multiple user organization roles from http request",
|
|
253
|
+
# request_context=request_context,
|
|
254
|
+
# authentication=authentication,
|
|
255
|
+
# action=operation_action,
|
|
256
|
+
# resource=RESOURCE,
|
|
257
|
+
# result=result,
|
|
258
|
+
# ).log(
|
|
259
|
+
# self._logger, level=LogLevel.INFO
|
|
260
|
+
# )
|
|
261
261
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
# if parameters.use_cache:
|
|
263
|
+
# await self._redis.set(
|
|
264
|
+
# cache_key, result.model_dump_json(), Expiration.EXP_1WK
|
|
265
|
+
# )
|
|
266
266
|
|
|
267
|
-
|
|
267
|
+
# return result
|
|
268
268
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
269
|
+
# self._raise_resource_http_request_error(
|
|
270
|
+
# response=response,
|
|
271
|
+
# operation_id=operation_id,
|
|
272
|
+
# operation_context=operation_context,
|
|
273
|
+
# executed_at=executed_at,
|
|
274
|
+
# operation_action=operation_action,
|
|
275
|
+
# request_context=request_context,
|
|
276
|
+
# authentication=authentication,
|
|
277
|
+
# resource=RESOURCE,
|
|
278
|
+
# )
|