%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyo

�
���^c
@@s!dZddlmZmZmZddlZddlmZddlZ	ddl
Z	eje�Z
yKddlZddlZddlmZejd�jej�eZWnek
r�eZnXd�Zd�Zddddd	�Zddddddddddddd
�Zddddd�Zddddd�Zddddd
�Zddddd�Z ddddddddddddd�Z!ddddd�Z"ddddd�Z#ddddd�Z$ddddd�Z%ddddd�Z&ddddd�Z'dS(uN
Connection module for Amazon CloudTrail

.. 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

        cloudtrail.keyid: GKTADJGHEIQSXMKKRBJ08H
        cloudtrail.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    A region may also be specified in the configuration:

    .. code-block:: yaml

        cloudtrail.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(tsix(tClientErroruboto3cC@stjjjdd�S(ug
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    t	boto3_veru1.2.5(tsalttutilstversionstcheck_boto_reqs(((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyt__virtual__OscC@s1tjjjt�tr-tdtd�ndS(Nuboto3.assign_funcsu
cloudtrail(RRtcompattpack_dundert__name__tHAS_BOTOt	__utils__(topts((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyt__init__\sc	C@s�y@td|d|d|d|�}|jd|�itd6SWnZtk
r�}td|�}|jjdi�jd	�d
kr�itd6Si|d6SXdS(
u

    Given a trail name, check to see if the given trail exists.

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

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.exists mytrail

    tregiontkeytkeyidtprofiletNameuexistsuboto3.get_erroruErroruCodeuTrailNotFoundExceptionuerrorN(t	_get_conntget_trail_statustTrueRRtresponsetgettFalse(RRRRRtconnteterr((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytexistsbs!$c	C@s�y�td|
d|d|d|
�}i}x5dD]-}t�|dk	r1t�|||<q1q1W|jd
|d||�}|r�tjd|d�itd6|dd6Stjd�itd6SWn,t	k
r�}itd6t
d|�d6SXdS(u
    Given a valid config, create a trail.

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

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.create my_trail my_bucket

    RRRRuS3KeyPrefixuSnsTopicNameuIncludeGlobalServiceEventsuIsMultiRegionTrailuEnableLogFileValidationuCloudWatchLogsLogGroupArnuCloudWatchLogsRoleArnuKmsKeyIdRtS3BucketNameu"The newly created trail name is %suNameucreatedunameuTrail was not createduboto3.get_erroruerrorN(uS3KeyPrefixuSnsTopicNameuIncludeGlobalServiceEventsuIsMultiRegionTrailuEnableLogFileValidationuCloudWatchLogsLogGroupArnuCloudWatchLogsRoleArnuKmsKeyId(RtlocalstNonetcreate_trailtlogtinfoRtwarningRRR(RR!tS3KeyPrefixtSnsTopicNametIncludeGlobalServiceEventstIsMultiRegionTrailtEnableLogFileValidationtCloudWatchLogsLogGroupArntCloudWatchLogsRoleArntKmsKeyIdRRRRRtkwargstargttrailR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytcreate}s&!
	
c	C@ssy@td|d|d|d|�}|jd|�itd6SWn,tk
rn}itd6td|�d6SXd	S(
u
    Given a trail name, delete it.

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

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.delete mytrail

    RRRRRudeleteduboto3.get_erroruerrorN(Rtdelete_trailRRRR(RRRRRRR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytdelete�s!c
C@sy�td|d|d|d|�}|jd|g�}|r�t|jdg��dkr�d}|dj�}itg|D]}	|	|j|	�f^q��d6Sidd6SWndtk
r}
td|
�}|
j	jdi�jd�dkridd6Sitd|
�d6SXdS(u�
    Given a trail name describe its properties.

    Returns a dictionary of interesting properties.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.describe mytrail

    RRRRt
trailNameListu	trailListiuNameuS3BucketNameuS3KeyPrefixuSnsTopicNameuIncludeGlobalServiceEventsuIsMultiRegionTrailu
HomeRegionuTrailARNuLogFileValidationEnableduCloudWatchLogsLogGroupArnuCloudWatchLogsRoleArnuKmsKeyIdutrailuboto3.get_erroruErroruCodeuTrailNotFoundExceptionuerrorN(uNameuS3BucketNameuS3KeyPrefixuSnsTopicNameuIncludeGlobalServiceEventsuIsMultiRegionTrailu
HomeRegionuTrailARNuLogFileValidationEnableduCloudWatchLogsLogGroupArnuCloudWatchLogsRoleArnuKmsKeyId(
Rtdescribe_trailstlenRtpoptdictR#RRR(RRRRRRttrailstkeysR2tkRR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytdescribe�s$!$3$cC@s�y�td|d|d|d|�}|jd|�}|rud}itg|D]}||j|�f^qO�d6Sidd6SWndtk
r�}	td|	�}
|	jjdi�jd�dkr�idd6Sitd|	�d6SXdS(u�
    Given a trail name describe its properties.

    Returns a dictionary of interesting properties.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.describe mytrail

    RRRRRu	IsLogginguLatestDeliveryErroruLatestNotificationErroruLatestDeliveryTimeuLatestNotificationTimeuStartLoggingTimeuStopLoggingTimeu!LatestCloudWatchLogsDeliveryErroru LatestCloudWatchLogsDeliveryTimeuLatestDigestDeliveryTimeuLatestDigestDeliveryErroruLatestDeliveryAttemptTimeuLatestNotificationAttemptTimeu"LatestNotificationAttemptSucceededuLatestDeliveryAttemptSucceededuTimeLoggingStarteduTimeLoggingStoppedutrailuboto3.get_erroruErroruCodeuTrailNotFoundExceptionuerrorN(u	IsLogginguLatestDeliveryErroruLatestNotificationErroruLatestDeliveryTimeuLatestNotificationTimeuStartLoggingTimeuStopLoggingTimeu!LatestCloudWatchLogsDeliveryErroru LatestCloudWatchLogsDeliveryTimeuLatestDigestDeliveryTimeuLatestDigestDeliveryErroruLatestDeliveryAttemptTimeuLatestNotificationAttemptTimeu"LatestNotificationAttemptSucceededuLatestDeliveryAttemptSucceededuTimeLoggingStarteduTimeLoggingStopped(RRR:RR#RRR(RRRRRRR2R<R=RR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytstatus�s.!3$c	C@s�ymtd|d|d|d|�}|j�}t|jd��sUtjd�ni|jdg�d6SWn%tk
r�}itd|�d	6SXd
S(u�
    List all trails

    Returns list of trails

    CLI Example:

    .. code-block:: yaml

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

    RRRRu	trailListuNo trails foundutrailsuboto3.get_erroruerrorN(RR7tboolRR%R'RR(RRRRRR;R((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytlists!c	C@s�y�td|
d|d|d|
�}i}x5dD]-}t�|dk	r1t�|||<q1q1W|jd
|d||�}|r�tjd|d�itd6|dd6Stjd�itd6SWn,t	k
r�}itd6t
d|�d6SXdS(u
    Given a valid config, update a trail.

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

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.update my_trail my_bucket

    RRRRuS3KeyPrefixuSnsTopicNameuIncludeGlobalServiceEventsuIsMultiRegionTrailuEnableLogFileValidationuCloudWatchLogsLogGroupArnuCloudWatchLogsRoleArnuKmsKeyIdRR!uThe updated trail name is %suNameuupdatedunameuTrail was not createduboto3.get_erroruerrorN(uS3KeyPrefixuSnsTopicNameuIncludeGlobalServiceEventsuIsMultiRegionTrailuEnableLogFileValidationuCloudWatchLogsLogGroupArnuCloudWatchLogsRoleArnuKmsKeyId(RR"R#tupdate_trailR%R&RR'RRR(RR!R(R)R*R+R,R-R.R/RRRRRR0R1R2R((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pytupdate*s&!
	
c	C@ssy@td|d|d|d|�}|jd|�itd6SWn,tk
rn}itd6td|�d6SXd	S(
u
    Start logging for a trail

    Returns {started: true} if the trail was started and returns
    {started: False} if the trail was not started.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.start_logging my_trail

    RRRRRustarteduboto3.get_erroruerrorN(Rt
start_loggingRRRR(RRRRRRR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyRDYs!c	C@ssy@td|d|d|d|�}|jd|�itd6SWn,tk
rn}itd6td|�d6SXd	S(
u
    Stop logging for a trail

    Returns {stopped: true} if the trail was stopped and returns
    {stopped: False} if the trail was not stopped.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.stop_logging my_trail

    RRRRRustoppeduboto3.get_erroruerrorN(Rtstop_loggingRRRR(RRRRRRR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyREqs!c	C@s|jd�r|Stdd|d|d|d|�}|rWd|krW|d}n|dkrld}nd	j|||�S(
Nuarn:aws:cloudtrail:uboto_iam.get_account_idRRRRuregionu	us-east-1u$arn:aws:cloudtrail:{0}:{1}:trail/{2}(t
startswitht__salt__R#tformat(tnameRRRRt
account_id((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyt_get_trail_arn�s

	cK@sy�td|d|d|d|�}g}xhtj|�D]W\}}	tj|�jd�rdq:n|jitj|�d6tj|	�d6�q:W|jdt|d|d|d|d|�d	|�itd
6SWn,t	k
r}
it
d
6td|
�d6SXd
S(u
    Add tags to a trail

    Returns {tagged: true} if the trail was tagged and returns
    {tagged: False} if the trail was not tagged.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.add_tags my_trail tag_a=tag_value tag_b=tag_value

    RRRRu__uKeyuValuet
ResourceIdtTagsListutaggeduboto3.get_erroruerrorN(RRt	iteritemst	text_typeRFtappendtadd_tagsRKRRRR(RRRRRR0RttagslistR=tvR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyRQ�s!1cK@sy�td|d|d|d|�}g}xhtj|�D]W\}}	tj|�jd�rdq:n|jitj|�d6tj|	�d6�q:W|jdt|d|d|d|d|�d	|�itd
6SWn,t	k
r}
it
d
6td|
�d6SXd
S(u
    Remove tags from a trail

    Returns {tagged: true} if the trail was tagged and returns
    {tagged: False} if the trail was not tagged.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.remove_tags my_trail tag_a=tag_value tag_b=tag_value

    RRRRu__uKeyuValueRLRMutaggeduboto3.get_erroruerrorN(RRRNRORFRPtremove_tagsRKRRRR(RRRRRR0RRRR=RSR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyRT�s!1c
C@s�y�td|d|d|d|�}t|d|d|d|d|�}|jd|g�}|jdg�j�jd�}i}	x*|D]"}
|
jd�|	|
jd	�<q�Wi|	d
6SWn%tk
r�}itd|�d6SXd
S(u�
    List tags of a trail

    Returns:
        tags:
          - {...}
          - {...}

    CLI Example:

    .. code-block:: bash

        salt myminion boto_cloudtrail.list_tags my_trail

    RRRRtResourceIdListuResourceTagListuTagsListuValueuKeyutagsuboto3.get_erroruerrorN(RRKt	list_tagsRR9RR(RRRRRRtridtretttlistttagdictttagR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyRV�s!		!
 ((t__doc__t
__future__RRRtloggingtsalt.extRtsalt.utils.compatRtsalt.utils.versionst	getLoggerR
R%tbototboto3tbotocore.exceptionsRtsetLeveltCRITICALRRtImportErrorRR
RR#R R3R5R>R?RARCRDRERKRQRTRV(((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudtrail.pyt<module>0sZ


	
	'$('

Zerion Mini Shell 1.0