%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyc

�
���^c@@s'dZddlmZmZmZddlZddlZddlZddl	Zddl
Zeje�Z
ddlmZy[ddlZddlZddlmZddlmZejd�jej�eZWnek
r�eZnXd�Zd	�Zddddd
�Z ddddd�Z!ddddd�Z"eddddd
�Z#ddddd�Z$ddddd�Z%ddddd�Z&ddddd�Z'ddddd�Z(ddddd�Z)eddddd�Z*ddddd�Z+ddddd�Z,ddddd�Z-ddddd�Z.ddddd�Z/ddddd�Z0ddddd�Z1ddddd�Z2ddddd�Z3eddddd�Z4eddddd�Z5ddddd �Z6ddddd!�Z7ddddddd"�Z8dS(#u,
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

i(tabsolute_importtprint_functiontunicode_literalsN(tstring_types(tClientError(t__version__uboto3cC@stjjjdddd�S(ug
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    t	boto3_veru1.2.1tbotocore_veru1.4.41(tsalttutilstversionstcheck_boto_reqs(((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyt__virtual__QscC@s1tjjjt�tr-tdtd�ndS(Nuboto3.assign_funcsuiot(RR	tcompattpack_dundert__name__tHAS_BOTOt	__utils__(topts((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyt__init___sc		C@s�y\td|d|d|d|�}|jd|�}|jd�rPitd6Sitd6SWnZtk
r�}td|�}|jjd	i�jd
�dkr�itd6Si|d6SXd
S(uI
    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

    tregiontkeytkeyidtprofilet
thingTypeNameu
thingTypeNameuexistsuboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(t	_get_conntdescribe_thing_typetgettTruetFalseRRtresponse(	RRRRRtconntresteterr((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pytthing_type_existses!$c	C@s*y�td|d|d|d|�}|jd|�}|r�|jdd�|jd�}|r�xNdD]C}|j|�}	|	rht|	tj�rhd
j|	�||<qhqhWni|d6Sidd6SWnZt	k
r%}
t
d|
�}|
jjd
i�jd�dkridd6Si|d6SXdS(u�
    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

    RRRRRuResponseMetadatauthingTypeMetadataucreationDateudeprecationDateu{0}u
thing_typeuboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(ucreationDateudeprecationDate(RRtpoptNoneRt
isinstancetdatetimetdatetformatRRR(RRRRRRR tthingTypeMetadatatdtypetdvalR!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR�s$!
$c	C@s�y�td|d|d|d|�}td|d|�}|jd|d|�}	|	r�tjd	|	d
�itd6|	d
d
6Stjd�itd6SWn,tk
r�}
itd6t	d
|
�d6SXdS(u�
    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"]'

    RRRRtthingTypeDescriptiontsearchableAttributesRtthingTypePropertiesu&The newly created thing type ARN is %suthingTypeArnucreateduthing type was not createduboto3.get_erroruerrorN(
Rtdicttcreate_thing_typetlogtinfoRtwarningRRR(RR-tsearchableAttributesListRRRRRR/t	thingtypeR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR1�s!			
c		C@s�y^td|d|d|d|�}|jd|d|�|tkrLtnt}i|d6SWn,tk
r�}itd6td|�d	6SXd
S(u�
    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

    RRRRRt
undoDeprecateu
deprecateduboto3.get_erroruerrorN(Rtdeprecate_thing_typeRRRR(	RR7RRRRRt
deprecatedR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR8�s!	c	C@s�y@td|d|d|d|�}|jd|�itd6SWnatk
r�}td|�}|jjdi�jd	�d
kr�itd6Sitd6|d6SXdS(
u8
    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

    RRRRRudeleteduboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(Rtdelete_thing_typeRRRRRR(RRRRRRR!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR:�s!$c	C@s�y@td|d|d|d|�}|jd|�itd6SWnZtk
r�}td|�}|jjdi�jd	�d
kr�itd6Si|d6SXdS(
u
    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

    RRRRt
policyNameuexistsuboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(Rt
get_policyRRRRRR(R;RRRRRR!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyt
policy_existss!$c		C@s�y�td|d|d|d|�}t|t�sKtjjj|�}n|jd|d|�}|r�tj	d|d�it
d	6|dd
6Stjd�itd	6SWn,t
k
r�}itd	6td|�d
6SXdS(u�
    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"]}]}'

    RRRRR;tpolicyDocumentu&The newly created policy version is %supolicyVersionIducreatedu	versionIduPolicy was not createduboto3.get_erroruerrorN(RR&RRR	tjsontdumpst
create_policyR2R3RR4RRR(	R;R>RRRRRtpolicyR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRA+s!	
c	C@ssy@td|d|d|d|�}|jd|�itd6SWn,tk
rn}itd6td|�d6SXd	S(
u
    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

    RRRRR;udeleteduboto3.get_erroruerrorN(Rt
delete_policyRRRR(R;RRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRCPs!c	C@s�y�td|d|d|d|�}|jd|�}|rud}itg|D]}||j|�f^qO�d
6Sidd
6SWndtk
r�}	td|	�}
|	jjdi�jd
�dkr�idd
6Sitd|	�d6SXdS(u�
    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

    RRRRR;u
policyNameu	policyArnupolicyDocumentudefaultVersionIdupolicyuboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(u
policyNameu	policyArnupolicyDocumentudefaultVersionId(RR<R0RR%RRR(R;RRRRRRBtkeystkR!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pytdescribe_policyhs!3$c
	C@s�yNtd|d|d|d|�}|jd|d|�}it|�d6SWndtk
r�}td|�}	|jjd	i�jd
�dkr�itd6Sitd|�d6SXd
S(uK
    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

    RRRRR;tpolicyversionIduexistsuboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(Rtget_policy_versiontboolRRRRR(
R;tpolicyVersionIdRRRRRRBR!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pytpolicy_version_exists�s!	$c
	C@s�y�td|d|d|d|�}t|t�sKtjjj|�}n|jd|d|d|�}|r�tj	d|d	�it
d
6|d	d6Stjd�itd
6SWn,t
k
r�}	itd
6td
|	�d6SXdS(u�
    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"]}]}'

    RRRRR;R>tsetAsDefaultu&The newly created policy version is %supolicyVersionIducreatedunameuPolicy version was not createduboto3.get_erroruerrorN(RR&RRR	R?R@tcreate_policy_versionR2R3RR4RRR(
R;R>RLRRRRRRBR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRM�s!	
c	C@syyFtd|d|d|d|�}|jd|d|�itd6SWn,tk
rt}itd6td|�d	6SXd
S(u0
    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

    RRRRR;RJudeleteduboto3.get_erroruerrorN(Rtdelete_policy_versionRRRR(R;RJRRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRN�s!c	C@s�y�td|d|d|d|�}|jd|d|�}|r{d}itg|D]}	|	|j|	�f^qU�d6Sidd6SWndtk
r�}
td
|
�}|
jjdi�jd�dkr�idd6Sitd
|
�d6SXdS(u�
    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

    RRRRR;RJu
policyNameu	policyArnupolicyDocumentupolicyVersionIduisDefaultVersionupolicyuboto3.get_erroruErroruCodeuResourceNotFoundExceptionuerrorN(u
policyNameu	policyArnupolicyDocumentupolicyVersionIduisDefaultVersion(RRHR0RR%RRR(R;RJRRRRRRBRDRER!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pytdescribe_policy_version�s!	3$c	C@s�y�td|d|d|d|�}g}x8td|jdddd	�D]}|j|d
�qJWt|�s�tjd�ni|d
6SWn%tk
r�}itd|�d
6SXdS(u�
    List all policies

    Returns list of policies

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iot.list_policies

    Example Return:

    .. code-block:: yaml

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

    RRRRuboto3.paged_calltmarker_flagu
nextMarkert
marker_argumarkerupoliciesuNo policies founduboto3.get_erroruerrorN(RRt
list_policiestextendRIR2R4R(RRRRRtpoliciestretR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRR�s!
c		C@s�y�td|d|d|d|�}g}x>td|jdddd	d
|�D]}|j|d�qPWt|�s�tjd�ni|d6SWn%tk
r�}itd
|�d6SXdS(u
    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:
          - {...}
          - {...}

    RRRRuboto3.paged_callRPu
nextMarkerRQumarkerR;upolicyVersionsuNo versions founduboto3.get_erroruerrorN(RRtlist_policy_versionsRSRIR2R4R(	R;RRRRRtversRUR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRV"s!
c	C@syLtd|d|d|d|�}|jd|dt|��itd6SWn,tk
rz}itd6td|�d	6SXd
S(u�
    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

    RRRRR;RJuchangeduboto3.get_erroruerrorN(Rtset_default_policy_versiontstrRRRR(R;RJRRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRXEs!
c		C@s�y�td|d|d|d|�}g}x>td|jd|ddd	d
�D]}|j|d�qPWt|�s�tjd�ni|d6SWn%tk
r�}itd
|�d6SXdS(u
    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:
          - {...}
          - {...}

    RRRRuboto3.paged_callt	principalRPu
nextMarkerRQumarkerupoliciesuNo policies founduboto3.get_erroruerrorN(RRtlist_principal_policiesRSRIR2R4R(	RZRRRRRRWRUR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR[`s!
c	C@syyFtd|d|d|d|�}|jd|d|�itd6SWn,tk
rt}itd6td|�d	6SXd
S(uQ
    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

    RRRRR;RZuattacheduboto3.get_erroruerrorN(Rtattach_principal_policyRRRR(R;RZRRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR\�s!c	C@syyFtd|d|d|d|�}|jd|d|�itd6SWn,tk
rt}itd6td|�d	6SXd
S(uR
    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

    RRRRR;RZudetacheduboto3.get_erroruerrorN(Rtdetach_principal_policyRRRR(R;RZRRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyR]�s!c		C@s�yBtd|d|d|d|�}|jd|�}itd6SWndtk
r�}td|�}|jjdi�jd	�d
kr�itd6Sitd|�d6SXdS(
u
    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

    RRRRtruleNameuexistsuboto3.get_erroruErroruCodeuUnauthorizedExceptionuerrorN(Rtget_topic_ruleRRRRRR(	R^RRRRRtruleR!R"((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyttopic_rule_exists�s!$c		C@s�ybtd|d|d|d|�}	|	jd|di|d6|d6|d	6|d
6�itd6SWn,tk
r�}
itd6td|
�d
6SXdS(u�
    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"}}]'

    RRRRR^ttopicRulePayloadusqludescriptionuactionsuruleDisableducreateduboto3.get_erroruerrorN(Rtcreate_topic_ruleRRRR(R^tsqltactionstdescriptiontruleDisabledRRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRc�s!c		C@s�ybtd|d|d|d|�}	|	jd|di|d6|d6|d	6|d
6�itd6SWn,tk
r�}
itd6td|
�d
6SXdS(u�
    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"}}]'

    RRRRR^RbusqludescriptionuactionsuruleDisabledureplaceduboto3.get_erroruerrorN(Rtreplace_topic_ruleRRRR(R^RdReRfRgRRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRh�s!c	C@ssy@td|d|d|d|�}|jd|�itd6SWn,tk
rn}itd6td|�d6SXd	S(
u�
    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

    RRRRR^udeleteduboto3.get_erroruerrorN(Rtdelete_topic_ruleRRRR(R^RRRRRR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRis!c
	C@s�y�td|d|d|d|�}|jd|�}|r�d|kr�|d}d}itg|D]}||j|�f^qe�d6Sidd6SWn%tk
r�}	itd|	�d
6SXdS(u�
    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

    RRRRR^uruleuruleNameusqludescriptionuactionsuruleDisableduboto3.get_erroruerrorN(uruleNameusqludescriptionuactionsuruleDisabled(RR_R0RR%RR(
R^RRRRRR`RDRER!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pytdescribe_topic_rule0s!
3c	C@s�y�td|d|d|d|�}i}|dk	rC||d<n|dk	r\||d<ng}x;td|jdd	d
d	|�D]}	|j|	d�q�Wt|�s�tjd�ni|d6SWn%tk
r�}
itd
|
�d6SXdS(u
    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:
          - {...}
          - {...}

    RRRRutopicuruleDisableduboto3.paged_callRPu	nextTokenRQurulesuNo rules founduboto3.get_erroruerrorN(	RR%Rtlist_topic_rulesRSRIR2R4R(ttopicRgRRRRRtkwargstrulesRUR!((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyRkMs$!


(9t__doc__t
__future__RRRtloggingR'tsalt.utils.compatRtsalt.utils.jsontsalt.utils.versionst	getLoggerRR2tsalt.ext.sixRtbototboto3tbotocore.exceptionsRtbotocoreRtfound_botocore_versiontsetLeveltCRITICALRRtImportErrorRRRR%R#RR1R8R:R=RARCRFRKRMRNRORRRVRXR[R\R]RaRcRhRiRjRk(((s9/usr/lib/python2.7/site-packages/salt/modules/boto_iot.pyt<module>0sd


		 %(%#$##   

Zerion Mini Shell 1.0