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

list_objects: add extra headers and extra query parameters #1458

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ client.remove_bucket("my-bucket")

<a name="list_objects"></a>

### list_objects(bucket_name, prefix=None, recursive=False, start_after=None, include_user_meta=False, include_version=False, use_api_v1=False, use_url_encoding_type=True)
### list_objects(bucket_name, prefix=None, recursive=False, start_after=None, include_user_meta=False, include_version=False, use_api_v1=False, use_url_encoding_type=True, extra_headers=None, extra_query_params=None)

Lists object information of a bucket.

Expand All @@ -199,6 +199,8 @@ __Parameters__
| `include_version` | _bool_ | Flag to control whether include object versions. |
| `use_api_v1` | _bool_ | Flag to control to use ListObjectV1 S3 API or not. |
| `use_url_encoding_type` | _bool_ | Flag to control whether URL encoding type to be used or not. |
| `extra_headers` | _dict_ | Extra HTTP headers for advanced usage. |
| `extra_query_params` | _dict_ | Extra query parameters for advanced usage. |

__Return Value__

Expand Down Expand Up @@ -1374,7 +1376,7 @@ print(

<a name="stat_object"></a>

### stat_object(bucket_name, object_name, ssec=None, version_id=None, extra_query_params=None)
### stat_object(bucket_name, object_name, ssec=None, version_id=None, extra_headers=None, extra_query_params=None)

Get object information and metadata of an object.

Expand Down
11 changes: 10 additions & 1 deletion minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,8 @@ def list_objects(
use_api_v1: bool = False,
use_url_encoding_type: bool = True,
fetch_owner: bool = False,
extra_headers: DictType | None = None,
extra_query_params: DictType | None = None,
):
"""
Lists object information of a bucket.
Expand All @@ -2021,6 +2023,8 @@ def list_objects(
:param use_api_v1: Flag to control to use ListObjectV1 S3 API or not.
:param use_url_encoding_type: Flag to control whether URL encoding type
to be used or not.
:param extra_headers: Extra HTTP headers for advanced usage.
:param extra_query_params: Extra query parameters for advanced usage.
:return: Iterator of :class:`Object <Object>`.

Example::
Expand Down Expand Up @@ -2065,6 +2069,8 @@ def list_objects(
include_version=include_version,
encoding_type="url" if use_url_encoding_type else None,
fetch_owner=fetch_owner,
extra_headers=extra_headers,
extra_query_params=extra_query_params,
)

def stat_object(
Expand Down Expand Up @@ -3136,6 +3142,8 @@ def _list_objects(
version_id_marker: str | None = None, # versioned
use_api_v1: bool = False,
include_version: bool = False,
extra_headers: DictType | None = None,
extra_query_params: DictType | None = None,
) -> Iterator[Object]:
"""
List objects optionally including versions.
Expand All @@ -3152,7 +3160,7 @@ def _list_objects(

is_truncated = True
while is_truncated:
query = {}
query = extra_query_params or {}
if include_version:
query["versions"] = ""
elif not use_api_v1:
Expand Down Expand Up @@ -3184,6 +3192,7 @@ def _list_objects(
"GET",
bucket_name,
query_params=cast(DictType, query),
headers=extra_headers,
)

objects, is_truncated, start_after, version_id_marker = (
Expand Down