File: //opt/imunify360/venv/lib/python3.11/site-packages/im360/__pycache__/aibolit_job.cpython-311.pyc
�
�؞i| � � � d Z ddlZddlZddlZddlZddlZddlZddlmZm Z ddl
mZ ddlm
Z
g d�ZdZ ed� � Z ed � � Z ed
� � ZdZdZd
Zdej d�d�Zedd�d�Zedd�d�Zdd�d�Zefd�Zdedefd�ZdS )zHelper functions to kick off the aibolit scan on file upload.
See {modsec,pureftpd}-on-upload scripts for the example usage.
� N)� ExitStack�suppress)�Path)�NamedTemporaryFile)�RESIDENT_DIR�RESIDENT_IN_DIR_NOTIFY_REL_PATH�RESIDENT_IN_DIR_UPLOAD_REL_PATH�UPLOAD_TIMEOUT�create_notify_job�create_remaining_time_func�create_upload_job�$notify_aibolit_start_it_if_necessaryz./var/run/defence360agent/aibolit-resident.sockz /var/imunify360/aibolit/residentzin/upload-jobszin/notify-jobs� �
g�������?)�
start_time�timerc �. � ��� �� � ��� �fd�}|S )z�Create remaining_time() function.
Start the timer if start_time is None otherwise use given value as
the start time.
remaining_time() raises TimeoutError in *timeout*
seconds after the *start_time* according to the *timer*.
c �B �� � �� � �z
z
} | dk rt �| S )Nr )�TimeoutError)� time_leftr �timeoutr s ����F/opt/imunify360/venv/lib/python3.11/site-packages/im360/aibolit_job.py�remaining_timez2create_remaining_time_func.<locals>.remaining_time8 s- �� ��u�u�w�w��3�4� ���>�>����� � )r r r r s ``` r r r * s= ���� � ����J�� � � � � � � �r )�resident_dir_pathr c � � t | |t z d� t j � � � � z |�� � dS )z-Create PID.upload_job in the resident/in dir.z
{}.upload_job��job_pathr N)�
create_jobr �format�os�getpid��filesr r s r r
r
A sR � ��
�"�
)�*�
�
�
�����
-�
-�.� �� � � � � r c � � t | |t z d� t j � � � � z |�� � dS )z.Create UUID.notify_job in the resident/in dir.z
{}.notify_jobr N)r r r! �uuid�uuid4r$ s r r r L sR � ��
�"�
)�*�
�
�
�����
.�
.�/� �� � � � � r )r c � � d� | D � � } t |t j d| i� � � d� � � � d S )Nc � � g | ];}t j t j |� � � � � d � � ��<S )�ascii)�base64� b64encoder"