o
    `oi
                     @   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 )ZHTTP_ N)
startswithsub).0headervalueregex \/var/www/html/kuke-dev/django-kuke/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 )NZHTTP_X_FORWARDED_FOR,r   ZREMOTE_ADDRr   )r   getsplit)r   Z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_databaseZ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   r+   )typer   strSENSITIVE_KEYSr   r
   formatupperlistr   r'   )dataZmask_api_parametersZsensitive_keykeyr   r   r   r   r'   2   s$   	r'   )N)F)r   Zdjango.confr   r.   r!   r,   r   r1   tupleextendr   r   r#   r$   r'   r   r   r   r   <module>   s    


