Xc@sddlZddlZddlZddlZddlmZddlZddlZddlZddl Zddl Z ddl Z ddl m Z ddlmZdejjfdYZdejjfdYZd Zd ZdS( iN(tArg(t Euca2ools(tAWSErrortS3cBsYeZdZdZdZdZeddddd d gZd Zd Z d Z RS(ts3sObject storage servicetEUCA_DEFAULT_REGIONtAWS_DEFAULT_REGIONtS3_URLs-Us--urltmetavartURLthelps#object storage service endpoint URLcCst|dS(N(R(tselftresponse((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pythandle_http_error5sc Cs2tjjjj|}|js@tjjjjd|}ntjjjj|j}|j||\}}|r|j||fS|j j d}x{|j D]m\}}tjjjj|} |j|| \}}|r|j j dd|} | p |||fSqWt dj|dS(s Given a URL, try to return its associated region, bucket, and key names based on this object's endpoint info as well as all S3 endpoints given in the configuration. shttp://ss3-urltnametregionsgURL '{0}' matches no known object storage endpoints. Supply one via the command line or configuration.N(tsixtmovesturllibtparseturlparsetschemetendpointt_S3__match_patht region_nametconfigtget_all_region_optionstitemstget_region_optiont ValueErrortformat( R turlt parsed_urltparsed_own_urltbuckettkeyts3_urlstsectiontconf_urltparsed_conf_urlR((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytresolve_url_to_location9s"   c Csg|j|jkr|j}|jds7|d7}n|jj|dd}|jdd\}}|jjd|j|j|j|j|j|j|| n|jj|jrQ|jjd|jdd}|jd}|jj dr |jd}n |j}|jjd|j|j|j|j|j|j|| n d}d}||fS(Nt/is/URL path match: %s://%s%s + %s://%s%s -> %s/%st.is0URL vhost match: %s://%s%s + %s://%s%s -> %s/%s( tnetloctpathtendswithtsplittlogtdebugRtrsplittlstript startswithtNone(R tgiventservicet service_pathtcpathR"R#((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyt __match_pathTs.        (RR( t__name__t __module__tNAMEt DESCRIPTIONt REGION_ENVVARt URL_ENVVARRtARGSR R(R(((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyR+s   t S3RequestcBsPeZeZeZejjj Z dZ dZ dZ dZdZRS(cKs#tjjj||d|_dS(Ni(trequestbuildertrequestt BaseRequestt__init__tredirects_left(R tkwargs((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyREwscCsdtjjj||jr`|jjdtjjj j |j}|j||_ndS(Nsswitching to HmacV4Auth( RBRCRDt configuret_S3Request__should_use_sigv4R/tinfotauthtawst HmacV4Autht from_other(R RK((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyRH{s   cCs|jj|jjdS(Nss3-force-sigv4(Rtconvert_to_boolR(R ((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyt__should_use_sigv4s c Cs|j|jr@tjjjj|jd|dd}n!tjjjj|jd|}|jj d|j d|j d|j d|S(sm Get a pre-signed URL for this request that expires after a given number of seconds. ttimeoutt payload_hashsUNSIGNED-PAYLOADtmethodR,tparamsRK( t preprocessRIRBRKRLtQueryHmacV4AuthRNtQueryHmacV1AuthR6tget_request_urlRSR,RT(R RQRK((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytget_presigned_url2s   cCsG|jdkr-|jjdditd6|jj|jjditd6|jjd|jjdd}d|jkr|d j|jd7}n|jj|d td |jkrd j|jd }nd }t j j j j |jj}dj||j}tjj|ntjjj||SdS(Ni-s-- response content -- textratappends-- end of response content --sresult: inter-region redirects%Aborting due to inter-region redirecttEndpoints to {0}texc_infotBuckets"{0}" tsuBucket {0}is not available from endpoint "{1}". Ensure the object storage service URL matches the bucket's location.(t status_codeR/R0tTrueR ttextterrortelementsRRRRRRR6RR+RBt exceptionst ClientErrorRCRDthandle_server_error(R terrtmsgR"tparsed((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyRgs&# (R:R;RtSUITERt SERVICE_CLASSRBRKRLt HmacV1Autht AUTH_CLASSRERHRIRYRg(((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyRArs   cCst|dkr!tdnt|dkrBtdnx@|D]8}|tjtjdkrItdj|qIqIWdS(Nisname is too shortisname is too longs.-_sinvalid character '{0}'(tlenRtstringt ascii_letterstdigitsR(R"tchar((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytvalidate_generic_bucket_names cCst|dkr!tdnt|dkrBtdn|jdr`tdn|jdr~tdn|jd}x|D]}t|dkrtd nx@|D]8}|tjtjd krtd j|qqW|dtjtjkr4td j|dn|d tjtjkrtdj|d qqWt|dkry*g|jdD]}t |^qWntk rqXtdndS(Nisname is too shorti?sname is too longR*sname may not start with '.'sname may not end with '.'isname may not contain '..'t-sinvalid character '{0}'s3character '{0}' may not begin part of a bucket nameis1character '{0}' may not end part of a bucket nameis-name must not be formatted like an IP address( RoRR3R-R.Rptascii_lowercaseRrRtint(R"tlabelstlabelRstchunk((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytvalidate_dns_bucket_names6    * (tosRptsysRRBRtrequestbuilder.auth.awstrequestbuilder.exceptionstrequestbuilder.requesttrequestbuilder.servicetrequestsRteuca2ools.commandsRteuca2ools.exceptionsRR6t BaseServiceRRCRDRARtR{(((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyts          GC