Skip to content

Commit

Permalink
Add UserTags support to list_objects API (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybat committed Jan 13, 2024
1 parent b763f0e commit 67aab07
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion minio/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from collections import OrderedDict
from datetime import datetime
from enum import Enum
from typing import Type, TypeVar, cast
from typing import Any, List, Tuple, Type, TypeVar, cast
from urllib.parse import unquote_plus
from xml.etree import ElementTree as ET

Expand All @@ -38,6 +38,7 @@
except ImportError:
from urllib3.response import HTTPResponse as BaseHTTPResponse

from .commonconfig import Tags
from .credentials import Credentials
from .helpers import check_bucket_name
from .signer import get_credential_string, post_presign_v4
Expand Down Expand Up @@ -136,6 +137,7 @@ def __init__( # pylint: disable=too-many-arguments
owner_name: str | None = None,
content_type: str | None = None,
is_delete_marker: bool = False,
tags: Tags | None = None,
):
self._bucket_name = bucket_name
self._object_name = object_name
Expand All @@ -150,6 +152,7 @@ def __init__( # pylint: disable=too-many-arguments
self._owner_name = owner_name
self._content_type = content_type
self._is_delete_marker = is_delete_marker
self._tags = tags

@property
def bucket_name(self) -> str:
Expand Down Expand Up @@ -223,6 +226,11 @@ def content_type(self) -> str | None:
"""Get content type."""
return self._content_type

@property
def tags(self) -> Tags | None:
"""Get the tags"""
return self._tags

@classmethod
def fromxml(
cls: Type[B],
Expand Down Expand Up @@ -257,6 +265,17 @@ def fromxml(
if encoding_type == "url":
object_name = unquote_plus(object_name)

tags_text = findtext(element, "UserTags")
tags: Tags | None = None
if tags_text:
tags = Tags.new_object_tags()
tags.update(
cast(
List[Tuple[Any, Any]],
[tokens.split("=") for tokens in tags_text.split("&")],
),
)

return cls(
bucket_name,
object_name,
Expand All @@ -270,6 +289,7 @@ def fromxml(
owner_name=owner_name,
metadata=metadata,
is_delete_marker=is_delete_marker,
tags=tags
)


Expand Down

0 comments on commit 67aab07

Please sign in to comment.