maleo-identity 0.0.77__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.

@@ -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
- 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
- )
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
- 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
- )
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
- 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)
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
- # Get function identifier
113
- func = self.__class__
114
- module, qualname = func.__module__, func.__qualname__
112
+ # # Get function identifier
113
+ # func = self.__class__
114
+ # module, qualname = func.__module__, func.__qualname__
115
115
 
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
- }
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
- # Define full function string
138
- function = f"{qualname}({json.dumps(positional_arguments)}|{json.dumps(keyword_arguments)})"
137
+ # # Define full function string
138
+ # function = f"{qualname}({json.dumps(positional_arguments)}|{json.dumps(keyword_arguments)})"
139
139
 
140
- # Define full cache key
141
- cache_key = build_key(module, function, namespace=self._namespace)
140
+ # # Define full cache key
141
+ # cache_key = build_key(module, function, namespace=self._namespace)
142
142
 
143
- if parameters.use_cache:
144
- operation_context = deepcopy(self._default_operation_context)
145
- operation_context.target.type = OperationTarget.CACHE
143
+ # if parameters.use_cache:
144
+ # operation_context = deepcopy(self._default_operation_context)
145
+ # operation_context.target.type = OperationTarget.CACHE
146
146
 
147
- # Check redis for data
148
- result_str = await self._redis.get(cache_key)
147
+ # # Check redis for data
148
+ # result_str = await self._redis.get(cache_key)
149
149
 
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
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
- 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}/"
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
- # 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)
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
- # 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
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
- # 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
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
- if (
208
- token is None
209
- and authorization is not None
210
- and authorization.scheme == "Bearer"
211
- ):
212
- token = authorization.credentials
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
- if token is None:
215
- token = self._credential_manager.token
214
+ # if token is None:
215
+ # token = self._credential_manager.token
216
216
 
217
- auth = BearerAuth(token) if token is not None else None
217
+ # auth = BearerAuth(token) if token is not None else None
218
218
 
219
- # Send request and wait for response
220
- response = await http_client.get(
221
- url=url, params=params, headers=headers, auth=auth
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
- 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
- )
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
- if parameters.use_cache:
263
- await self._redis.set(
264
- cache_key, result.model_dump_json(), Expiration.EXP_1WK
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
- return result
267
+ # return result
268
268
 
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
- )
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
+ # )