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

Updated minio driver to support 7.1.xx #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 19 additions & 23 deletions src/cloudstorage/drivers/minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
from urllib.parse import quote, urljoin

from inflection import camelize, underscore
from minio import Minio, PostPolicy, definitions
from minio import Minio
from minio.datatypes import PostPolicy
from minio.error import (
BucketAlreadyExists,
BucketAlreadyOwnedByYou,
BucketNotEmpty,
InvalidAccessKeyId,
InvalidBucketError,
InvalidBucketName,
NoSuchKey,
ResponseError,
SignatureDoesNotMatch,
MinioException,
InvalidResponseError,
ServerError,
S3Error
)

from cloudstorage import Blob, Container, Driver, messages
Expand All @@ -38,6 +34,8 @@
MetaData,
)

from minio.datatypes import Bucket, Object

__all__ = ["MinioDriver"]

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -148,14 +146,14 @@ def _normalize_parameters(

return normalized

def _get_bucket(self, bucket_name: str) -> definitions.Bucket:
def _get_bucket(self, bucket_name: str) -> Bucket:
"""Get a Minio bucket.

:param bucket_name: The Bucket's name identifier.
:type bucket_name: str

:return: Bucket resource object.
:rtype: :class:`minio.definitions.Bucket`
:rtype: :class:`minio.datatypes.Bucket`

:raises NotFoundError: If the bucket does not exist.
"""
Expand All @@ -164,14 +162,14 @@ def _get_bucket(self, bucket_name: str) -> definitions.Bucket:
return bucket
raise NotFoundError(messages.CONTAINER_NOT_FOUND % bucket_name)

def _make_obj(self, container: Container, obj: definitions.Object) -> Blob:
def _make_obj(self, container: Container, obj: Object) -> Blob:
"""Convert Minio Object to Blob instance.

:param container: The container that holds the blob.
:type container: :class:`.Container`

:param obj: Minio object stats.
:type obj: :class:`minio.definitions.Object`
:type obj: :class:`minio.datatypes.Object`

:return: A blob object.
:rtype: :class:`.Blob`
Expand Down Expand Up @@ -205,11 +203,11 @@ def _make_obj(self, container: Container, obj: definitions.Object) -> Blob:
expires_at=None,
)

def _make_container(self, bucket: definitions.Bucket) -> Container:
def _make_container(self, bucket: Bucket) -> Container:
"""Convert Minio Bucket to Container.

:param bucket: Minio bucket.
:type bucket: :class:`minio.definitions.Bucket`
:type bucket: :class:`minio.datatypes.Bucket`

:return: The container if it exists.
:rtype: :class:`.Container`
Expand All @@ -232,7 +230,7 @@ def validate_credentials(self) -> None:
try:
for _ in self.client.list_buckets():
break
except (InvalidAccessKeyId, SignatureDoesNotMatch) as err:
except (MinioException) as err:
raise CredentialsError(str(err))

@property
Expand All @@ -250,9 +248,7 @@ def create_container(

try:
self.client.make_bucket(container_name)
except (BucketAlreadyExists, BucketAlreadyOwnedByYou):
pass
except (InvalidBucketName, InvalidBucketError, ResponseError) as err:
except (MinioException) as err:
raise CloudStorageError(str(err))

bucket = self._get_bucket(container_name)
Expand All @@ -270,7 +266,7 @@ def delete_container(self, container: Container) -> None:

try:
self.client.remove_bucket(container.name)
except BucketNotEmpty:
except MinioException:
raise IsNotEmptyError(messages.CONTAINER_NOT_EMPTY % bucket.name)

def container_cdn_url(self, container: Container) -> str:
Expand Down Expand Up @@ -332,7 +328,7 @@ def upload_blob(
def get_blob(self, container: Container, blob_name: str) -> Blob:
try:
obj = self.client.stat_object(container.name, blob_name)
except NoSuchKey:
except MinioException:
raise NotFoundError(messages.BLOB_NOT_FOUND % (blob_name, container.name))
return self._make_obj(container, obj)

Expand All @@ -357,7 +353,7 @@ def patch_blob(self, blob: Blob) -> None:
def delete_blob(self, blob: Blob) -> None:
try:
self.client.remove_object(blob.container.name, blob.name)
except ResponseError as err:
except InvalidResponseError as err:
raise CloudStorageError(str(err))

def blob_cdn_url(self, blob: Blob) -> str:
Expand Down