o @a%@s~ddlZddlmZddlmZddlmZmZddlmZddlmZGdddej j Z Gd d d e Z ej d e dS) N)config)log)FatalBackendExceptionBackendException)util)progressc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)S3Boto3Backenda Backend for Amazon's Simple Storage System, (aka Amazon S3), though the use of the boto3 module. (See https://boto3.amazonaws.com/v1/documentation/api/latest/index.html for information on boto3.) Pursuant to Amazon's announced deprecation of path style S3 access, this backend only supports virtual host style bucket URIs. See the man page for full details. To make use of this backend, you must provide AWS credentials. This may be done in several ways: through the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, by the ~/.aws/credentials file, by the ~/.aws/config file, or by using the boto2 style ~/.boto or /etc/boto.cfg files. cCstjj||dd|jdD}|r|d|_ntd|r+dd ||_ nd|_ ||_ tj ||_ d|_d|_t|_dS)NcSsg|]}|dkr|qS)).0xr r E/usr/lib/python3/dist-packages/duplicity/backends/s3_boto3_backend.py Esz+S3Boto3Backend.__init__../rzS3 requires a bucket name.z%s/r ) duplicitybackendBackend__init__pathsplitpop bucket_namerjoin key_prefix parsed_urlstrip_auth_from_url straight_urls3bucketUploadProgressTrackertracker)selfrurl_path_partsr r r r?s zS3Boto3Backend.__init__c Csddl}ddl}ddlm}d|_|jdtjtjd|_ z |j j j j |j dWn%|jjyM}z|jdd}|dkrHtd |j tjjd d}~ww|j |j |_dS) Nr) ClientErrorr) region_name endpoint_url)BucketErrorCode404zS3 bucket "%s" does not existcode)boto3botocorebotocore.exceptionsr#rresourcers3_region_names3_endpoint_urlrmetaclient head_bucketr exceptionsresponserr ErrorCodebackend_not_foundr&)r!r,r-r#bce error_coder r r reset_connectionVs"  zS3Boto3Backend.reset_connectionc Cs,ddlm}|js |t|}|j|}tjrd}n"tj r#d}ntj r)d}ntj r3d|vr3d}n tj r=d|vr=d}nd }d |i}tj rKd |d <n!tjrltjdur[td tjjdd|d <tj|d<tjrltj|d<|tjtjd}|j}td|j||f|j|jj|j|j|j||ddS)Nr)TransferConfigREDUCED_REDUNDANCY STANDARD_IA ONEZONE_IAmanifestGLACIER DEEP_ARCHIVESTANDARD StorageClassAES256ServerSideEncryptionzOS3 USE SSE KMS was requested, but key id not provided require (--s3-kms-key-id)r*zaws:kms SSEKMSKeyIdGrantFullControl)multipart_chunksizemultipart_thresholdzUploading %s/%s to %s Storage)CallbackConfig ExtraArgs)boto3.s3.transferr<rr;rfsdecoderr s3_use_rrs s3_use_ias3_use_onezone_ias3_use_glaciers3_use_deep_archive s3_use_sses3_use_sse_kms s3_kms_key_idrrr7 s3_kms_no_id s3_kms_grants3_multipart_chunk_sizer InforObjectrname upload_fileuc_name progress_cb) r!local_source_pathremote_filenamer<key storage_class extra_argstransfer_configr r r r _putjsL        zS3Boto3Backend._putcCs@|js|t|}|j|}|j|jj||j dSN) rr;rrOrr\rr] download_filer_)r!rb local_pathrcr r r _gets   zS3Boto3Backend._getc Csz|js|g}|jjj|jdD](}z|j|jdd}|t |t d|j |fWqty:Yqw|S)N)Prefixr z Listed %s/%s)rr;robjectsfilterrrcreplaceappendrfsencoderDebugrAttributeError)r! filename_listobjfilenamer r r _lists zS3Boto3Backend._listcCs<|js|t|}|j|}|j|jj|dSrh) rr;rrOrr\rr]delete)r!rbrcr r r _deletes   zS3Boto3Backend._deletec Cs|js|ddl}t|}|j|}d}z|j|jj|}| |j }Wd|iS|j j yN}z|j dddkr@nWYd}~d|iSd}~ww)Nrr'r(r)size)rr;r-rrOrr\rr]loadcontent_lengthr5r#r6)r!rbr-rcr~s3_objr9r r r _querys&   zS3Boto3Backend._queryN) __name__ __module__ __qualname____doc__rr;rgrkrxrzrr r r r r-s3 rc@seZdZddZddZdS)rcCs d|_dSNr) total_bytes)r!r r r rs zUploadProgressTracker.__init__cCs |j|7_t|jddSr)rrreport_transfer)r!fresh_byte_countr r r r`sz!UploadProgressTracker.progress_cbN)rrrrr`r r r r rs rzboto3+s3)duplicity.backendrrrduplicity.errorsrrrrrrrobjectrregister_backendr r r r s    $