MCPcopy Create free account
hub / github.com/dataease/SQLBot / async_wrapper

Function async_wrapper

backend/common/audit/schemas/logger_decorator.py:485–594  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

483 def decorator(func: Callable) -> Callable:
484 @functools.wraps(func)
485 async def async_wrapper(*args, **kwargs):
486 start_time = time.time()
487 status = OperationStatus.SUCCESS
488 error_message = None
489 request = None
490 resource_id = None
491 resource_name = None
492 remark = None
493 oid = -1
494 opt_type_ref = None
495 resource_info_list = None
496 result = None
497
498 try:
499 # Get current request
500 request = RequestContext.get_request()
501 func_signature = inspect.signature(func)
502 bound_args = func_signature.bind(*args, **kwargs)
503 bound_args.apply_defaults()
504 unified_kwargs = dict(bound_args.arguments)
505
506 # Step 1: Attempt to extract the resource ID from the parameters
507 if config.resource_id_expr:
508 resource_id = SystemLogger.extract_from_function_params(
509 config.resource_id_expr,
510 unified_kwargs,
511 kwargs
512 )
513 if config.remark_expr:
514 remark = SystemLogger.extract_from_function_params(
515 config.remark_expr,
516 unified_kwargs,
517 kwargs
518 )
519
520 if config.operation_type == OperationType.LOGIN:
521 input_account_dec = SystemLogger.extract_from_function_params(
522 "form_data.username",
523 args,
524 kwargs
525 )
526 from common.utils.crypto import sqlbot_decrypt
527 input_account = await sqlbot_decrypt(input_account_dec)
528 with Session(engine) as session:
529 userInfo = get_user_by_account(session=session, account=input_account)
530 if userInfo is not None:
531 resource_id = userInfo.id
532 resource_name = userInfo.name
533 oid = userInfo.oid
534 else:
535 resource_id = -1
536 oid = -1
537 resource_name = input_account
538 if config.operation_type == OperationType.DELETE:
539 with Session(engine) as session:
540 resource_info_list = get_resource_name_by_id_and_module(session, resource_id, config.module)
541
542 if config.operation_type == OperationType.CREATE_OR_UPDATE:

Callers

nothing calls this directly

Calls 8

sqlbot_decryptFunction · 0.90
get_user_by_accountFunction · 0.90
extract_resource_idMethod · 0.80
create_log_recordMethod · 0.80
get_requestMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected