
    iq                    p    d Z ddlmZ ddlZddlmZ ddlmZ  ej        e	          Z
 G d d          ZdS )u  
Nom du script : audit_log_service.py
Chemin : /gitlab-bridge/app/services/audit_log_service.py
Description : Persistance des journaux d'audit en base SQL avec gestion défensive des erreurs.
Options éventuelles : Aucune.
Exemples d'utilisation : `write_log(...)` après chaque action.
Prérequis : Python 3.11+, SQLAlchemy 2.x.
Auteur : Sylvain SCATTOLINI
Date de création / modification : 2026-03-25
Version : 1.1
    )annotationsN)Session)AuditLogc                  *    e Zd ZdZddZdddddZdS )AuditLogServiceuU   Journalise les actions tout en évitant de casser le flux métier en cas d'échec DB.dbr   returnNonec                    || _         d S )N)r   )selfr   s     =/var/www/html/gitlab-bridge/app/services/audit_log_service.py__init__zAuditLogService.__init__   s        N)response_payloaderror_messageusernamestremailactionproject_pathstatusrequest_payloaddictr   dict | Noner   
str | Nonec          
     $   	 t          ||||||||          }	| j                            |	           | j                                         d S # t          $ r7 | j                                         t                              d           Y d S w xY w)N)r   r   r   r   r   r   r   r   z+Impossible de journaliser l'action en base.)r   r   addcommit	Exceptionrollbacklogger	exception)
r   r   r   r   r   r   r   r   r   	audit_logs
             r   	write_logzAuditLogService.write_log   s    	M !) /!1+	 	 	I GKK	"""GNN 	M 	M 	MGKLLLLLL	Ms   A
A =BB)r   r   r	   r
   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r
   )__name__
__module____qualname____doc__r   r$    r   r   r   r      s\        __    )-$(M M M M M M M Mr   r   )r(   
__future__r   loggingsqlalchemy.ormr   app.db.models.audit_logr   	getLoggerr%   r!   r   r)   r   r   <module>r/      s   
 
 # " " " " "  " " " " " " , , , , , ,		8	$	$!M !M !M !M !M !M !M !M !M !Mr   