U
    3ìd;[  ã                   @   s   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
Zd dlmZ d dlmZ d dlmZmZ dZd	ZG d
d„ deƒZdS )é    )Ú	exceptionN)ÚAWSAuthConnection)Úhandler)ÚResourceRecordSets©ÚZone)ÚsixÚurlliba  <?xml version="1.0" encoding="UTF-8"?>
<CreateHostedZoneRequest xmlns="%(xmlns)s">
  <Name>%(name)s</Name>
  <CallerReference>%(caller_ref)s</CallerReference>
  <HostedZoneConfig>
    <Comment>%(comment)s</Comment>
  </HostedZoneConfig>
</CreateHostedZoneRequest>a`  <?xml version="1.0" encoding="UTF-8"?>
<CreateHostedZoneRequest xmlns="%(xmlns)s">
  <Name>%(name)s</Name>
  <VPC>
    <VPCId>%(vpc_id)s</VPCId>
    <VPCRegion>%(vpc_region)s</VPCRegion>
  </VPC>
  <CallerReference>%(caller_ref)s</CallerReference>
  <HostedZoneConfig>
    <Comment>%(comment)s</Comment>
  </HostedZoneConfig>
</CreateHostedZoneRequest>c                       sî   e Zd ZdZdZdZdddddedddddf‡ fdd„	Zd	d
„ Zd2‡ fdd„	Zd3dd„Z	dd„ Z
dd„ Zd4dd„Zdd„ ZdZd5dd„Zd6dd„Zdd„ Zd d!„ Zd7d"d#„Zd$d%„ Zd&d'„ Zd8d(d)„Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Z‡  ZS )9ÚRoute53Connectionzroute53.amazonaws.comz
2013-04-01z-https://route53.amazonaws.com/doc/2013-04-01/Nr   Tc                    s,   t t| ƒj|||d||||||	|
|d d S )NT)ÚdebugÚsecurity_tokenÚvalidate_certsÚhttps_connection_factoryÚprofile_name)Úsuperr
   Ú__init__)ÚselfZaws_access_key_idZaws_secret_access_keyÚportÚproxyZ
proxy_portÚhostr   r   r   r   r   ©Ú	__class__© ú;/tmp/pip-unpacked-wheel-d7dsrkjd/boto/route53/connection.pyr   L   s    
     ùzRoute53Connection.__init__c                 C   s   dgS )NZroute53r   ©r   r   r   r   Ú_required_auth_capabilityZ   s    z+Route53Connection._required_auth_capabilityÚ c           	         sr   |rVg }t  |¡D ]0\}}|d kr$q| |d tj t|ƒ¡ ¡ q|dd |¡ 7 }tt	| ƒj
||||| jdS )Nú=ú?ú&)Zretry_handler)r   Ú	iteritemsÚappendr	   ÚparseÚquoteÚstrÚjoinr   r
   Úmake_requestÚ_retry_handler)	r   ÚactionÚpathÚheadersÚdataÚparamsÚpairsÚkeyÚvalr   r   r   r&   ]   s     
   þzRoute53Connection.make_requestc           	      C   sÊ   i }|rd|i}| j dd| j |d}| ¡ }tj |¡ |jdkrVt |j|j	|¡‚tj
jddd}tj
 |d	¡}| |¡ |r”|d
 d  |¡ d|d
 krÆ|d
 d }|d
 d }|  ||¡}q”|S )aA  
        Returns a Python data structure with information about all
        Hosted Zones defined for the AWS account.

        :param int start_marker: start marker to pass when fetching additional
            results after a truncated list
        :param list zone_list: a HostedZones list to prepend to results
        ÚmarkerÚGETú/%s/hostedzone©r,   é,  ÚHostedZones)Ú
HostedZone©Zlist_markerZitem_markerNÚListHostedZonesResponseZ
NextMarker)r&   ÚVersionÚreadÚbotoÚlogr   Ústatusr   ÚDNSServerErrorÚreasonÚjsonresponseÚElementÚ
XmlHandlerr"   ÚextendÚget_all_hosted_zones)	r   Zstart_markerZ	zone_listr,   ÚresponseÚbodyÚeÚhZnext_markerr   r   r   rD   k   s2    	ÿ
þÿ
z&Route53Connection.get_all_hosted_zonesc                 C   sv   d| j |f }|  d|¡}| ¡ }tj |¡ |jdkrJt |j|j	|¡‚tj
jddd}tj
 |d¡}| |¡ |S )z·
        Get detailed information about a particular Hosted Zone.

        :type hosted_zone_id: str
        :param hosted_zone_id: The unique identifier for the Hosted Zone

        ú/%s/hostedzone/%sr1   r4   ÚNameServers©Z
NameServerr7   N©r9   r&   r:   r;   r<   r   r=   r   r>   r?   r@   rA   rB   r"   ©r   Úhosted_zone_idÚurirE   rF   rG   rH   r   r   r   Úget_hosted_zone‹   s    
þÿ
z!Route53Connection.get_hosted_zonec                 C   sZ   |d dkr|d7 }|   ¡ }|d d D ],}|d |kr(|  |d  d¡d ¡  S q(dS )	zÑ
        Get detailed information about a particular Hosted Zone.

        :type hosted_zone_name: str
        :param hosted_zone_name: The fully qualified domain name for the Hosted
            Zone

        éÿÿÿÿÚ.r8   r5   ÚNameZIdú/N)rD   rP   Úsplit)r   Zhosted_zone_nameZall_hosted_zonesÚzoner   r   r   Úget_hosted_zone_by_name¡   s    	z)Route53Connection.get_hosted_zone_by_nameFc                 C   sÌ   |dkrt t ¡ ƒ}|r6|||||| jdœ}t| }n|||| jdœ}t| }d| j }	|  d|	ddi|¡}
|
 ¡ }t	j
 |¡ |
jdkr¶t	jjd	d
d}t	j |d¡}| |¡ |S t |
j|
j|¡‚dS )a^  
        Create a new Hosted Zone.  Returns a Python data structure with
        information about the newly created Hosted Zone.

        :type domain_name: str
        :param domain_name: The name of the domain. This should be a
            fully-specified domain, and should end with a final period
            as the last label indication.  If you omit the final period,
            Amazon Route 53 assumes the domain is relative to the root.
            This is the name you have registered with your DNS registrar.
            It is also the name you will delegate from your registrar to
            the Amazon Route 53 delegation servers returned in
            response to this request.A list of strings with the image
            IDs wanted.

        :type caller_ref: str
        :param caller_ref: A unique string that identifies the request
            and that allows failed CreateHostedZone requests to be retried
            without the risk of executing the operation twice.  If you don't
            provide a value for this, boto will generate a Type 4 UUID and
            use that.

        :type comment: str
        :param comment: Any comments you want to include about the hosted
            zone.

        :type private_zone: bool
        :param private_zone: Set True if creating a private hosted zone.

        :type vpc_id: str
        :param vpc_id: When creating a private hosted zone, the VPC Id to
            associate to is required.

        :type vpc_region: str
        :param vpc_region: When creating a private hosted zone, the region
            of the associated VPC is required.

        N)ÚnameÚ
caller_refÚcommentÚvpc_idÚ
vpc_regionÚxmlns)rX   rY   rZ   r]   r2   ÚPOSTúContent-Typeútext/xmléÉ   rJ   rK   r7   )r$   ÚuuidÚuuid4ÚXMLNameSpaceÚHZPXMLÚHZXMLr9   r&   r:   r;   r<   r   r=   r@   rA   rB   r"   r   r>   r?   )r   Zdomain_namerY   rZ   Úprivate_zoner[   r\   r,   Úxml_bodyrO   rE   rF   rG   rH   r   r   r   Úcreate_hosted_zone²   sF    (û
ý
 ÿ
ÿ
þz$Route53Connection.create_hosted_zonec                 C   sp   d| j |f }|  d|¡}| ¡ }tj |¡ |jdkrJt |j|j	|¡‚tj
 ¡ }tj
 |d¡}| |¡ |S )z›
        Delete the hosted zone specified by the given id.

        :type hosted_zone_id: str
        :param hosted_zone_id: The hosted zone's id

        rI   ÚDELETE©éÈ   éÌ   NrL   rM   r   r   r   Údelete_hosted_zoneú   s    
þ

z$Route53Connection.delete_hosted_zonez—<CreateHealthCheckRequest xmlns="%(xmlns)s">
    <CallerReference>%(caller_ref)s</CallerReference>
    %(health_check)s
    </CreateHealthCheckRequest>c           
      C   s¨   |dkrt t ¡ ƒ}d| j }| j|| ¡ dœ}| j| }|  d|ddi|¡}| ¡ }t	j
 |¡ |jdkr’t	j ¡ }t	j |d¡}	|	 |¡ |S t |j|j|¡‚dS )aì  
        Create a new Health Check

        :type health_check: HealthCheck
        :param health_check: HealthCheck object

        :type caller_ref: str
        :param caller_ref: A unique string that identifies the request
            and that allows failed CreateHealthCheckRequest requests to be retried
            without the risk of executing the operation twice.  If you don't
            provide a value for this, boto will generate a Type 4 UUID and
            use that.

        Nú/%s/healthcheck)r]   rY   Úhealth_checkr^   r_   r`   ra   )r$   rb   rc   r9   rd   Zto_xmlÚPOSTHCXMLBodyr&   r:   r;   r<   r   r=   r@   rA   rB   r"   r   r>   r?   )
r   rp   rY   rO   r,   rh   rE   rF   rG   rH   r   r   r   Úcreate_health_check  s"    
þ



z%Route53Connection.create_health_checkc           	      C   sœ   i }|dk	r||d< |dk	r$||d< d| j f }| jd||d}| ¡ }tj |¡ |jdkrpt |j|j	|¡‚tj
jdd	d
}tj
 |d¡}| |¡ |S )zã
        Return a list of health checks

        :type maxitems: int
        :param maxitems: Maximum number of items to return

        :type marker: str
        :param marker: marker to get next set of items to list

        NÚmaxitemsr0   ro   r1   r3   r4   ZHealthChecks)ZHealthCheckr7   rL   )	r   rs   r0   r,   rO   rE   rF   rG   rH   r   r   r   Úget_list_health_checks8  s(    
þÿ
z(Route53Connection.get_list_health_checksc                 C   sr   d| j  }|  d|¡}| ¡ }tj |¡ |jdkrFt |j|j	|¡‚tj
jddd}tj
 |d¡}| |¡ |S )z@
        Return a list of Route53 healthcheck IP ranges
        z/%s/checkeriprangesr1   r4   ZCheckerIpRanges)Úmemberr7   NrL   )r   rO   rE   rF   rG   rH   r   r   r   Úget_checker_ip_rangesX  s    

þ
z'Route53Connection.get_checker_ip_rangesc                 C   sp   d| j |f }|  d|¡}| ¡ }tj |¡ |jdkrJt |j|j	|¡‚tj
 ¡ }tj
 |d¡}| |¡ |S )z
        Delete a health check

        :type health_check_id: str
        :param health_check_id: ID of the health check to delete

        z/%s/healthcheck/%srj   rk   NrL   )r   Zhealth_check_idrO   rE   rF   rG   rH   r   r   r   Údelete_health_checki  s    
þ

z%Route53Connection.delete_health_checkc                 C   s†   ||||dœ}d| j |f }| jd||d}| ¡ }	tj |	¡ |jdkr\t |j|j	|	¡‚t
| |d}
t |
| ¡}tj |	|¡ |
S )aÿ  
        Retrieve the Resource Record Sets defined for this Hosted Zone.
        Returns the raw XML data returned by the Route53 call.

        :type hosted_zone_id: str
        :param hosted_zone_id: The unique identifier for the Hosted Zone

        :type type: str
        :param type: The type of resource record set to begin the record
            listing from.  Valid choices are:

                * A
                * AAAA
                * CNAME
                * MX
                * NS
                * PTR
                * SOA
                * SPF
                * SRV
                * TXT

            Valid values for weighted resource record sets:

                * A
                * AAAA
                * CNAME
                * TXT

            Valid values for Zone Apex Aliases:

                * A
                * AAAA

        :type name: str
        :param name: The first name in the lexicographic ordering of domain
                     names to be retrieved

        :type identifier: str
        :param identifier: In a hosted zone that includes weighted resource
            record sets (multiple resource record sets with the same DNS
            name and type that are differentiated only by SetIdentifier),
            if results were truncated for a given DNS name and type,
            the value of SetIdentifier for the next resource record
            set that has the current DNS name and type

        :type maxitems: int
        :param maxitems: The maximum number of records

        )ÚtyperX   Ú
identifierrs   ú/%s/hostedzone/%s/rrsetr1   r3   r4   )Ú
connectionrN   )r9   r&   r:   r;   r<   r   r=   r   r>   r?   r   r   rB   ÚxmlÚsaxÚparseString)r   rN   rx   rX   ry   rs   r,   rO   rE   rF   ÚrsrH   r   r   r   Úget_all_rrsets€  s"    4 ÿ
þz Route53Connection.get_all_rrsetsc                 C   sx   d| j |f }|  d|ddi|¡}| ¡ }tj |¡ |jdkrRt |j|j	|¡‚tj
 ¡ }tj
 |d¡}| |¡ |S )aß  
        Create or change the authoritative DNS information for this
        Hosted Zone.
        Returns a Python data structure with information about the set of
        changes, including the Change ID.

        :type hosted_zone_id: str
        :param hosted_zone_id: The unique identifier for the Hosted Zone

        :type xml_body: str
        :param xml_body: The list of changes to be made, defined in the
            XML schema defined by the Route53 service.

        rz   r^   r_   r`   r4   NrL   )r   rN   rh   rO   rE   rF   rG   rH   r   r   r   Úchange_rrsetsÃ  s     þ
þ

zRoute53Connection.change_rrsetsc                 C   sp   d| j |f }|  d|¡}| ¡ }tj |¡ |jdkrJt |j|j	|¡‚tj
 ¡ }tj
 |d¡}| |¡ |S )aƒ  
        Get information about a proposed set of changes, as submitted
        by the change_rrsets method.
        Returns a Python data structure with status information about the
        changes.

        :type change_id: str
        :param change_id: The unique identifier for the set of changes.
            This ID is returned in the response to the change_rrsets method.

        z/%s/change/%sr1   r4   NrL   )r   Z	change_idrO   rE   rF   rG   rH   r   r   r   Ú
get_changeá  s    
þ

zRoute53Connection.get_changec                 C   s$   | j ||||d}t| |d d ƒS )a#  
        Create a new Hosted Zone.  Returns a Zone object for the newly
        created Hosted Zone.

        :type name: str
        :param name: The name of the domain. This should be a
            fully-specified domain, and should end with a final period
            as the last label indication.  If you omit the final period,
            Amazon Route 53 assumes the domain is relative to the root.
            This is the name you have registered with your DNS registrar.
            It is also the name you will delegate from your registrar to
            the Amazon Route 53 delegation servers returned in
            response to this request.

        :type private_zone: bool
        :param private_zone: Set True if creating a private hosted zone.

        :type vpc_id: str
        :param vpc_id: When creating a private hosted zone, the VPC Id to
            associate to is required.

        :type vpc_region: str
        :param vpc_region: When creating a private hosted zone, the region
            of the associated VPC is required.
        )rg   r[   r\   ZCreateHostedZoneResponser6   )ri   r   )r   rX   rg   r[   r\   rV   r   r   r   Úcreate_zoneú  s
     ÿzRoute53Connection.create_zonec                 C   s.   |   |¡}|  ¡ D ]}||jkr|  S qdS )zö
        Returns a Zone object for the specified Hosted Zone.

        :param name: The name of the domain. This should be a
            fully-specified domain, and should end with a final period
            as the last label indication.
        N)Ú_make_qualifiedÚ	get_zonesrX   )r   rX   rV   r   r   r   Úget_zone  s    

zRoute53Connection.get_zonec                    s"   ˆ   ¡ }‡ fdd„|d d D ƒS )z¸
        Returns a list of Zone objects, one for each of the Hosted
        Zones defined for the AWS account.

        :rtype: list
        :returns: A list of Zone objects.

        c                    s   g | ]}t ˆ |ƒ‘qS r   r   )Ú.0rV   r   r   r   Ú
<listcomp>0  s     z/Route53Connection.get_zones.<locals>.<listcomp>r8   r5   )rD   )r   Zzonesr   r   r   r…   &  s    	

ÿzRoute53Connection.get_zonesc                 C   sv   t |ƒtttfkrNg }|D ].}|r>|d dks>| d| ¡ q| |¡ q|S | ¡ }|rn|d dksnd| }|S dS )z„
        Ensure passed domain names end in a period (.) character.
        This will usually make a domain fully qualified.
        rQ   rR   z%s.N)rx   ÚlistÚtupleÚsetr!   Ústrip)r   ÚvalueZnew_listÚrecordr   r   r   r„   3  s    z!Route53Connection._make_qualifiedc                 C   s”   d }t j d|j ¡ |jdkr| ¡ }t |j|j|¡}|jr|jdkrN|S d|j|f }t	t
 
¡ d|  t j ddd¡ƒ}|d	7 }|||f}|S )
NzSaw HTTP status: %si  )ZPriorRequestNotCompleteZ
ThrottlingZServiceUnavailableZRequestExpiredz%s, retry attempt %sé   ZBotoZmax_retry_delayé<   é   )r;   r<   r   r=   r:   r   r>   r?   Z
error_codeÚminÚrandomÚconfigÚget)r   rE   ÚiZ
next_sleepr=   rF   ÚerrÚmsgr   r   r   r'   F  s,    
ý
þÿ
z Route53Connection._retry_handler)Nr   N)NN)Nr   FNN)N)NN)NNNN)FNN)Ú__name__Ú
__module__Ú__qualname__ZDefaultHostr9   rd   r   r   r&   rD   rP   rW   ri   rn   rq   rr   rt   rv   rw   r€   r   r‚   rƒ   r†   r…   r„   r'   Ú__classcell__r   r   r   r   r
   B   sZ        ü
       ÿ
H
"
       ÿ
C    ÿ
r
   )Zboto.route53r   r“   rb   Zxml.saxr|   r;   Zboto.connectionr   r   Zboto.jsonresponseZboto.route53.recordr   Zboto.route53.zoner   Zboto.compatr   r	   rf   re   r
   r   r   r   r   Ú<module>   s   	