HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/boto3_sns.cpython-310.pyc
o

�N�g<2�@sddZddlZddlZddlZddlZe�e�Zdd�Z							ddd�Z
	d
dd	�Zd
d�ZdS)a
Manage SNS Topics
=================

Create and destroy SNS topics. Be aware that this interacts with Amazon's
services, and so may incur charges.

This module uses ``boto``, which can be installed via package, or pip.

This module accepts explicit AWS credentials but 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 `here
<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.

If IAM roles are not used you need to specify them either in a pillar file or
in the minion's config file:

.. code-block:: yaml

    sns.keyid: GKTADJGHEIQSXMKKRBJ08H
    sns.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile, either
passed in as a dict, or as a string to pull from pillars or minion config:

.. code-block:: yaml

    myprofile:
        keyid: GKTADJGHEIQSXMKKRBJ08H
        key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
        region: us-east-1

.. code-block:: yaml

    mytopic:
        boto3_sns.topic_present:
            - region: us-east-1
            - keyid: GKTADJGHEIQSXMKKRBJ08H
            - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

Using a profile from pillars
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: yaml

    mytopic:
        boto3_sns.topic_present:
            - region: us-east-1
            - profile: mysnsprofile

Passing in a profile
^^^^^^^^^^^^^^^^^^^^

.. code-block:: yaml

    mytopic:
        boto3_sns.topic_present:
            - region: us-east-1
            - profile:
                keyid: GKTADJGHEIQSXMKKRBJ08H
                key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
�NcCsdtvrdSdS)z)
    Only load if boto is available.
    zboto3_sns.topic_existsZ	boto3_sns)Fz$boto3_sns module could not be loaded)�__salt__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/boto3_sns.py�__virtual__Jsrc
CsB|ddid�}d}td|||||�}	|	r"d|�d�|d<|	d	}
n>td
r4d|�d�|d<d|d
<|Std|||||d�}
|
rLd�||
�|d<d}nd|��|d<t�|d�d|d
<|S|rd|ni}td|
||||d�}dD]j}
|�|
�}|�|
�}|dur�qst||�r�qstd
r�|dd�|
|
�7<d|d
<qst|t�r�|nt	j
j�|�}td|
|
|||||d�r�|dd�|
||
�7<d}qs|dd�|
|
�7<d|d
<|S|r�|ng}g}|	�dg�}dd�|D�}g}g}|D]5}|d}t
�d|�}|du�r|�d|��dd�|d<|t�|�g7}||v�r.||d<||g7}q�|D] }|d |dd!�}||v�rP|d"�d#��rP||d"g7}�q1|D]b}|d }|d}td
�rxd$�|||
�}|d|7<d|d
<�qTtd%|
||||||d�}|�r�d&|�d|�d'|
�d(�}|d|7<d}�qTd)�|||
�}|d|7<d|d
<|S|D]N}td
�r�d*�||
�}|d|7<d|d
<�q�td+|||||d�}|�r�|dd,�||
�7<d}�q�d-�||
�}|d|7<d|d
<|S|�r|	|d.d/<td|||||�|d.d0<|S)1ak
    Ensure the SNS topic exists.

    name
        Name of the SNS topic.

    subscriptions
        List of SNS subscriptions.

        Each subscription is a dictionary with a protocol and endpoint key:

        .. code-block:: yaml

            subscriptions:
            - Protocol: https
              Endpoint: https://www.example.com/sns-endpoint
            - Protocol: sqs
              Endpoint: arn:aws:sqs:us-west-2:123456789012:MyQueue

    attributes
        Dictionary of attributes to set on the SNS topic
        Valid attribute keys are:

          - Policy:  the JSON serialization of the topic's access control policy
          - DisplayName:  the human-readable name used in the "From" field for notifications
                to email and email-json endpoints
          - DeliveryPolicy:  the JSON serialization of the topic's delivery policy

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string)
        that contains a dict with region, key and keyid.
    T���name�result�comment�changesF�boto3_sns.describe_topic�AWS SNS topic z	 present.r
�TopicArn�testz would be created.Nr	zboto3_sns.create_topic��region�key�keyid�profilez%AWS SNS topic {} created with ARN {}.zFailed to create AWS SNS topic zboto3_sns.get_topic_attributes)ZDisplayName�PolicyZDeliveryPolicyz,  Attribute {} would be updated on topic {}.zboto3_sns.set_topic_attributesz%  Attribute {} set to {} on topic {}.z"  Failed to update {} on topic {}.�
SubscriptionscSsg|]}|d|dd��qS)�Protocol�Endpoint�rrr��.0�srrr�
<listcomp>�s�z!topic_present.<locals>.<listcomp>rz$https://(?P<user>\w+):(?P<pass>\w+)@�:�passz:****rr�SubscriptionArnzarn:aws:sns:z- Subscription {}:{} would be set on topic {}.zboto3_sns.subscribez Subscription z set on topic �.z. Failed to set subscription {}:{} on topic {}.z1  Subscription {} would be removed from topic {}.�boto3_sns.unsubscribez(  Subscription {} removed from topic {}.z1  Failed to remove subscription {} from topic {}.r�old�new)r�__opts__�format�log�error�get�_json_objs_equal�
isinstance�str�salt�utils�json�dumps�re�search�replace�	groupdict�copy�deepcopy�
startswith)rZ
subscriptionsZ
attributesrrrr�ret�something_changed�currentrZ
want_attrsZ
current_attrs�attrZcurr_valZwant_valZ	want_subsZobfuscated_subsZcurrent_subsZcurrent_slimZ	subscribe�unsubscribe�subZendpoint�matchesZminimalZprotZendp�msgZsubbedZunsubbedrrr�
topic_presentSs2

��
�


���	���
�

���
���
�
���
�r@FcCs�|ddid�}d}td|||||�}|sd|�d�|d<n�|d	}	td
rEd|	�d�|d<|r?|dd�t|d
��7<d|d<|S|r�|d
D]=}
|
ddkrbt�d|
d|
d|
d	�qKtd|
d||||d�ryt�d|
|	�d}qKd�|
|	�|d<d|d<|Std|	||||d�s�d|	��|d<t�|d�d|d<nd|	�d�|d<|r�|dd�dd�|d
D��7<d}|r�||dd <td|||||�|dd!<|S)"a�
    Ensure the named sns topic is deleted.

    name
        Name of the SNS topic.

    unsubscribe
        If True, unsubscribe all subcriptions to the SNS topic before
        deleting the SNS topic

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string)
        that contains a dict with region, key and keyid.
    TrrFrr
z absent.r
rrz would be removed.z&  {} subscription(s) would be removed.rNr	r ZPendingConfirmationz;Ignoring PendingConfirmation subscription %s %s on topic %srrr"rz(Deleted subscription %s for SNS topic %sz1Failed to delete subscription {} for SNS topic {}zboto3_sns.delete_topiczFailed to delete SNS topic z	 deleted.z  cSsg|]}d|�d��qS)z
Subscription z deletedrrrrrrrsz topic_absent.<locals>.<listcomp>rr#r$)	rr%r&�lenr'�warning�debugr(�join)rr<rrrrr8r9r:rr=rrr�topic_absent"sr
�����
�
�
�rEcCsPtdt|t�rtjj�|�n|�}tdt|t�r!tjj�|�n|�}||kS)Nz
boto3.ordered)Z	__utils__r+r,r-r.r/�loads)�left�rightrrrr*~s��r*)NNNNNN)FNNNN)
�__doc__r5�loggingr1Zsalt.utils.jsonr-�	getLogger�__name__r'rr@rEr*rrrr�<module>s$@

�Q
�\