File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/engines/__pycache__/sqs_events.cpython-310.pyc
Back
o ;j� � @ s� d Z ddlZddlZddlZddlZzddlZdZW n e y% dZY nw dd� Z e�e�Z ddd�Z dd d�Zddd �ZdS )a� An engine that continuously reads messages from SQS and fires them as events. Note that long polling is utilized to avoid excessive CPU usage. .. versionadded:: 2015.8.0 :depends: boto Configuration ============= This engine can be run on the master or on a minion. Example Config: .. code-block:: yaml sqs.keyid: GKTADJGHEIQSXMKKRBJ08H sqs.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs sqs.message_format: json Explicit sqs credentials are accepted but this engine can also utilize IAM roles assigned to the instance through Instance Profiles. Dynamic credentials are then automatically obtained from AWS API and no further configuration is necessary. More Information available at:: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html If IAM roles are not (or for ``boto`` version < 2.5.1) used you need to specify them either in a pillar or in the config file of the master or minion, as appropriate: To deserialize the message from json: .. code-block:: yaml sqs.message_format: json It's also possible to specify key, keyid and region via a profile: .. code-block:: yaml sqs.keyid: GKTADJGHEIQSXMKKRBJ08H sqs.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs A region may also be specified in the configuration: .. code-block:: yaml sqs.region: us-east-1 If a region is not specified, the default is us-east-1. It's also possible to specify key, keyid and region via a profile: .. code-block:: yaml myprofile: keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 Additionally you can define cross account sqs: .. code-block:: yaml engines: - sqs_events: queue: prod owner_acct_id: 111111111111 � NTFc C s t sdS dS )N)FzKCannot import engine sqs_events because the required boto module is missingT)�HAS_BOTO� r r �K/opt/saltstack/salt/lib/python3.10/site-packages/salt/engines/sqs_events.py�__virtual__Y s r c C s� | r%t | t�rt| }nt | t�r| }|�dd�}|�dd�}|�dd�}|s-t�dd�}|s5t�dd�}|s=t�dd�}ztjj|||d �}W |S tjj yZ t �d � Y dS w )z' Get a boto connection to SQS. �keyN�keyid�regionz sqs.regionz us-east-1zsqs.keyz sqs.keyid)Zaws_access_key_idZaws_secret_access_keyz_No authentication credentials found when attempting to make sqs_event engine connection to AWS.)� isinstance�str�__opts__�dict�get�boto�sqsZconnect_to_region� exceptionZNoAuthHandlerFound�log�error)�profiler r r Z_profile�connr r r � _get_sqs_conng s2 � ���r �salt/engine/sqsc C s� | st �dd�dd� t|�|fD ��� t�d� d S | jdd�}|D ]$}|dkr9||d tjj � |�� �id � n ||d |�� id � |�� q#d S )Nz4failure connecting to queue: %s, waiting 10 seconds.�:c S s g | ]}|r|�qS r r )�.0Z_fr r r � <listcomp>� s z"_process_queue.<locals>.<listcomp>� � )Zwait_time_seconds�json�message)�tag�data) r �warning�joinr �time�sleepZget_messages�salt�utilsr �loads�get_body�delete)�qZq_name�fire_masterr � owner_acct_id�message_formatZmsgs�msgr r r �_process_queue� s �� �r. c C s� t �d�dkrtjjjt t d dd�j}ntd }t �dd�}t|�}d} |s7|j | |d �}|� tjj j� t|| ||||d� q&)z5 Listen to sqs and fire message on event bus Z__roleZmasterZsock_dirF)�listenz event.sendzsqs.message_formatNT)r+ )r r+ r, )r r r$ r% �eventZget_master_eventZ fire_eventZ__salt__r Z get_queueZset_message_classr r r Z RawMessager. )�queuer r r+ r* r, r r) r r r �start� s. ����r2 )NNN)r NN)Nr N)�__doc__�loggingr"