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