U
    3d[C                     @   sX   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 G dd deZdS )	    N)json)AWSQueryConnection)
RegionInfo)JSONResponseError)
exceptionsc                       s   e Zd ZdZdZdZdZdZdZe	Z
ejejejejejejejejejejejejejejejejejejejejdZ  fdd	Z!d
d Z"dd Z#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 Z*dd Z+dd  Z,d!d" Z-d#d$ Z.  Z/S )*ConfigServiceConnectionaM  
    AWS Config
    AWS Config provides a way to keep track of the configurations of
    all the AWS resources associated with your AWS account. You can
    use AWS Config to get the current and historical configurations of
    each AWS resource and also to get information about the
    relationship between the resources. An AWS resource can be an
    Amazon Compute Cloud (Amazon EC2) instance, an Elastic Block Store
    (EBS) volume, an Elastic network Interface (ENI), or a security
    group. For a complete list of resources currently supported by AWS
    Config, see `Supported AWS Resources`_.

    You can access and manage AWS Config through the AWS Management
    Console, the AWS Command Line Interface (AWS CLI), the AWS Config
    API, or the AWS SDKs for AWS Config

    This reference guide contains documentation for the AWS Config API
    and the AWS CLI commands that you can use to manage AWS Config.

    The AWS Config API uses the Signature Version 4 protocol for
    signing requests. For more information about how to sign a request
    with this protocol, see `Signature Version 4 Signing Process`_.

    For detailed information about AWS Config features and their
    associated actions or commands, as well as how to work with AWS
    Management Console, see `What Is AWS Config?`_ in the AWS Config
    Developer Guide .
    z
2014-11-12z	us-east-1zconfig.us-east-1.amazonaws.comZConfigServiceZStarlingDoveService)InvalidLimitExceptionNoSuchBucketExceptionInvalidSNSTopicARNExceptionResourceNotDiscoveredException,MaxNumberOfDeliveryChannelsExceededException(LastDeliveryChannelDeleteFailedException#InsufficientDeliveryPolicyExceptionInvalidRoleExceptionInvalidTimeRangeExceptionNoSuchDeliveryChannelException$NoSuchConfigurationRecorderExceptionInvalidS3KeyPrefixException#InvalidDeliveryChannelNameException'NoRunningConfigurationRecorderExceptionValidationException)NoAvailableConfigurationRecorderExceptionInvalidNextTokenException)InvalidConfigurationRecorderNameException#NoAvailableDeliveryChannelException2MaxNumberOfConfigurationRecordersExceededExceptionc                    sZ   | dd }|s t| | j| j}d|ks4|d d kr>|j|d< tt| jf | || _d S )Nregionhost)	popr   DefaultRegionNameDefaultRegionEndpointendpointsuperr   __init__r   )selfkwargsr   	__class__ =/tmp/pip-unpacked-wheel-d7dsrkjd/boto/configservice/layer1.pyr#   [   s    
z ConfigServiceConnection.__init__c                 C   s   dgS )Nzhmac-v4r(   )r$   r(   r(   r)   _required_auth_capabilityg   s    z1ConfigServiceConnection._required_auth_capabilityc                 C   s   d|i}| j dt|dS )a  
        Deletes the specified delivery channel.

        The delivery channel cannot be deleted if it is the only
        delivery channel and the configuration recorder is still
        running. To delete the delivery channel, stop the running
        configuration recorder using the StopConfigurationRecorder
        action.

        :type delivery_channel_name: string
        :param delivery_channel_name: The name of the delivery channel to
            delete.

        ZDeliveryChannelNameZDeleteDeliveryChannelactionbodymake_requestr   dumpsr$   Zdelivery_channel_nameparamsr(   r(   r)   delete_delivery_channelj   s    z/ConfigServiceConnection.delete_delivery_channelc                 C   s   d|i}| j dt|dS )a  
        Schedules delivery of a configuration snapshot to the Amazon
        S3 bucket in the specified delivery channel. After the
        delivery has started, AWS Config sends following notifications
        using an Amazon SNS topic that you have specified.


        + Notification of starting the delivery.
        + Notification of delivery completed, if the delivery was
          successfully completed.
        + Notification of delivery failure, if the delivery failed to
          complete.

        :type delivery_channel_name: string
        :param delivery_channel_name: The name of the delivery channel through
            which the snapshot is delivered.

        ZdeliveryChannelNameZDeliverConfigSnapshotr+   r.   r1   r(   r(   r)   deliver_config_snapshot}   s    z/ConfigServiceConnection.deliver_config_snapshotNc                 C   s(   i }|dk	r||d< | j dt|dS )a(  
        Returns the current status of the specified configuration
        recorder. If a configuration recorder is not specified, this
        action returns the status of all configuration recorder
        associated with the account.

        :type configuration_recorder_names: list
        :param configuration_recorder_names: The name(s) of the configuration
            recorder. If the name is not specified, the action returns the
            current status of all the configuration recorders associated with
            the account.

        NConfigurationRecorderNamesZ#DescribeConfigurationRecorderStatusr+   r.   r$   Zconfiguration_recorder_namesr2   r(   r(   r)   &describe_configuration_recorder_status   s    z>ConfigServiceConnection.describe_configuration_recorder_statusc                 C   s(   i }|dk	r||d< | j dt|dS )a  
        Returns the name of one or more specified configuration
        recorders. If the recorder name is not specified, this action
        returns the names of all the configuration recorders
        associated with the account.

        :type configuration_recorder_names: list
        :param configuration_recorder_names: A list of configuration recorder
            names.

        Nr5   ZDescribeConfigurationRecordersr+   r.   r6   r(   r(   r)    describe_configuration_recorders   s    z8ConfigServiceConnection.describe_configuration_recordersc                 C   s(   i }|dk	r||d< | j dt|dS )ab  
        Returns the current status of the specified delivery channel.
        If a delivery channel is not specified, this action returns
        the current status of all delivery channels associated with
        the account.

        :type delivery_channel_names: list
        :param delivery_channel_names: A list of delivery channel names.

        NDeliveryChannelNamesZDescribeDeliveryChannelStatusr+   r.   r$   Zdelivery_channel_namesr2   r(   r(   r)    describe_delivery_channel_status   s    z8ConfigServiceConnection.describe_delivery_channel_statusc                 C   s(   i }|dk	r||d< | j dt|dS )aK  
        Returns details about the specified delivery channel. If a
        delivery channel is not specified, this action returns the
        details of all delivery channels associated with the account.

        :type delivery_channel_names: list
        :param delivery_channel_names: A list of delivery channel names.

        Nr9   ZDescribeDeliveryChannelsr+   r.   r:   r(   r(   r)   describe_delivery_channels   s    
z2ConfigServiceConnection.describe_delivery_channelsc           	      C   sn   ||d}|dk	r||d< |dk	r*||d< |dk	r:||d< |dk	rJ||d< |dk	rZ||d< | j dt|d	S )
ab  
        Returns a list of configuration items for the specified
        resource. The list contains details about each state of the
        resource during the specified time interval. You can specify a
        `limit` on the number of results returned on the page. If a
        limit is specified, a `nextToken` is returned as part of the
        result that you can use to continue this request.

        :type resource_type: string
        :param resource_type: The resource type.

        :type resource_id: string
        :param resource_id: The ID of the resource (for example., `sg-xxxxxx`).

        :type later_time: timestamp
        :param later_time: The time stamp that indicates a later time. If not
            specified, current time is taken.

        :type earlier_time: timestamp
        :param earlier_time: The time stamp that indicates an earlier time. If
            not specified, the action returns paginated results that contain
            configuration items that start from when the first configuration
            item was recorded.

        :type chronological_order: string
        :param chronological_order: The chronological order for configuration
            items listed. By default the results are listed in reverse
            chronological order.

        :type limit: integer
        :param limit: The maximum number of configuration items returned in
            each page. The default is 10. You cannot specify a limit greater
            than 100.

        :type next_token: string
        :param next_token: An optional parameter used for pagination of the
            results.

        )ZresourceTypeZ
resourceIdNZ	laterTimeZearlierTimeZchronologicalOrderlimitZ	nextTokenZGetResourceConfigHistoryr+   r.   )	r$   Zresource_typeZresource_idZ
later_timeZearlier_timeZchronological_orderr=   Z
next_tokenr2   r(   r(   r)   get_resource_config_history   s     ,z3ConfigServiceConnection.get_resource_config_historyc                 C   s   d|i}| j dt|dS )a  
        Creates a new configuration recorder to record the resource
        configurations.

        You can use this action to change the role ( `roleARN`) of an
        existing recorder. To change the role, call the action on the
        existing configuration recorder and specify a role.

        :type configuration_recorder: dict
        :param configuration_recorder: The configuration recorder object that
            records each configuration change made to the resources. The
            format should follow:

            {'name': 'myrecorder',
             'roleARN': 'arn:aws:iam::123456789012:role/trusted-aws-config'}

        ZConfigurationRecorderZPutConfigurationRecorderr+   r.   )r$   Zconfiguration_recorderr2   r(   r(   r)   put_configuration_recorder  s    z2ConfigServiceConnection.put_configuration_recorderc                 C   s   d|i}| j dt|dS )a_  
        Creates a new delivery channel object to deliver the
        configuration information to an Amazon S3 bucket, and to an
        Amazon SNS topic.

        You can use this action to change the Amazon S3 bucket or an
        Amazon SNS topic of the existing delivery channel. To change
        the Amazon S3 bucket or an Amazon SNS topic, call this action
        and specify the changed values for the S3 bucket and the SNS
        topic. If you specify a different value for either the S3
        bucket or the SNS topic, this action will keep the existing
        value for the parameter that is not changed.

        :type delivery_channel: dict
        :param delivery_channel: The configuration delivery channel object that
            delivers the configuration information to an Amazon S3 bucket, and
            to an Amazon SNS topic.

        ZDeliveryChannelZPutDeliveryChannelr+   r.   )r$   Zdelivery_channelr2   r(   r(   r)   put_delivery_channel/  s    z,ConfigServiceConnection.put_delivery_channelc                 C   s   d|i}| j dt|dS )a  
        Starts recording configurations of all the resources
        associated with the account.

        You must have created at least one delivery channel to
        successfully start the configuration recorder.

        :type configuration_recorder_name: string
        :param configuration_recorder_name: The name of the recorder object
            that records each configuration change made to the resources.

        ConfigurationRecorderNameZStartConfigurationRecorderr+   r.   r$   Zconfiguration_recorder_namer2   r(   r(   r)   start_configuration_recorderG  s     z4ConfigServiceConnection.start_configuration_recorderc                 C   s   d|i}| j dt|dS )a4  
        Stops recording configurations of all the resources associated
        with the account.

        :type configuration_recorder_name: string
        :param configuration_recorder_name: The name of the recorder object
            that records each configuration change made to the resources.

        rA   ZStopConfigurationRecorderr+   r.   rB   r(   r(   r)   stop_configuration_recorderZ  s     z3ConfigServiceConnection.stop_configuration_recorderc           
      C   s   d| j |f | jjdtt|d}| jdddi ||d}| j|d dd}| d	}t	j
| |jd
kr~|rt|S n8t|}|dd }| j|| j}	|	|j|j|dd S )Nz%s.%szapplication/x-amz-json-1.1)zX-Amz-TargetHostzContent-TypezContent-LengthPOST/)methodpathZ	auth_pathr2   headersdata
   )ZsenderZoverride_num_retrieszutf-8   Z__type)r-   )TargetPrefixr   r!   strlenZbuild_base_http_requestZ_mexereaddecodebotologdebugstatusr   loadsget_faultsResponseErrorreason)
r$   r,   r-   rJ   http_requestresponseZresponse_bodyZ	json_bodyZ
fault_nameZexception_classr(   r(   r)   r/   j  s6    
    


z$ConfigServiceConnection.make_request)N)N)N)N)NNNNN)0__name__
__module____qualname____doc__Z
APIVersionr   r    ZServiceNamerN   r   rZ   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   r#   r*   r3   r4   r7   r8   r;   r<   r>   r?   r@   rC   rD   r/   __classcell__r(   r(   r&   r)   r      sb    
 


       
<r   )rS   Zboto.compatr   Zboto.connectionr   Zboto.regioninfor   Zboto.exceptionr   Zboto.configservicer   r   r(   r(   r(   r)   <module>   s   