
    h                         d Z ddlZddlZddlmZmZ ddlZddlmZ ddlm	Z	m
Z
mZmZmZ 	 	 ddede	dee   d	ed
ee   dedee   dee   fdZde
fdZy)z2
Functions to create audit logs for LiteLLM Proxy
    N)datetimetimezone)verbose_proxy_logger)AUDIT_ACTIONSLiteLLM_AuditLogsLitellmTableNamesOptionalUserAPIKeyAuth	object_idactionlitellm_changed_byuser_api_key_dictlitellm_proxy_admin_name
table_namebefore_valueafter_valuec                 V  K   ddl m} t        j                  xs  |d      }	|	duryt	        t        t        t        j                               t        j                  t        j                        |xs |j                  xs ||j                  || |||	             d{    y7 w)a  
    Create an audit log for an internal user.

    Parameters:
    - user_id: str - The id of the user to create the audit log for.
    - action: AUDIT_ACTIONS - The action to create the audit log for.
    - user_row: LiteLLM_UserTable - The user row to create the audit log for.
    - litellm_changed_by: Optional[str] - The user id of the user who is changing the user.
    - user_api_key_dict: UserAPIKeyAuth - The user api key dictionary.
    - litellm_proxy_admin_name: Optional[str] - The name of the proxy admin.
    r   get_secret_boolLITELLM_STORE_AUDIT_LOGSTN)	id
updated_at
changed_bychanged_by_api_keyr   r   r   updated_valuesr   )request_data)litellm.secret_managers.mainr   litellmstore_audit_logscreate_audit_log_for_updater   struuiduuid4r   nowr   utcuser_idapi_key)
r   r   r   r   r   r   r   r   r   r   s
             g/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/proxy/management_helpers/audit_logs.pycreate_object_audit_logr)      s     * =// ?"4 t#
%&4::< ||HLL1) ( ((('088!&%
  s   BB)!B'"B)r   c                   K   ddl m} t        j                  xs  |d      }|duryddlm}m} |dury|t        d      t        j                  d|        t        | j                  t              r$t        j                  | j                        | _        t        | j                  t              r$t        j                  | j                        | _        | j!                  d	      }	 |j"                  j$                  j'                  i |
       d{    y7 # t        $ r"}t        j(                  d|        Y d}~yd}~ww xY ww)z,
    Create an audit log for an object.
    r   r   r   TN)premium_userprisma_clientz&prisma_client is None, no DB connectedzcreating audit log for %s)exclude_none)datazFailed Creating audit log )r   r   r   r   litellm.proxy.proxy_serverr+   r,   	Exceptionr   debug
isinstancer   dictjsondumpsr   
model_dumpdblitellm_auditlogcreateerror)r   r   r   r+   r,   _request_dataes          r(   r    r    C   s:     =// ?"4 t#F4@AA:LI,--t4&*jj1L1L&M#,++T2$(JJ|/H/H$I! +++>ME//66 7 
 	
 	
 	

  E""%?s#CDD
	EsB   C$E'+D DD ED 	E#E ;E EE)NN)__doc__r4   r"   r   r   r   litellm._loggingr   litellm.proxy._typesr   r   r   r	   r
   r!   r)   r         r(   <module>rB      s      '  1   #'!%,,, !, &	,
 'sm, ", 3-, #,^(4E (rA   