Pull request #49: Add exists to storage
Merge in RR/pyinfra from add-exists-to-storage to master
Squashed commit of the following:
commit 48d5e1c9e103702bfebfc115e811576514e115c3
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Aug 12 13:32:40 2022 +0200
refactor
commit 711d2c8dbf7c78e26133e3ea3a57670fe829059b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Aug 12 11:45:42 2022 +0200
add method to check if objects exists for azure and s3
This commit is contained in:
parent
0f6512df54
commit
be82114f83
@ -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}'...")
|
||||
|
||||
@ -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:
|
||||
return False
|
||||
|
||||
@retry(tries=3, delay=5, jitter=(1, 3))
|
||||
def get_object(self, bucket_name, object_name):
|
||||
logger.debug(f"Downloading '{object_name}'...")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user