refactoring, better logging

This commit is contained in:
Matthias Bisping 2022-02-24 07:37:40 +01:00
parent 9b56870414
commit f4e48e816f

View File

@ -7,6 +7,10 @@ from retry import retry
from pyinfra.storage.adapters.adapter import StorageAdapter
logger = logging.getLogger(__name__)
logging.getLogger("azure").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
def _retry(exceptions=Exception):
@ -33,6 +37,7 @@ class AzureStorageAdapter(StorageAdapter):
return container_client if container_client.exists() else self.__client.create_container(container_name)
def put(self, bucket_name, object_name, data):
logger.debug(f"Uploading {object_name}")
container_client = self.__provide_container_client(bucket_name)
blob_client = container_client.get_blob_client(object_name)
blob_client.upload_blob(data, overwrite=True)
@ -46,14 +51,15 @@ class AzureStorageAdapter(StorageAdapter):
def get_all(self, bucket_name):
container_client = self.__provide_container_client(bucket_name)
for blob in container_client.list_blobs(bucket_name):
blobs = container_client.list_blobs(bucket_name)
for blob in blobs:
blob_client = container_client.get_blob_client(blob)
blob_data = blob_client.download_blob()
yield blob_data
@_retry(ResourceExistsError)
def purge(self, bucket_name):
logging.debug(f"Purging Azure container '{bucket_name}'")
logger.debug(f"Purging Azure container '{bucket_name}'")
container_client = self.__client.get_container_client(bucket_name)
blobs = container_client.list_blobs()
container_client.delete_blobs(*blobs)