add method to check if objects exists for azure and s3
This commit is contained in:
parent
0f6512df54
commit
711d2c8dbf
@ -37,6 +37,11 @@ class AzureStorageAdapter(object):
|
|||||||
blob_client = container_client.get_blob_client(object_name)
|
blob_client = container_client.get_blob_client(object_name)
|
||||||
blob_client.upload_blob(data, overwrite=True)
|
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))
|
@retry(tries=3, delay=5, jitter=(1, 3))
|
||||||
def get_object(self, bucket_name, object_name):
|
def get_object(self, bucket_name, object_name):
|
||||||
logger.debug(f"Downloading '{object_name}'...")
|
logger.debug(f"Downloading '{object_name}'...")
|
||||||
|
|||||||
@ -42,6 +42,13 @@ class S3StorageAdapter(object):
|
|||||||
data = io.BytesIO(data)
|
data = io.BytesIO(data)
|
||||||
self._client.put_object(bucket_name, object_name, data, length=data.getbuffer().nbytes)
|
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))
|
@retry(tries=3, delay=5, jitter=(1, 3))
|
||||||
def get_object(self, bucket_name, object_name):
|
def get_object(self, bucket_name, object_name):
|
||||||
logger.debug(f"Downloading '{object_name}'...")
|
logger.debug(f"Downloading '{object_name}'...")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user