add method to check if objects exists for azure and s3

This commit is contained in:
Julius Unverfehrt 2022-08-12 11:45:42 +02:00
parent 0f6512df54
commit 711d2c8dbf
2 changed files with 12 additions and 0 deletions

View File

@ -37,6 +37,11 @@ class AzureStorageAdapter(object):
blob_client = container_client.get_blob_client(object_name)
blob_client.upload_blob(data, overwrite=True)
def exists(self, bucket_name, object_name):
container_client = self.__provide_container_client(bucket_name)
blob_client = container_client.get_blob_client(object_name)
return blob_client.exists()
@retry(tries=3, delay=5, jitter=(1, 3))
def get_object(self, bucket_name, object_name):
logger.debug(f"Downloading '{object_name}'...")

View File

@ -42,6 +42,13 @@ class S3StorageAdapter(object):
data = io.BytesIO(data)
self._client.put_object(bucket_name, object_name, data, length=data.getbuffer().nbytes)
def exists(self, bucket_name, object_name):
try:
self._client.stat_object(bucket_name, object_name)
return True
except Exception: # TODO: specify exception
return False
@retry(tries=3, delay=5, jitter=(1, 3))
def get_object(self, bucket_name, object_name):
logger.debug(f"Downloading '{object_name}'...")