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/modules/__pycache__/boto_iot.cpython-310.pyc
o

�N�g�h�@s�dZddlZddlZddlZddlZddlZe�e�Z	z!ddl
Z
ddlZddlm
ZddlmZe�d��ej�dZWneyGdZYnwdd	�Zd
d�Zd>dd
�Zd>dd�Z				d>dd�Z	d?dd�Zd>dd�Zd>dd�Z	d>dd�Zd>dd�Zd>dd�Z	d>dd�Z 					d?d d!�Z!	d>d"d#�Z"	d>d$d%�Z#d>d&d'�Z$d>d(d)�Z%	d>d*d+�Z&d>d,d-�Z'	d>d.d/�Z(	d>d0d1�Z)d>d2d3�Z*					d?d4d5�Z+					d?d6d7�Z,d>d8d9�Z-d>d:d;�Z.	d@d<d=�Z/dS)Aa,
Connection module for Amazon IoT

.. versionadded:: 2016.3.0

:depends:
    - boto
    - boto3

The dependencies listed above can be installed via package or pip.

:configuration: This module accepts explicit Lambda 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 at:

    .. code-block:: text

        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 or
    in the minion's config file:

    .. code-block:: yaml

        iot.keyid: GKTADJGHEIQSXMKKRBJ08H
        iot.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    A region may also be specified in the configuration:

    .. code-block:: yaml

        iot.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, either
    as a passed in dict, or as a string to pull from pillars or minion config:

    .. code-block:: yaml

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

�N)�__version__)�ClientError�boto3TFcCstjjjddd�S)zg
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    z1.2.1z1.4.41)Z	boto3_verZbotocore_ver)�salt�utilsZversionsZcheck_boto_reqs�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/boto_iot.py�__virtual__Psr	cCstrtdtd�dSdS)Nzboto3.assign_funcsZiot)�HAS_BOTO�	__utils__�__name__)�optsrrr�__init__[s�rc	
Cs�zt||||d�}|j|d�}|�d�rddiWSddiWStyO}z&td|�}|j�di��d	�d
krAddiWYd}~Sd|iWYd}~Sd}~ww)
aI
    Given a thing type name, check to see if the given thing type exists

    Returns True if the given thing type exists and returns False if the
    given thing type does not exist.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.thing_type_exists mythingtype

    ��region�key�keyid�profile��
thingTypeNamer�existsTF�boto3.get_error�Error�Code�ResourceNotFoundExceptionN�error)�	_get_conn�describe_thing_type�getrr�response)	rrrrr�conn�res�e�errrrr�thing_type_exists`s


��r$c
Cs�z>t||||d�}|j|d�}|r:|�dd�|�d�}|r5dD]}|�|�}	|	r4t|	tj�r4|	�||<q d|iWSddiWStyp}
z&td|
�}|
j	�d	i��d
�dkrbddiWYd}
~
Sd|iWYd}
~
Sd}
~
ww)
z�
    Given a thing type name describe its properties.

    Returns a dictionary of interesting properties.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.describe_thing_type mythingtype

    rrZResponseMetadataN�thingTypeMetadata)ZcreationDateZdeprecationDateZ
thing_typerrrrr)
rr�popr�
isinstance�datetime�daterrr)rrrrrr r!r%ZdtypeZdvalr"r#rrrrs*


�

��rc
Cs�z1t||||d�}t||d�}|j||d�}	|	r(t�d|	d�d|	dd�WSt�d�d	d
iWStyL}
zd
td|
�d�WYd
}
~
Sd
}
~
ww)a�
    Given a valid config, create a thing type.

    Returns {created: true} if the thing type was created and returns
    {created: False} if the thing type was not created.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.create_thing_type mythingtype \
              thingtype_description_string '["searchable_attr_1", "searchable_attr_2"]'

    r)�thingTypeDescriptionZsearchableAttributes)r�thingTypePropertiesz&The newly created thing type ARN is %s�thingTypeArnT)�createdr,zthing type was not createdr-Fr�r-rN)r�dict�create_thing_type�log�info�warningrr)rr*ZsearchableAttributesListrrrrr r+Z	thingtyper"rrrr0�s(���

��r0c	
Cspzt||||d�}|j||d�|durdnd}d|iWSty7}zdtd|�d�WYd}~Sd}~ww)	a�
    Given a thing type name, deprecate it when undoDeprecate is False
    and undeprecate it when undoDeprecate is True.

    Returns {deprecated: true} if the thing type was deprecated and returns
    {deprecated: false} if the thing type was not deprecated.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.deprecate_thing_type mythingtype

    r)r�
undoDeprecateFT�
deprecatedr)r5rN)r�deprecate_thing_typerr)	rr4rrrrr r5r"rrrr6�s�
��r6c
Cs�zt||||d�}|j|d�ddiWStyF}z'td|�}|j�di��d�dkr7ddiWYd	}~Sd
|d�WYd	}~Sd	}~ww)a8
    Given a thing type name, delete it.

    Returns {deleted: true} if the thing type was deleted and returns
    {deleted: false} if the thing type was not deleted.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.delete_thing_type mythingtype

    rr�deletedTrrrrNF�r7r)r�delete_thing_typerrrr)rrrrrr r"r#rrrr9�s
��r9c
Cs�zt||||d�}|j|d�ddiWStyE}z&td|�}|j�di��d�dkr7dd	iWYd
}~Sd|iWYd
}~Sd
}~ww)a
    Given a policy name, check to see if the given policy exists.

    Returns True if the given policy exists and returns False if the given
    policy does not exist.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.policy_exists mypolicy

    r��
policyNamerTrrrrFNr�rZ
get_policyrrrr)r;rrrrr r"r#rrr�
policy_existss
��r=c	
Cs�z7t||||d�}t|t�stjj�|�}|j||d�}|r.t�	d|d�d|dd�WSt�
d�dd	iWStyR}zd	td
|�d�WYd}~Sd}~ww)
a�
    Given a valid config, create a policy.

    Returns {created: true} if the policy was created and returns
    {created: False} if the policy was not created.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.create_policy my_policy \
              '{"Version":"2015-12-12",\
              "Statement":[{"Effect":"Allow",\
                            "Action":["iot:Publish"],\
                            "Resource":["arn:::::topic/foo/bar"]}]}'

    r)r;�policyDocument�&The newly created policy version is %s�policyVersionIdT)r-Z	versionIdzPolicy was not createdr-Frr.N)
rr'�strrr�json�dumps�
create_policyr1r2r3rr)	r;r>rrrrr �policyr"rrrrD)s$
��

��rDc
C�^zt||||d�}|j|d�ddiWSty.}zdtd|�d�WYd}~Sd}~ww)	a
    Given a policy name, delete it.

    Returns {deleted: true} if the policy was deleted and returns
    {deleted: false} if the policy was not deleted.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.delete_policy mypolicy

    rr:r7TFrr8N)r�
delete_policyrr)r;rrrrr r"rrrrGR�
��rGc	
s�z#t||||d�}|j|d���rd}d�fdd�|D�iWSddiWStyY}z*td|�}|j�d	i��d
�dkrGddiWYd}~Sdtd|�iWYd}~Sd}~ww)
z�
    Given a policy name describe its properties.

    Returns a dictionary of interesting properties.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.describe_policy mypolicy

    rr:)r;�	policyArnr>ZdefaultVersionIdrEc�i|]}|��|��qSr�r��.0�k�rErr�
<dictcomp>|�z#describe_policy.<locals>.<dictcomp>Nrrrrrr<)	r;rrrrr �keysr"r#rrOr�describe_policyis
��rSc

Cs�zt||||d�}|j||d�}dt|�iWStyL}z*td|�}	|j�di��d�dkr:ddiWYd	}~Sd
td|�iWYd	}~Sd	}~ww)aK
    Given a policy name and version ID, check to see if the given policy version exists.

    Returns True if the given policy version exists and returns False if the given
    policy version does not exist.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.policy_version_exists mypolicy versionid

    r)r;ZpolicyversionIdrrrrrFNr)r�get_policy_version�boolrrrr)
r;r@rrrrr rEr"r#rrr�policy_version_exists�s���rVc

Cs�z8t||||d�}t|t�stjj�|�}|j|||d�}|r/t�	d|d�d|dd�WSt�
d�dd	iWStyS}	zd	td
|	�d�WYd}	~	Sd}	~	ww)
a�
    Given a valid config, create a new version of a policy.

    Returns {created: true} if the policy version was created and returns
    {created: False} if the policy version was not created.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.create_policy_version my_policy \
               '{"Statement":[{"Effect":"Allow","Action":["iot:Publish"],"Resource":["arn:::::topic/foo/bar"]}]}'

    r)r;r>�setAsDefaultr?r@T)r-�namezPolicy version was not createdr-Frr.N)
rr'rArrrBrC�create_policy_versionr1r2r3rr)
r;r>rWrrrrr rEr"rrrrY�s(
��

��rYc
C�`zt||||d�}|j||d�ddiWSty/}zdtd|�d�WYd}~Sd}~ww)	a0
    Given a policy name and version, delete it.

    Returns {deleted: true} if the policy version was deleted and returns
    {deleted: false} if the policy version was not deleted.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.delete_policy_version mypolicy version

    r�r;r@r7TFrr8N)r�delete_policy_versionrr�r;r@rrrrr r"rrrr\�s�
��r\c

s�z$t||||d�}|j||d���r d}d�fdd�|D�iWSddiWStyZ}z*td|�}	|j�d	i��d
�dkrHddiWYd}~Sdtd|�iWYd}~Sd}~ww)
z�
    Given a policy name and version describe its properties.

    Returns a dictionary of interesting properties.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.describe_policy_version mypolicy version

    rr[)r;rIr>r@ZisDefaultVersionrEcrJrrKrLrOrrrP
rQz+describe_policy_version.<locals>.<dictcomp>Nrrrrr)rrTrrrr)
r;r@rrrrr rRr"r#rrOr�describe_policy_version�s �
��r^c
Cs�z,t||||d�}g}td|jddd�D]	}|�|d�qt|�s(t�d�d|iWStyF}zdtd	|�iWYd
}~Sd
}~ww)z�
    List all policies

    Returns list of policies

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.list_policies

    Example Return:

    .. code-block:: yaml

        policies:
          - {...}
          - {...}

    r�boto3.paged_call�
nextMarker�marker��marker_flag�
marker_arg�policies�No policies foundrrN)rr�
list_policies�extendrUr1r3r)rrrrr re�retr"rrrrgs
�

��rgc	
Cs�z-t||||d�}g}td|jdd|d�D]	}|�|d�qt|�s)t�d�d|iWStyG}zdtd	|�iWYd
}~Sd
}~ww)a
    List the versions available for the given policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.list_policy_versions mypolicy

    Example Return:

    .. code-block:: yaml

        policyVersions:
          - {...}
          - {...}

    rr_r`ra)rcrdr;ZpolicyVersionszNo versions foundrrN)rr�list_policy_versionsrhrUr1r3r)	r;rrrrr �versrir"rrrrj7�"
�

��rjc
Csdzt||||d�}|j|t|�d�ddiWSty1}zdtd|�d�WYd}~Sd}~ww)	a�
    Sets the specified version of the specified policy as the policy's default
    (operative) version. This action affects all certificates that the policy is
    attached to.

    Returns {changed: true} if the policy version was set
    {changed: False} if the policy version was not set.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.set_default_policy_version mypolicy versionid

    rr[�changedTFr)rmrN)r�set_default_policy_versionrArrr]rrrrn[s�
��rnc	
Cs�z-t||||d�}g}td|j|ddd�D]	}|�|d�qt|�s)t�d�d|iWStyG}zdtd	|�iWYd
}~Sd
}~ww)a
    List the policies attached to the given principal.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.list_principal_policies myprincipal

    Example Return:

    .. code-block:: yaml

        policies:
          - {...}
          - {...}

    rr_r`ra)�	principalrcrdrerfrrN)rr�list_principal_policiesrhrUr1r3r)	rorrrrr rkrir"rrrrpwrlrpc
CrZ)	aP
    Attach the specified policy to the specified principal (certificate or other
    credential.)

    Returns {attached: true} if the policy was attached
    {attached: False} if the policy was not attached.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.attach_principal_policy mypolicy mycognitoID

    r�r;ro�attachedTFr)rrrN)r�attach_principal_policyrr�r;rorrrrr r"rrrrs��
��rsc
CrZ)	aR
    Detach the specified policy from the specified principal (certificate or other
    credential.)

    Returns {detached: true} if the policy was detached
    {detached: False} if the policy was not detached.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.detach_principal_policy mypolicy mycognitoID

    rrq�detachedTFr)rvrN)r�detach_principal_policyrrrtrrrrw�rurwc	
Cs�zt||||d�}|j|d�}ddiWStyI}z*td|�}|j�di��d�dkr7dd	iWYd
}~Sdtd|�iWYd
}~Sd
}~ww)a
    Given a rule name, check to see if the given rule exists.

    Returns True if the given rule exists and returns False if the given
    rule does not exist.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.topic_rule_exists myrule

    r��ruleNamerTrrrZUnauthorizedExceptionFNr)r�get_topic_rulerrrr)	ryrrrrr �ruler"r#rrr�topic_rule_exists�s
��r|c	
C�jzt||||d�}	|	j|||||d�d�ddiWSty4}
zdtd|
�d�WYd	}
~
Sd	}
~
ww)
a�
    Given a valid config, create a topic rule.

    Returns {created: true} if the rule was created and returns
    {created: False} if the rule was not created.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.create_topic_rule my_rule "SELECT * FROM 'some/thing'" \
            '[{"lambda":{"functionArn":"arn:::::something"}},{"sns":{\
            "targetArn":"arn:::::something","roleArn":"arn:::::something"}}]'

    r��sql�description�actions�ruleDisabled�ryZtopicRulePayloadr-TFrr.N)r�create_topic_rulerr�ryrr�r�r�rrrrr r"rrrr�����
	��r�c	
Cr})
a�
    Given a valid config, replace a topic rule with the new values.

    Returns {created: true} if the rule was created and returns
    {created: False} if the rule was not created.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.replace_topic_rule my_rule 'SELECT * FROM some.thing' \
            '[{"lambda":{"functionArn":"arn:::::something"}},{"sns":{\
            "targetArn":"arn:::::something","roleArn":"arn:::::something"}}]'

    rr~r��replacedTFr)r�rN)r�replace_topic_rulerrr�rrrr�r�r�c
CrF)	z�
    Given a rule name, delete it.

    Returns {deleted: true} if the rule was deleted and returns
    {deleted: false} if the rule was not deleted.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.delete_rule myrule

    rrxr7TFrr8N)r�delete_topic_rulerr)ryrrrrr r"rrrr�BrHr�c
s�z+t||||d�}|j|d���r'd�vr'�d�d}d�fdd�|D�iWSddiWStyE}zdtd	|�iWYd}~Sd}~ww)
z�
    Given a topic rule name describe its properties.

    Returns a dictionary of interesting properties.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.describe_topic_rule myrule

    rrxr{)ryrr�r�r�crJrrKrL�r{rrrPmrQz'describe_topic_rule.<locals>.<dictcomp>Nrr)rrzrr)ryrrrrr rRr"rr�r�describe_topic_ruleYs
��r�c
Cs�zBt||||d�}i}|dur||d<|dur||d<g}td|jfddd�|��D]	}	|�|	d�q+t|�s>t�d	�d|iWSty\}
zd
td|
�iWYd}
~
Sd}
~
ww)a
    List all rules (for a given topic, if specified)

    Returns list of rules

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.list_topic_rules

    Example Return:

    .. code-block:: yaml

        rules:
          - {...}
          - {...}

    rN�topicr�r_Z	nextTokenrb�ruleszNo rules foundrr)rr�list_topic_rulesrhrUr1r3r)r�r�rrrrr �kwargsr�rir"rrrr�ts0��
�

��r�)NNNN)FNNNN)NNNNNN)0�__doc__r(�loggingZsalt.utils.compatrZsalt.utils.jsonZsalt.utils.versions�	getLoggerrr1ZbotorZbotocorerZfound_botocore_versionZbotocore.exceptionsr�setLevel�CRITICALr
�ImportErrorr	rr$rr0r6r9r=rDrGrSrVrYr\r^rgrjrnrprsrwr|r�r�r�r�r�rrrr�<module>s�4
�

(
�2
�


�
)

�!
�/
�
�
'
#%
�
%
�
�
$
�0
�
+
�