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

�N�g�d�@s�dZddlZddlZddlZddlZddlZddlZe�e	�Z
dd�Z				ddd�Z	ddd�Z
	dd	d
�Zddd�Z	dd
d�Z	ddd�Z						ddd�Zddd�ZdS)ar
Manage IoT Objects
==================

.. versionadded:: 2016.3.0

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

:depends:
    - boto
    - boto3

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

This module accepts explicit vpc 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

    vpc.keyid: GKTADJGHEIQSXMKKRBJ08H
    vpc.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

    Ensure policy exists:
        boto_iot.policy_present:
            - policyName: mypolicy
            - policyDocument:
                Version: "2012-10-17"
                Statement:
                  Action:
                    - iot:Publish
                  Resource:
                    - "*"
                  Effect: "Allow"
            - region: us-east-1
            - keyid: GKTADJGHEIQSXMKKRBJ08H
            - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    Ensure topic rule exists:
        boto_iot.topic_rule_present:
            - ruleName: myrule
            - sql: "SELECT * FROM 'iot/test'"
            - description: 'test rule'
            - ruleDisabled: false
            - actions:
              - lambda:
                  functionArn: "arn:aws:us-east-1:1234:function/functionname"
            - region: us-east-1
            - keyid: GKTADJGHEIQSXMKKRBJ08H
            - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

�NcCsdtvrdSdS)z)
    Only load if boto is available.
    �boto_iot.policy_existsZboto_iot)Fz#boto_iot module could not be loaded)�__salt__�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/boto_iot.py�__virtual__Tsrc	Cs"|ddid�}td|||||d�}	d|	vr'd|d<d	�|	dd
�|d<|S|	�d�r9d|d<d
�|�|d<|StdrKd|�d�|d<d|d<|Std|||||||d�}	|	�d�snd|d<d	�|	dd
�|d<|Std|||||d�}
ddi|dd<|
|dd<d|�d�|d<|S)a[
    Ensure thing type exists.

    .. versionadded:: 2016.11.0

    name
        The name of the state definition

    thingTypeName
        Name of the thing type

    thingTypeDescription
        Description of the thing type

    searchableAttributesList
        List of string attributes that are searchable for
        the thing type

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used

    profile
        A dict with region, key, keyid, or a pillar key (string) that
        contains a dict with region, key, and keyid

    T���name�result�comment�changeszboto_iot.thing_type_exists��
thingTypeName�region�key�keyid�profile�errorFr
z Failed to create thing type: {}.�messager�existsz,Thing type with given name {} already exists�testzThing type � is set to be created.Nzboto_iot.create_thing_type)r�thingTypeDescription�searchableAttributesListrrrr�created�boto_iot.describe_thing_type�
thing_typer�old�new�Thing Type �	 created.)r�format�get�__opts__)r	rrrrrrr�ret�r�	_describerrr�thing_type_present]sd*�
�
��


��r'cCs�|ddid�}td|||||d�}d|vr'd|d<d	�|dd
�|d<|S|r7|ds7d
|�d�|d<|S|d}|�d�}	|	�dd�}
tdr_|
rOd}nd}d�||�|d<d|d<|Sd}|
dur�td|d||||d�}
d|
vr�d|d<d�|
dd
�|d<|Sn1|	�d�}|r�|�d�}|dkr�|d|�}tj�|d�}tj��|}|jdkr�d}nd|j}|r�t	�
d|�t�|�td |||||d�}|d!s�d|d<d	�|dd
�|d<|S||d"d#<ddi|d"d$<d
|�d%�|d<|S)&a�
    Ensure thing type with passed properties is absent.

    .. versionadded:: 2016.11.0

    name
        The name of the state definition.

    thingTypeName
        Name of the thing type.

    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.

    Trrrr
rFr
z Failed to delete thing type: {}.rrrr� does not exist.ZthingTypeMetadataZ
deprecatedrZremovedzdeprecated and removedzThing Type {} is set to be {}.Ni,zboto_iot.deprecate_thing_type)rZ
undoDeprecaterrrrz#Failed to deprecate thing type: {}.ZdeprecationDate�+���z%Y-%m-%d %H:%M:%S.%frzbwait for %s seconds per AWS (5 minutes after deprecation time) before we can delete iot thing typezboto_iot.delete_thing_type�deletedrrr�	 deleted.)
rr!r"r#�find�datetime�strptime�utcnow�seconds�log�warning�time�sleep)r	rrrrrr$r&Z_existing_thing_typeZ_thing_type_metadataZ_deprecatedZ_change_descZ_delete_wait_timerZ
_deprecateZ_deprecation_date_strZ	_tz_indexZ_deprecation_dateZ_elapsed_time_deltar%rrr�thing_type_absent�s��
�
��
��

�

�
�
�r6c	Cs�|ddid�}td|||||d�}d|vr'd|d<d	�|dd
�|d<|S|�d�s�td
r>d|�d�|d<d|d<|Std||||||d�}|�d�s`d|d<d	�|dd
�|d<|Std|||||d�}	ddi|dd<|	|dd<d|�d�|d<|Stj�|dd|�d�g�|d<i|d<td|||||d�d}	t|	dt�r�t	j
j�|	d�}
n|	d}
t|t�r�t	j
j�|�}t	j
j
�|
|�}t|��rEtd
r�d|�d�}||d<d|d<|Stj�|ddg�|d<t	j
j�|�}td||d||||d �}|�d��s!d|d<d!�|dd
�|d<i|d<|Std"||	d#||||d$�||d�di�d<|	d|d�di�d<|S)%aR
    Ensure policy exists.

    name
        The name of the state definition

    policyName
        Name of the policy.

    policyDocument
        The JSON document that describes the policy. The length of the
        policyDocument must be a minimum length of 1, with a maximum length of
        2048, excluding whitespace.

    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.
    Trrr)�
policyNamerrrrrFr
zFailed to create policy: {}.rrrr�Policy rNzboto_iot.create_policy)r7�policyDocumentrrrrrzboto_iot.describe_policy�rrrr�policyrrrr � is present.r9� set to be modified.zPolicy to be modifiedzboto_iot.create_policy_version)r7r9ZsetAsDefaultrrrrzFailed to update policy: {}.�boto_iot.delete_policy_versionZdefaultVersionId)r7�policyVersionIdrrrr)rr!r"r#�os�linesep�join�
isinstance�str�salt�utils�json�loads�dataZ
compare_dicts�bool�dumps�
setdefault)r	r7r9rrrrr$r%r&ZdescribeDict�msgrrr�policy_presentFs�
�
�

�
��
��

�	
��	�rNc
	Cs�|ddid�}td|||||d�}d|vr'd|d<d	�|dd
�|d<|S|r7|ds7d
|�d�|d<|StdrId
|�d�|d<d|d<|Std|||||d�}|r�|�dg�D]/}	|	�dd�req\td||	�d�||||d�}|ds�d|d<d	�|dd
�|d<|Sq\td|||||d�}|ds�d|d<d	�|dd
�|d<|Sd|i|dd<ddi|dd<d
|�d�|d<|S)a�
    Ensure policy with passed properties is absent.

    name
        The name of the state definition.

    policyName
        Name of the 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.
    Trrrr:rFr
zFailed to delete policy: {}.rrrr8r(r� is set to be removed.Nzboto_iot.list_policy_versionsZpolicyVersionsZisDefaultVersionr>Z	versionId)r?rrrrr+zboto_iot.delete_policyr;rrrr,)rr!r#r")
r	r7rrrrr$r%Zversions�versionrrr�
policy_absent�s`
�
��
��
�rQcCsL|ddid�}td|||||d�}d|vr'd|d<d	�|dd
�|d<|Sd}	|�dg�D]
}
|
�d
�|kr<d}	nq/|	s�tdrQd�||�|d<d|d<|Std||||||d�}|�d�ssd|d<d	�|dd
�|d<|Sddi|dd<ddi|dd<d|�d|�d�|d<|Stj�|dd|�d�g�|d<i|d<|S)a�
    Ensure policy is attached to the given principal.

    name
        The name of the state definition

    policyName
        Name of the policy.

    principal
        The principal which can be a certificate ARN or a Cognito ID.

    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.
    Trr� boto_iot.list_principal_policies��	principalrrrrrFr
zFailed to attach policy: {}.rr�policiesr7rz&Policy {} is set to be attached to {}.Nz boto_iot.attach_principal_policy�r7rTrrrr�attachedrrrr8z
 attached to �.z
 is attached.�rr!r"r#r@rArB�r	r7rTrrrrr$r%rWr;rrr�policy_attachedsX
����

��r[cCsL|ddid�}td|||||d�}d|vr'd|d<d	�|dd
�|d<|Sd}	|�dg�D]
}
|
�d
�|kr<d}	nq/|	r�tdrQd�||�|d<d|d<|Std||||||d�}|�d�ssd|d<d�|dd
�|d<|Sddi|dd<ddi|dd<d|�d|�d�|d<|Stj�|dd|�d�g�|d<i|d<|S)a�
    Ensure policy is attached to the given principal.

    name
        The name of the state definition.

    policyName
        Name of the policy.

    principal
        The principal which can be a certificate ARN or a Cognito ID.

    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.
    TrrrRrSrFr
zFailed to detached policy: {}.rrrUr7rz(Policy {} is set to be detached from {}.Nz boto_iot.detach_principal_policyrVZdetachedzFailed to detach policy: {}.rWrrrr8z detached from rXz
 is detached.rYrZrrr�policy_detachedisX
����

��r\rFc
Cs�|ddid�}
td|||||	d�}d|vr'd|
d<d	�|dd
�|
d<|
S|�d�s�td
r>d|�d�|
d<d|
d<|
Std|||||||||	d�	}|�d�scd|
d<d	�|dd
�|
d<|
Std|||||	d�}ddi|
dd<||
dd<d|�d�|
d<|
Stj�|
dd|�d�g�|
d<i|
d<td|||||	d�d}t|t�r�t	j
j�|�}d}
|d|k|d|k}t
|�r�d}
||
d�di�d<|d|
d�di�d<dD]'}||t�|k�rd}
t�||
d�di�|<|||
d�di�|<q�|
�rWtd
�r#d|�d�}i|
d<||
d<d|
d<|
Stj�|
ddg�|
d<td |||||||||	d�	}|�d!��sWd|
d<d"�|dd
�|
d<i|
d<|
S)#ar
    Ensure topic rule exists.

    name
        The name of the state definition

    ruleName
        Name of the rule.

    sql
        The SQL statement used to query the topic.

    actions
        The actions associated with the rule.

    description
        The description of the rule.

    ruleDisable
        Specifies whether the rule is disabled.

    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.
    Trr�boto_iot.topic_rule_exists)�ruleNamerrrrrFr
zFailed to create rule: {}.rrrr�Rule rNzboto_iot.create_topic_rule)	r^�sql�actions�description�ruleDisabledrrrrrzboto_iot.describe_topic_ruler:�rulerrrr r<ra)r`rbrcr=zRule to be modifiedzboto_iot.replace_topic_ruleZreplacedzFailed to update rule: {}.)rr!r"r#r@rArBrCrDrErFrGrHrJrL�locals)r	r^r`rarbrcrrrrr$r%r&Zneed_update�varrMrrr�topic_rule_present�s�.
�
�

� 
��
�
�rgcCs|ddid�}td|||||d�}d|vr'd|d<d	�|dd
�|d<|S|r7|ds7d
|�d�|d<|StdrId
|�d�|d<d|d<|Std|||||d�}|dsid|d<d	�|dd
�|d<|Sd|i|dd<ddi|dd<d
|�d�|d<|S)a�
    Ensure topic rule with passed properties is absent.

    name
        The name of the state definition.

    ruleName
        Name of the 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.
    Trrr]r:rFr
zFailed to delete rule: {}.rrrr_r(rrONzboto_iot.delete_topic_ruler+rdrrrr,)rr!r#)r	r^rrrrr$r%rrr�topic_rule_absent>s4
�
�rh)NNNN)rFNNNN)�__doc__r.�loggingr@r4Zsalt.utils.datarEZsalt.utils.json�	getLogger�__name__r2rr'r6rNrQr[r\rgrhrrrr�<module>sDH

�f
�
�
U
�O
�T
�