o
     e
                     @   st   d dl Z d dlmZ g dZeedr"eejeefv r"e	ej dddZ
dd Zd	d
 Zdd ZdddZdS )    N)settings)passwordtokenaccessrefreshDRF_API_LOGGER_EXCLUDE_KEYSc                    s&   t d t fdd| j D S )zt
        Function:       get_headers(self, request)
        Description:    To get all the headers from request
    z^HTTP_c                 3   s.    | ]\}}| d r d||fV  qdS )HTTP_ N)
startswithsub).0headervalueregex G/var/www/html/venv/lib/python3.10/site-packages/drf_api_logger/utils.py	<genexpr>   s   
 zget_headers.<locals>.<genexpr>)recompiledictMETAitems)requestr   r   r   get_headers
   s   
r   c                 C   sD   z| j d}|r|dd }|W S | j d}|W S    Y dS )NHTTP_X_FORWARDED_FOR,r   REMOTE_ADDRr	   )r   getsplit)r   x_forwarded_foripr   r   r   get_client_ip   s   r"   c                  C   s0   d} t tdr
tj} d}t tdrtj}| p|S )NFDRF_API_LOGGER_DATABASEDRF_API_LOGGER_SIGNAL)hasattrr   r#   r$   )drf_api_logger_databasedrf_api_logger_signalr   r   r   is_api_logger_enabled    s   

r(   c                  C   s   d} t tdr
tj} | S )NFr#   )r%   r   r#   )r&   r   r   r   database_log_enabled+   s   
r)   Fc                 C   s   t | tur1|r"t | tu r"tD ]}td|d| | } qt | tu r/dd | D } | S | 	 D ]+\}}|tv rAd| |< t |tu rOt
| | | |< t |tu r`dd | | D | |< q5| S )a  
    Hides sensitive keys specified in sensitive_keys settings.
    Loops recursively over nested dictionaries.

    When the mask_api_parameters parameter is set, the function will 
    instead iterate over sensitive_keys and remove them from an api 
    URL string.
    z({}=)(.*?)($|&)z\g<1>***FILTERED***\g<3>c                 S      g | ]}t |qS r   mask_sensitive_datar   itemr   r   r   
<listcomp>B       z'mask_sensitive_data.<locals>.<listcomp>z***FILTERED***c                 S   r*   r   r+   r-   r   r   r   r/   L   r0   )typer   strSENSITIVE_KEYSr   r   formatupperlistr   r,   )datamask_api_parameterssensitive_keykeyr   r   r   r   r,   2   s$   	r,   )N)F)r   django.confr   r3   r%   r1   r   r6   tupleextendr   r"   r(   r)   r,   r   r   r   r   <module>   s    


