o `@sddlmZddlZddlZddlZddlmZddlmZddlm Z ddl m Z e dZ dd ZGd d d ejjZejd edS) )strN)config)log)BackendException)fsdecodez)^[a-z0-9](?!.*--)[a-z0-9-]{1,61}[a-z0-9]$cCst|}|duS)z Check, whether the given name conforms to the rules as defined in https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata for valid names. N)_VALID_CONTAINER_NAME_REmatch)namerr A/usr/lib/python3/dist-packages/duplicity/backends/azurebackend.py_is_valid_container_name$s r c@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS) AzureBackendz0 Backend for Azure Blob Storage Service c Cstjj||zddl}ddl}ddl}ddlm}Wnty0}zt dt |d}~ww|j d|_ t|j sAt ddtjvrJt di}tjrTtj|d<tjr\tj|d <tjrdtj|d <tjd}|j|dfi||_|dS) Nr)BlobServiceClientz{Azure backend requires Microsoft Azure Storage SDK for Python (https://pypi.org/project/azure-storage-blob/). Exception: %s/z*Invalid Azure Storage Blob container name.AZURE_CONNECTION_STRINGz5AZURE_CONNECTION_STRING environment variable not set.timeoutmax_single_put_sizemax_block_size) duplicitybackendBackend__init__azure azure.storageazure.storage.blobr ImportErrorrrpathlstripcontainer_namer osenvironrrazure_max_single_put_sizeazure_max_block_sizefrom_connection_string blob_service_get_or_create_container)self parsed_urlrrekwargsconn_strr r r r2s6       zAzureBackend.__init__c Csddlm}z|j|j|_|jWdS|y YdStyE}zt dt |j  dddtj jWYd}~dSd}~ww)Nr)ResourceExistsErrorz$Could not create Azure container: %s )azure.core.exceptionsr+r$get_container_clientr containercreate_container Exceptionr FatalErrorrmessagesplit ErrorCodeconnection_failed)r&r+r(r r r r%Ws  z%AzureBackend._get_or_create_containercCsjt|}i}tjrtj|d<|d}|jj||fi|Wdn1s)wY||dS)Nmax_concurrencyrb)rrazure_max_connectionsopenr0 upload_blob _set_tier)r& source_pathremote_filenamer)datar r r _putds  zAzureBackend._putcCs"tjdur|jtj|dSdSN)razure_blob_tierr0set_standard_blob_tier_blobs)r&r?r r r r=ps zAzureBackend._set_tiercCsJ|j|}|d}||WddS1swYdS)Nwb)r0 download_blobr;writereadall)r&r? local_pathblob download_filer r r _getts  "zAzureBackend._getcCs0g}|j}|D]}||q dd|DS)NcSsg|]}|jqSr )r ).0rJr r r sz&AzureBackend._list..)r0 list_blobsappend)r&blobs blob_listrJr r r _listzs   zAzureBackend._listcCs|jt|dSrB)r0 delete_blobr)r&filenamer r r _deleteszAzureBackend._deletecCs&|jt|}|}dt|jiS)Nsize)r0get_blob_clientrget_blob_propertiesintrW)r&rUclientpropr r r _queryszAzureBackend._querycCstjjSrB)rr6backend_not_found)r& operationr(r r r _error_codeszAzureBackend._error_codeN) __name__ __module__ __qualname____doc__rr%rAr=rLrSrVr]r`r r r r r .s%    r r)builtinsrrreduplicity.backendrrrduplicity.errorsrduplicity.utilrcompilerr rrr register_backendr r r r s       b