FRTc@s4ddlZddlZddlZddlmZmZddlmZddlm Z m Z ddl m Z m Z ddlmZddlmZmZddlmZd efd YZd efd YZd efdYZdefdYZdefdYZdefdYZdS(iN(tsixtjson(tOriginAccessIdentity(tObjecttStreamingObject(tActiveTrustedSignerstTrustedSigners(t LoggingInfo(tS3Origint CustomOrigin(tACLtDistributionConfigc BsPeZddeddddddd ZdZdZdZdZRS(tc Cs||_||_||_|r-||_nttj|_g|_|r]||_n||_||_ | |_ ||_ dS(s+ :param origin: Origin information to associate with the distribution. If your distribution will use an Amazon S3 origin, then this should be an S3Origin object. If your distribution will use a custom origin (non Amazon S3), then this should be a CustomOrigin object. :type origin: :class:`boto.cloudfront.origin.S3Origin` or :class:`boto.cloudfront.origin.CustomOrigin` :param enabled: Whether the distribution is enabled to accept end user requests for content. :type enabled: bool :param caller_reference: A unique number that ensures the request can't be replayed. If no caller_reference is provided, boto will generate a type 4 UUID for use as the caller reference. :type enabled: str :param cnames: A CNAME alias you want to associate with this distribution. You can have up to 10 CNAME aliases per distribution. :type enabled: array of str :param comment: Any comments you want to include about the distribution. :type comment: str :param trusted_signers: Specifies any AWS accounts you want to permit to create signed URLs for private content. If you want the distribution to use signed URLs, this should contain a TrustedSigners object; if you want the distribution to use basic URLs, leave this None. :type trusted_signers: :class`boto.cloudfront.signers.TrustedSigners` :param default_root_object: Designates a default root object. Only include a DefaultRootObject value if you are going to assign a default root object for the distribution. :type comment: str :param logging: Controls whether access logs are written for the distribution. If you want to turn on access logs, this should contain a LoggingInfo object; otherwise it should contain None. :type logging: :class`boto.cloudfront.logging.LoggingInfo` N( t connectiontorigintenabledtcaller_referencetstrtuuidtuuid4tcnamestcommentttrusted_signerstloggingtdefault_root_object( tselfR RRRRRRRR((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt__init__#s8         cCs d|jS(NsDistributionConfig:%s(R(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt__repr__jscCsd}|d7}|jr/||jj7}n|d|j7}x|jD]}|d|7}qJW|jr|d|j7}n|d7}|jr|d7}n |d7}|d 7}|jr|d 7}x8|jD]-}|d kr|d 7}q|d |7}qW|d7}n|jrV|d7}|d|jj7}|d|jj 7}|d7}n|j ry|j }|d|7}n|d7}|S(Ns' sM s( %s s %s s %s s ttruetfalses s tSelfs s* %s s s s %s s %s s s*%s s ( Rtto_xmlRRRRRRtbuckettprefixR(Rtstcnametsignertdro((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRms>                   cCs|dkrt|_|jS|dkr>t|_|jS|dkr]t|_|jS|dkr|t|_|jSdSdS(NRtLoggingRR (RRRRRRR tNone(RtnametattrsR ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt startElements        cCs|dkr|jj|n|dkr7||_nv|dkrm|jdkrat|_qt|_n@|dkr||_n(|dkr||_nt |||dS(NtCNAMEtCommenttEnabledRtCallerReferencetDefaultRootObject( RtappendRtlowertTrueRtFalseRRtsetattr(RR(tvalueR ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt endElements          N( t__name__t __module__R'R3RRRR*R6(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR !s   D  # tStreamingDistributionConfigc Bs2eZddeddddddZdZRS(R c CsGtt|jd|d|d|d|d|d|d|d|dS( NR RRRRRRR(tsuperR9R( RR RRRRRRR((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRs   cCsdd}|d7}|jr/||jj7}n|d|j7}x|jD]}|d|7}qJW|jr|d|j7}n|d7}|jr|d7}n |d7}|d 7}|jr|d 7}x8|jD]-}|d kr|d 7}q|d |7}qW|d7}n|jrV|d7}|d|jj7}|d|jj 7}|d7}n|d7}|S(Ns' sV s( %s s %s s %s s RRs s Rs s* %s s s s %s s %s s s ( RRRRRRRRR R!(RR"R#R$((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRs8                 N(R7R8R'R3RR(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR9s  tDistributionSummaryc BsPeZdddddddded ZdZdZdZdZRS(R c Cs||_||_||_||_||_||_| |_g|_|ra|jj|n||_ d|_ d|_ t |_dS(N(R t domain_nametidtlast_modified_timetstatusRRRR0RR'RtetagR3t streaming( RR R<R=R>R?RR#RR((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRs           cCs d|jS(NsDistributionSummary:%s(R<(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRscCsa|dkrt|_|jS|dkr>t|_|jS|dkr]t|_|jSdS(NRRR (RRRRR R'(RR(R)R ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR*s      cCs|dkr||_n|dkr0||_n|dkrH||_n|dkr`||_n|dkrx||_n|dkr|jj|nv|dkr||_n^|dkr|jd krt |_ q t |_ n(|d krt |_ nt |||dS( NtIdtStatustLastModifiedTimet DomainNametOriginR+R,R-RtStreamingDistributionSummary(R=R?R>R<RRR0RR1R2RR3RAR4(RR(R5R ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR6s*                  cCs|jj|jS(N(R tget_distribution_infoR=(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytget_distributionsN( R7R8R'R3RRR*R6RI(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR;s    RGcBseZdZRS(cCs|jj|jS(N(R tget_streaming_distribution_infoR=(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRIs(R7R8RI(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRGst DistributioncBs%eZdddddddZdZdZdZddddZdZdZ dZ d Z d Z e d Ze d Zded ZdddddddZdddddddZedZeddddZedddZedZRS(R cCsg||_||_||_||_||_||_d|_d|_d|_ d|_ t |_ dS(Ni( R tconfigR<R=R>R?t in_progress_invalidation_batchesR'tactive_signersR@t_bucketRt _object_class(RR RLR<R=R>R?((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR"s          cCs d|jS(NsDistribution:%s(R<(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR0scCsF|dkrt|_|jS|dkr>t|_|jSdSdS(NR R(R RLRRNR'(RR(R)R ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR*3s    cCs|dkr||_nv|dkr0||_n^|dkrH||_nF|dkrft||_n(|dkr~||_nt|||dS(NRBRDRCtInProgressInvalidationBatchesRE(R=R>R?tintRMR<R4(RR(R5R ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR6=s         c Cst|j|jj|jj|jj|jj|jj|jj|jj }|dk rf||_n|dk r~||_n|dk r||_n|jj |j |j ||_ ||_t|_dS(s Update the configuration of the Distribution. The only values of the DistributionConfig that can be directly updated are: * CNAMES * Comment * Whether the Distribution is enabled or not Any changes to the ``trusted_signers`` or ``origin`` properties of this distribution's current config object will also be included in the update. Therefore, to set the origin access identity for this distribution, set ``Distribution.config.origin.origin_access_identity`` before calling this update method. :type enabled: bool :param enabled: Whether the Distribution is active or not. :type cnames: list of str :param cnames: The DNS CNAME's associated with this Distribution. Maximum of 10 values. :type comment: str or unicode :param comment: The comment associated with the Distribution. N(R R RLRRRRRRRR'tset_distribution_configR=R@RRP(RRRRt new_config((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytupdateKs       ! cCs|jdtdS(se Activate the Distribution. A convenience wrapper around the update method. RN(RUR2(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytenabletscCs|jdtdS(sg Deactivate the Distribution. A convenience wrapper around the update method. RN(RUR3(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytdisable{scCs|jj|j|jdS(s Delete this CloudFront Distribution. The content associated with the Distribution is not deleted from the underlying Origin bucket in S3. N(R tdelete_distributionR=R@(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytdeletesc Cst|jjtr|js|jjj}|jdd}ddlm}||j j |j j d|j j d|j j d|j jd|j j}|j||_||j_|jj|jn|jStd dS( Ns.s3.amazonaws.comR i(t S3Connectiontproxyt proxy_portt proxy_usert proxy_passs%Unable to get_objects on CustomOrigin(t isinstanceRLRRROtdns_nametreplacetboto.s3.connectionRZR taws_access_key_idtaws_secret_access_keyR[R\R]R^t get_buckett distributiont set_key_classRPtNotImplementedError(Rtbucket_dns_namet bucket_nameRZts3((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt _get_buckets        cCs4|j}g}x|D]}|j|qW|S(s Return a list of all content objects in this distribution. :rtype: list of :class:`boto.cloudfront.object.Object` :return: The content objects (RlR0(RR tobjstkey((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt get_objectss   cCst|jjtr|jjjr|jjjjdd}|jj|}|j}|rst |_ n|j j d|j |j |q|jdndS(ss Sets the S3 ACL grants for the given object to the appropriate value based on the type of Distribution. If the Distribution is serving private content the ACL will be set to include the Origin Access Identity associated with the Distribution. If the Distribution is serving public content the content will be set up with "public-read". :type object: :class:`boto.cloudfront.object.Object` :param enabled: The Object whose ACL is being set :type replace: bool :param replace: If False, the Origin Access Identity will be appended to the existing ACL for the object. If True, the ACL for the object will be completely replaced with one that grants READ permission to the Origin Access Identity. t/itREADs public-readN(R_RLRRtorigin_access_identitytsplitR tget_origin_access_identity_infotget_aclR tacltadd_user_grantt s3_user_idtset_acltset_canned_acl(RtobjectRaR=toaitpolicy((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytset_permissionss cCs1|j}x|D]}|j||qWdS(s Sets the S3 ACL grants for all objects in the Distribution to the appropriate value based on the type of Distribution. :type replace: bool :param replace: If False, the Origin Access Identity will be appended to the existing ACL for the object. If True, the ACL for the object will be completely replaced with one that grants READ permission to the Origin Access Identity. N(RlR~(RRaR Rn((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytset_permissions_alls  cCsx|jjjrd}nd}|j}|j|}|j|d|d||jjjrt|j||n|S(s  Adds a new content object to the Distribution. The content for the object will be copied to a new Key in the S3 Bucket and the permissions will be set appropriately for the type of Distribution. :type name: str or unicode :param name: The name or key of the new object. :type content: file-like object :param content: A file-like object that contains the content for the new object. :type headers: dict :param headers: A dictionary containing additional headers you would like associated with the new object in S3. :rtype: :class:`boto.cloudfront.object.Object` :return: The newly created object. tprivates public-readtheadersR}(RLRRrRltnew_keytset_contents_from_fileR~(RR(tcontentRRaR}R R{((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyt add_objects  c Cs|jd|d|d|d|d|d|d|d|} d |krQd } nd } g} xJd d d dgD]6} | | krpd| | | f} | j| qpqpW|| d j| }|S(s Creates a signed CloudFront URL that is only valid within the specified parameters. :type url: str :param url: The URL of the protected object. :type keypair_id: str :param keypair_id: The keypair ID of the Amazon KeyPair used to sign theURL. This ID MUST correspond to the private key specified with private_key_file or private_key_string. :type expire_time: int :param expire_time: The expiry time of the URL. If provided, the URL will expire after the time has passed. If not provided the URL will never expire. Format is a unix epoch. Use time.time() + duration_in_sec. :type valid_after_time: int :param valid_after_time: If provided, the URL will not be valid until after valid_after_time. Format is a unix epoch. Use time.time() + secs_until_valid. :type ip_address: str :param ip_address: If provided, only allows access from the specified IP address. Use '192.168.0.10' for a single IP or use '192.168.0.0/24' CIDR notation for a subnet. :type policy_url: str :param policy_url: If provided, allows the signature to contain wildcard globs in the URL. For example, you could provide: 'http://example.com/media/\*' and the policy and signature would allow access to all contents of the media subdirectory. If not specified, only allow access to the exact url provided in 'url'. :type private_key_file: str or file object. :param private_key_file: If provided, contains the filename of the private key file used for signing or an open file object containing the private key contents. Only one of private_key_file or private_key_string can be provided. :type private_key_string: str :param private_key_string: If provided, contains the private key string used for signing. Only one of private_key_file or private_key_string can be provided. :rtype: str :return: The signed URL. turlt keypair_idt expire_timetvalid_after_timet ip_addresst policy_urltprivate_key_filetprivate_key_stringt?t&tExpirestPolicyt Signatures Key-Pair-Ids%s=%s(t_create_signing_paramsR0tjoin(RRRRRRRRRtparamstseptsigned_url_paramsRntparamt signed_url((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pytcreate_signed_urls8       c  Csi} |rF| rF| rF| rF|j||} t|| dYou must specify one of private_key_file or private_key_stringtrsSHA-1(trsat ImportErrorRht ValueErrorR'R_Rt string_typestopentreadt PrivateKeyt load_pkcs1tsignR(tmessageRRRt file_handlet private_keyR((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRs    cCsItj|}|jdd}|jdd}|jdd}|S(sd Base64 encodes a string using the URL-safe characters specified by Amazon. t+t-t=t_Rpt~(tbase64t b64encodeRa(tmsgt msg_base64((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRs N(R7R8R'RRR*R6RURVRWRYRlRoR3R~RR2RRRt staticmethodRRRR(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRK s4   )     "I tStreamingDistributioncBsGeZdddddddZdZddddZdZRS(R cCs2tt|j||||||t|_dS(N(R:RRRRP(RR RLR<R=R>R?((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRscCs?|dkrt|_|jStt|j|||SdS(NR9(R9RLR:RR*(RR(R)R ((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyR*s   cCst|j|jj|jj|jj|jj|jj|jj}|dk r]||_n|dk ru||_n|dk r||_n|jj |j |j ||_ ||_t |_dS(s Update the configuration of the StreamingDistribution. The only values of the StreamingDistributionConfig that can be directly updated are: * CNAMES * Comment * Whether the Distribution is enabled or not Any changes to the ``trusted_signers`` or ``origin`` properties of this distribution's current config object will also be included in the update. Therefore, to set the origin access identity for this distribution, set ``StreamingDistribution.config.origin.origin_access_identity`` before calling this update method. :type enabled: bool :param enabled: Whether the StreamingDistribution is active or not. :type cnames: list of str :param cnames: The DNS CNAME's associated with this Distribution. Maximum of 10 values. :type comment: str or unicode :param comment: The comment associated with the Distribution. N(R9R RLRRRRRRR't!set_streaming_distribution_configR=R@RRP(RRRRRT((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRUs$              cCs|jj|j|jdS(N(R tdelete_streaming_distributionR=R@(R((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRYsN(R7R8R'RR*RURY(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyRs   .(RRRt boto.compatRRtboto.cloudfront.identityRtboto.cloudfront.objectRRtboto.cloudfront.signersRRtboto.cloudfront.loggingRtboto.cloudfront.originRR t boto.s3.aclR R{R R9R;RGRKR(((sI/opt/freeware/lib/python2.7/site-packages/boto/cloudfront/distribution.pyts   +?