Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to S3 Storage blob methods #448

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions adapta/storage/blob/s3_storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Optional, Callable, Type, Iterator, Dict, TypeVar, final
from datetime import timedelta
from boto3 import Session
from botocore.exceptions import ClientError

from adapta.security.clients import AwsClient
from adapta.storage.blob.base import StorageClient
Expand Down Expand Up @@ -90,7 +91,7 @@ def blob_exists(self, blob_path: DataPath) -> bool:
try:
self._s3_resource.meta.client.head_object(Bucket=s3_path.bucket, Key=s3_path.path)
return True
except StorageClientError:
except ClientError:
return False

def save_data_as_blob(
Expand Down Expand Up @@ -146,10 +147,10 @@ def list_blobs(
response = self._s3_resource.meta.client.list_objects(Bucket=s3_path.bucket, Prefix=s3_path.path)
if "Contents" not in response:
yield from iter([])

for blob in response["Contents"]:
if filter_predicate is None or filter_predicate(blob):
yield blob
else:
for blob in response["Contents"]:
if filter_predicate is None or filter_predicate(blob):
yield blob

def read_blobs(
self,
Expand Down Expand Up @@ -195,8 +196,8 @@ def download_blobs(
os.makedirs(os.path.dirname(local_file_path), exist_ok=True)
try:
self._s3_resource.meta.client.download_file(s3_path.bucket, blob.key, local_file_path)
except StorageClientError as error:
raise RuntimeError(f"Error downloading blob: {error}") from error
except ClientError as error:
raise StorageClientError(f"Error downloading blob: {error}") from error

def copy_blob(self, blob_path: DataPath, target_blob_path: DataPath, doze_period_ms: int = 0) -> None:
"""
Expand Down
Loading