ul-api-utils 7.3.1__py3-none-any.whl → 7.3.3__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 ul-api-utils might be problematic. Click here for more details.

@@ -10,6 +10,7 @@ from functools import wraps
10
10
  from typing import List, Union, Callable, Tuple, Any, Optional, TypeVar, cast, Set, TYPE_CHECKING
11
11
 
12
12
  from flask import Response, request, Flask, url_for as flask_url_for, _app_ctx_stack
13
+ from pydantic import BaseModel
13
14
  from ul_py_tool.utils.arg_files_glob import arg_files_print
14
15
  from werkzeug import Response as BaseResponse
15
16
 
@@ -19,7 +20,7 @@ from ul_api_utils.api_resource.api_resource import ApiResource
19
20
  from ul_api_utils.api_resource.api_resource_config import ApiResourceConfig
20
21
  from ul_api_utils.api_resource.api_resource_fn_typing import ApiResourceFnTyping
21
22
  from ul_api_utils.api_resource.api_resource_type import ApiResourceType
22
- from ul_api_utils.api_resource.api_response import ApiResponse, JsonApiResponse, RootJsonApiResponse, ProxyJsonApiResponse
23
+ from ul_api_utils.api_resource.api_response import ApiResponse, JsonApiResponse, RootJsonApiResponse, ProxyJsonApiResponse, AnyJsonApiResponse
23
24
  from ul_api_utils.conf import APPLICATION_DEBUGGER_PIN, APPLICATION_DEBUG, APPLICATION_DIR, APPLICATION_ENV_IS_LOCAL, \
24
25
  APPLICATION_START_DT
25
26
  from ul_api_utils.const import REQUEST_HEADER__DEBUGGER, REQUEST_HEADER__INTERNAL
@@ -76,6 +77,19 @@ def clean_files() -> None:
76
77
  files.clear()
77
78
 
78
79
 
80
+ def _get_error_types(response: ApiResponse) -> Optional[str]:
81
+ if isinstance(response, AnyJsonApiResponse) and isinstance(response.errors, (list, tuple)) and len(response.errors) > 0:
82
+ for err in response.errors:
83
+ err_t = None
84
+ if isinstance(err, BaseModel): # type: ignore
85
+ err_t = getattr(err, 'error_type', None) # type: ignore
86
+ elif isinstance(err, dict):
87
+ err_t = err.get('error_type', None)
88
+ if isinstance(err_t, str):
89
+ return err_t
90
+ return None
91
+
92
+
79
93
  class ApiSdk:
80
94
  ACCESS_PUBLIC = GLOBAL_PERMISSION__PUBLIC
81
95
  ACCESS_PRIVATE = GLOBAL_PERMISSION__PRIVATE
@@ -292,6 +306,9 @@ class ApiSdk:
292
306
  assert self._initialized_flask_name is not None, 'app must be initialized'
293
307
  assert fn.__module__, 'empty __module__ of function'
294
308
 
309
+ fn_module = fn.__module__
310
+ fn_name = fn.__name__
311
+
295
312
  logger = logging.getLogger(fn.__module__)
296
313
 
297
314
  fn_typing = ApiResourceFnTyping.parse_fn(api_type, enum_methods, fn)
@@ -321,11 +338,13 @@ class ApiSdk:
321
338
  scope_user_id = None
322
339
  scope_token_id = None
323
340
 
341
+ res: Optional[Tuple[BaseResponse, int]] = None
342
+
324
343
  with sentry.configure_scope() as sentry_scope:
325
344
  sentry_scope.set_tag('app_name', self._initialized_flask_name)
326
345
  sentry_scope.set_tag('app_type', 'api')
327
346
  sentry_scope.set_tag('app_uptime', f'{(datetime.now() - APPLICATION_START_DT).seconds // 60}s')
328
- sentry_scope.set_tag('app_api_name', fn.__name__)
347
+ sentry_scope.set_tag('app_api_name', fn_name)
329
348
  sentry_scope.set_tag('app_api_access', access.id)
330
349
 
331
350
  try:
@@ -402,14 +421,18 @@ class ApiSdk:
402
421
  res = api_resource_config.override_flask_response(res)
403
422
 
404
423
  ri = api_resource.request_info
405
- logger.info(json.dumps({
406
- 'user_id': str(scope_user_id),
407
- 'token_id': str(scope_token_id),
424
+ logger.info('AUDIT ' + json.dumps({
425
+ 'user_id': str(scope_user_id) if scope_user_id else None,
426
+ 'token_id': str(scope_token_id) if scope_token_id else None,
408
427
  'method': request.method,
409
428
  'url': request.url,
410
429
  'ipv4': ri.ipv4,
411
430
  'user_agent': ri.user_agent,
412
431
  'duration': time.time() - now,
432
+ 'status_code': res[1] if res is not None else 500,
433
+ 'fn_id': fn_name,
434
+ 'fn_mdl': fn_module,
435
+ 'error_code': _get_error_types(result),
413
436
  }))
414
437
 
415
438
  return res
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ul-api-utils
3
- Version: 7.3.1
3
+ Version: 7.3.3
4
4
  Summary: Python api utils
5
5
  Author: Unic-lab
6
6
  Author-email:
@@ -55,7 +55,7 @@ ul_api_utils/internal_api/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
55
55
  ul_api_utils/internal_api/__tests__/internal_api.py,sha256=X2iopeso6vryszeeA__lcqXQVtz3Nwt3ngH7M4OuN1U,1116
56
56
  ul_api_utils/internal_api/__tests__/internal_api_content_type.py,sha256=mfiYPkzKtfZKFpi4RSnWAoCd6mRijr6sFsa2TF-s5t8,749
57
57
  ul_api_utils/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
- ul_api_utils/modules/api_sdk.py,sha256=-bzW4x8Zpn034v_KamCp4-fiF0Z06SKOYPmIW2o_K8U,20862
58
+ ul_api_utils/modules/api_sdk.py,sha256=3MsDwfsKxzaD7ixMUeJWAI_qSgBU6h7o2QBPS0-d6ZE,21880
59
59
  ul_api_utils/modules/api_sdk_config.py,sha256=ItTShOENf4mhZi9sOLsx7ZugDj5abDpYDeU_BN5sy8E,1761
60
60
  ul_api_utils/modules/api_sdk_jwt.py,sha256=2XRfb0LxHUnldSL67S60v1uyoDpVPNaq4zofUtkeg88,15112
61
61
  ul_api_utils/modules/intermediate_state.py,sha256=7ZZ3Sypbb8LaSfrVhaXaWRDnj8oyy26NUbmFK7vr-y4,1270
@@ -122,9 +122,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
122
122
  ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
123
123
  ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
124
124
  ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=QLZ7DFta01Z7DOK9Z5Iq4uf_CmvDkVReis-GAl_QN48,1447
125
- ul_api_utils-7.3.1.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
126
- ul_api_utils-7.3.1.dist-info/METADATA,sha256=GW_7jqYBIt3y4FiNbORYkgRIs0eUbM793zdpLXLVFrA,14371
127
- ul_api_utils-7.3.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
128
- ul_api_utils-7.3.1.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
129
- ul_api_utils-7.3.1.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
130
- ul_api_utils-7.3.1.dist-info/RECORD,,
125
+ ul_api_utils-7.3.3.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
126
+ ul_api_utils-7.3.3.dist-info/METADATA,sha256=Q7GUC7sI4cCZmTC3spchiEHqauep3ID0C0NFyuPWKiQ,14371
127
+ ul_api_utils-7.3.3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
128
+ ul_api_utils-7.3.3.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
129
+ ul_api_utils-7.3.3.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
130
+ ul_api_utils-7.3.3.dist-info/RECORD,,