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

feat: support includeFoldersAsPrefixes #1223

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Merge branch 'main' into includeFolders
  • Loading branch information
cojenco committed Mar 18, 2024
commit b6f5c07d9a7f05591d175765d47bf826e531ee39
9 changes: 9 additions & 0 deletions google/cloud/storage/bucket.py
Expand Up @@ -1307,6 +1307,7 @@ def list_blobs(
retry=DEFAULT_RETRY,
match_glob=None,
include_folders_as_prefixes=None,
soft_deleted=None,
):
"""Return an iterator used to find blobs in the bucket.

Expand Down Expand Up @@ -1393,6 +1394,13 @@ def list_blobs(
``prefixes`` returned by the query. Only applicable if ``delimiter`` is set to /.
See: https://cloud.google.com/storage/docs/managed-folders

:type soft_deleted: bool
:param soft_deleted:
(Optional) If true, only soft-deleted objects will be listed as distinct results in order of increasing
generation number. This parameter can only be used successfully if the bucket has a soft delete policy.
Note ``soft_deleted`` and ``versions`` cannot be set to True simultaneously. See:
https://cloud.google.com/storage/docs/soft-delete

:rtype: :class:`~google.api_core.page_iterator.Iterator`
:returns: Iterator of all :class:`~google.cloud.storage.blob.Blob`
in this bucket matching the arguments.
Expand All @@ -1414,6 +1422,7 @@ def list_blobs(
retry=retry,
match_glob=match_glob,
include_folders_as_prefixes=include_folders_as_prefixes,
soft_deleted=soft_deleted,
)

def list_notifications(
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/storage/client.py
Expand Up @@ -1185,6 +1185,7 @@ def list_blobs(
retry=DEFAULT_RETRY,
match_glob=None,
include_folders_as_prefixes=None,
soft_deleted=None,
):
"""Return an iterator used to find blobs in the bucket.

Expand Down Expand Up @@ -1288,6 +1289,12 @@ def list_blobs(
``prefixes`` returned by the query. Only applicable if ``delimiter`` is set to /.
See: https://cloud.google.com/storage/docs/managed-folders

soft_deleted (bool):
(Optional) If true, only soft-deleted objects will be listed as distinct results in order of increasing
generation number. This parameter can only be used successfully if the bucket has a soft delete policy.
Note ``soft_deleted`` and ``versions`` cannot be set to True simultaneously. See:
https://cloud.google.com/storage/docs/soft-delete

Returns:
Iterator of all :class:`~google.cloud.storage.blob.Blob`
in this bucket matching the arguments. The RPC call
Expand Down Expand Up @@ -1327,6 +1334,9 @@ def list_blobs(
if include_folders_as_prefixes is not None:
extra_params["includeFoldersAsPrefixes"] = include_folders_as_prefixes

if soft_deleted is not None:
extra_params["softDeleted"] = soft_deleted

if bucket.user_project is not None:
extra_params["userProject"] = bucket.user_project

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_bucket.py
Expand Up @@ -1178,6 +1178,7 @@ def test_list_blobs_w_defaults(self):
expected_projection = "noAcl"
expected_fields = None
expected_include_folders_as_prefixes = None
soft_deleted = None
client.list_blobs.assert_called_once_with(
bucket,
max_results=expected_max_results,
Expand All @@ -1194,6 +1195,7 @@ def test_list_blobs_w_defaults(self):
retry=DEFAULT_RETRY,
match_glob=expected_match_glob,
include_folders_as_prefixes=expected_include_folders_as_prefixes,
soft_deleted=soft_deleted,
)

def test_list_blobs_w_explicit(self):
Expand Down Expand Up @@ -1233,6 +1235,7 @@ def test_list_blobs_w_explicit(self):
retry=retry,
match_glob=match_glob,
include_folders_as_prefixes=include_folders_as_prefixes,
soft_deleted=soft_deleted,
)

self.assertIs(iterator, other_client.list_blobs.return_value)
Expand All @@ -1249,6 +1252,7 @@ def test_list_blobs_w_explicit(self):
expected_projection = projection
expected_fields = fields
expected_include_folders_as_prefixes = include_folders_as_prefixes
expected_soft_deleted = soft_deleted
other_client.list_blobs.assert_called_once_with(
bucket,
max_results=expected_max_results,
Expand All @@ -1265,6 +1269,7 @@ def test_list_blobs_w_explicit(self):
retry=retry,
match_glob=expected_match_glob,
include_folders_as_prefixes=expected_include_folders_as_prefixes,
soft_deleted=expected_soft_deleted,
)

def test_list_notifications_w_defaults(self):
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_client.py
Expand Up @@ -2016,6 +2016,7 @@ def test_list_blobs_w_explicit_w_user_project(self):
end_offset = "g"
include_trailing_delimiter = True
include_folders_as_prefixes = True
soft_deleted = False
versions = True
projection = "full"
page_size = 2
Expand Down Expand Up @@ -2049,6 +2050,7 @@ def test_list_blobs_w_explicit_w_user_project(self):
retry=retry,
match_glob=match_glob,
include_folders_as_prefixes=include_folders_as_prefixes,
soft_deleted=soft_deleted,
)

self.assertIs(iterator, client._list_resource.return_value)
Expand All @@ -2071,6 +2073,7 @@ def test_list_blobs_w_explicit_w_user_project(self):
"fields": fields,
"userProject": user_project,
"includeFoldersAsPrefixes": include_folders_as_prefixes,
"softDeleted": soft_deleted,
}
expected_page_start = _blobs_page_start
expected_page_size = 2
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.