o
    .&ßaT)  ã                   @   sò   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m	Z	 d dl
mZ d dlmZ dd„ Zdd
d„Zdd„ ZG dd„ de	ƒZG dd„ de	ƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ ZG dd„ deƒZG dd„ deƒZdS )é    N)Úparse_to_aware_datetime)ÚCloudFrontSigner)ÚCustomArgument)Ú#validate_mutually_exclusive_handler)ÚBasicCommandc                    sª   |   dt¡ |   dt¡ |   dtdgdgƒ¡ |   dtddgd	gƒ¡ |   d
dd„ ¡ |   d
dd„ ¡ i ‰ | j dˆ jdd� |   dtdgd	gƒ¡ |   d‡ fdd„¡ d S )Nz!building-command-table.cloudfrontz6building-argument-table.cloudfront.create-invalidationz4operation-args-parsed.cloudfront.create-invalidationÚinvalidation_batchÚpathsz4operation-args-parsed.cloudfront.create-distributionÚdefault_root_objectÚorigin_domain_nameÚdistribution_configz6building-argument-table.cloudfront.create-distributionc                 [   ó   |   dt| ƒ¡S )Núorigin-domain-name)Ú__setitem__ÚOriginDomainName©Úargument_tableÚkwargs© r   úB/usr/lib/python3/dist-packages/awscli/customizations/cloudfront.pyÚ<lambda>+   ó    ÿzregister.<locals>.<lambda>c                 [   r   )Núdefault-root-object)r   ÚCreateDefaultRootObjectr   r   r   r   r   /   r   ztop-level-args-parsedÚ
cloudfront)Ú	unique_idz4operation-args-parsed.cloudfront.update-distributionz6building-argument-table.cloudfront.update-distributionc                    s   |   dtˆ | d�¡S )Nr   )Úcontextr   )r   ÚUpdateDefaultRootObjectr   ©r   r   r   r   ;   s
    ÿÿ)ÚregisterÚ	_add_signÚ
_add_pathsr   Úupdate)Úevent_handlerr   r   r   r      sJ   ÿþþþþþÿÿþ
þr   Úclic                 C   s   d| t t ¡ ƒt dd¡f S )Nz%s-%s-%sé   i@B )ÚintÚtimeÚrandomÚrandint©Úprefixr   r   r   Úunique_string@   s   r+   c                 K   s   d| d _ tƒ | d< d S )NFzinvalidation-batchr   )ÚrequiredÚPathsArgumentr   r   r   r   r    D   s   
r    c                       ó$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )r-   c                    s   d}t t| ƒjdd|d� d S )NzlThe space-separated paths to be invalidated. Note: --invalidation-batch and --paths are mututally exclusive.r   ú+)ÚnargsÚ	help_text)Úsuperr-   Ú__init__)ÚselfÚdoc©Ú	__class__r   r   r3   K   s   ÿzPathsArgument.__init__c                 C   s*   |d urt ƒ t|ƒ|dœdœ|d< d S d S )N©ÚQuantityÚItems)ÚCallerReferenceÚPathsÚInvalidationBatch)r+   Úlen©r4   Ú
parametersÚvaluer   r   r   Úadd_to_paramsR   s
   þÿzPathsArgument.add_to_params©Ú__name__Ú
__module__Ú__qualname__r3   rB   Ú__classcell__r   r   r6   r   r-   I   s    r-   c                       s,   e Zd ZdZ	d‡ fdd„	Zdd„ Z‡  ZS )	ÚExclusiveArgumentz2%s This argument and --%s are mututally exclusive.údistribution-configÚ c                    s,   d|| _ tt| ƒj|| j||f d� d S )NF©r1   )r,   r2   rH   r3   ÚDOC)r4   Únamer   Úexclusive_tor1   r6   r   r   r3   ]   s   


ÿzExclusiveArgument.__init__c                 C   s4   t ƒ dg dœddddidœdddœd	dd
œdddœS )Nr   r8   ÚplaceholderFÚForwardÚnone)ÚQueryStringÚCookies)ÚEnabledr9   z	allow-all)ÚTargetOriginIdÚForwardedValuesÚTrustedSignersÚViewerProtocolPolicyÚMinTTLTrJ   )r;   ÚOriginsÚDefaultCacheBehaviorrT   ÚComment)r+   )r4   r   r   r   Údistribution_config_templatec   s   þþõïz.ExclusiveArgument.distribution_config_template)rI   rJ   )rD   rE   rF   rL   r3   r]   rG   r   r   r6   r   rH   Z   s
    ÿrH   c                       r.   )r   c                    s   t t| ƒjd|dd� d S )Nr   z The domain name for your origin.rK   )r2   r   r3   )r4   r   r6   r   r   r3   z   s   

þzOriginDomainName.__init__c                 C   s†   |d u rd S |  d|  ¡ ¡ t|d�}||ddœ}|d  d¡r'ddi|d< nd	d
ddœ|d< d|gdœ|d d< ||d d d< d S )NÚDistributionConfigr)   rJ   )ÚIdÚ
DomainNameÚ
OriginPathr`   z.s3.amazonaws.comÚOriginAccessIdentityÚS3OriginConfigéP   i»  z	http-only)ÚHTTPPortÚ	HTTPSPortÚOriginProtocolPolicyÚCustomOriginConfigr$   r8   rZ   r[   rU   )Ú
setdefaultr]   r+   Úendswith)r4   r@   rA   Ú	origin_idÚitemr   r   r   rB      s$   ÿ

þÿ
ÿÿzOriginDomainName.add_to_paramsrC   r   r   r6   r   r   y   s    r   c                       s&   e Zd Zd‡ fdd„	Zdd„ Z‡  ZS )r   rJ   c                    s   t t| ƒjd||p
dd� d S )Nr   zvThe object that you want CloudFront to return (for example, index.html) when a viewer request points to your root URL.rK   )r2   r   r3   )r4   r   r1   r6   r   r   r3   –   s   

þz CreateDefaultRootObject.__init__c                 C   s,   |d ur|  d|  ¡ ¡ ||d d< d S d S )Nr^   ÚDefaultRootObject)ri   r]   r?   r   r   r   rB   œ   s   ÿýz%CreateDefaultRootObject.add_to_params)rJ   rC   r   r   r6   r   r   •   s    r   c                       r.   )r   c                    s   t t| ƒj|dd� || _d S )NzÛThe object that you want CloudFront to return (for example, index.html) when a viewer request points to your root URL. CLI will automatically make a get-distribution-config call to load and preserve your other settings.rK   )r2   r   r3   r   )r4   r   r   r6   r   r   r3   ¤   s
   
þ
z UpdateDefaultRootObject.__init__c                 C   st   |d ur8| j d jd| j d j| j d j| j d jd�}|j|d d�}|d |d< |d	 |d	< ||d	 d
< d S d S )NÚsessionr   Úparsed_args)Úregion_nameÚendpoint_urlÚverifyr_   )r_   ÚETagÚIfMatchr^   rm   )r   Úcreate_clientÚregionrq   Ú
verify_sslÚget_distribution_config)r4   r@   rA   ÚclientÚresponser   r   r   rB   ­   s   



ü÷z%UpdateDefaultRootObject.add_to_paramsrC   r   r   r6   r   r   £   s    	r   c                 K   s   t |ƒ| d< d S )NÚsign)ÚSignCommand)Úcommand_tablern   r   r   r   r   r   º   ó   r   c                   @   sf   e Zd ZdZdZdZdddddœddd	d
œdddd
œddde d
œdde dœdddœgZdd„ ZdS )r|   r{   zSign a given url.aO  Supported formats include:
        YYYY-MM-DD (which means 0AM UTC of that day),
        YYYY-MM-DDThh:mm:ss (with default timezone as UTC),
        YYYY-MM-DDThh:mm:ss+hh:mm or YYYY-MM-DDThh:mm:ss-hh:mm (with offset),
        or EpochTime (which always means UTC).
        Do NOT use YYYYMMDD, because it will be treated as EpochTime.ÚurlTzThe URL to be signed)rM   Úno_paramfiler,   r1   zkey-pair-idz_The active CloudFront key pair Id for the key pair that you're using to generate the signature.)rM   r,   r1   zprivate-keyz#file://path/to/your/private-key.pemzdate-less-thanz*The expiration date and time for the URL. zdate-greater-thanz-An optional start date and time for the URL. )rM   r1   z
ip-addressztAn optional IP address or IP address range to allow client making the GET request from. Format: x.x.x.x/x or x.x.x.xc                 C   s”   t |jt|jƒjƒ}t|jƒ}|j}|d urt|ƒ}|d us#|jd ur<|j	|j
|||jd�}tj |j|j
|d�¡ dS tj |j|j
|d�¡ dS )N)Údate_greater_thanÚ
ip_address)Úpolicy)Údate_less_thanr   )r   Úkey_pair_idÚ	RSASignerÚprivate_keyr{   r   r„   r�   r‚   Úbuild_policyr   ÚsysÚstdoutÚwriteÚgenerate_presigned_url)r4   ÚargsÚparsed_globalsÚsignerr„   r�   rƒ   r   r   r   Ú	_run_mainì   s(   ÿ
þ
ÿ
þÿzSignCommand._run_mainN)rD   rE   rF   ÚNAMEÚDESCRIPTIONÚDATE_FORMATÚ	ARG_TABLEr�   r   r   r   r   r|   ¾   s8    üüýýýýã%r|   c                   @   s   e Zd Zdd„ Zdd„ ZdS )r†   c                 C   s   t j | d¡¡| _d S )NÚutf8)ÚrsaÚ
PrivateKeyÚ
load_pkcs1ÚencodeÚpriv_key)r4   r‡   r   r   r   r3      s   zRSASigner.__init__c                 C   s   t  || jd¡S )NzSHA-1)r–   r{   rš   )r4   Úmessager   r   r   r{     r~   zRSASigner.signN)rD   rE   rF   r3   r{   r   r   r   r   r†   ÿ   s    r†   )r#   )r‰   r&   r'   r–   Úbotocore.utilsr   Úbotocore.signersr   Úawscli.argumentsr   Úawscli.customizations.utilsr   Úawscli.customizations.commandsr   r   r+   r    r-   rH   r   r   r   r   r|   Úobjectr†   r   r   r   r   Ú<module>   s(   
&A