-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(storage): add object contexts in Python GCS SDK #17039
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
base: main
Are you sure you want to change the base?
Changes from all commits
f76c83e
30fb5c3
d96977a
1d1c36c
a5d59ef
1ef8d81
5aeeedd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| from google.cloud.storage._signing import generate_signed_url_v2, generate_signed_url_v4 | ||
| from google.cloud.storage.acl import BucketACL, DefaultObjectACL | ||
| from google.cloud.storage.blob import Blob, _quote | ||
| from google.cloud.storage.blob import ObjectContexts | ||
| from google.cloud.storage.constants import ( | ||
| _DEFAULT_TIMEOUT, | ||
| ARCHIVE_STORAGE_CLASS, | ||
|
|
@@ -1423,6 +1424,7 @@ def list_blobs( | |
| include_folders_as_prefixes=None, | ||
| soft_deleted=None, | ||
| page_size=None, | ||
| filter_=None, | ||
| ): | ||
| """Return an iterator used to find blobs in the bucket. | ||
|
|
||
|
|
@@ -1516,6 +1518,11 @@ def list_blobs( | |
| Note ``soft_deleted`` and ``versions`` cannot be set to True simultaneously. See: | ||
| https://cloud.google.com/storage/docs/soft-delete | ||
|
|
||
| :type filter_: str | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add link to the syntax for filter - https://docs.cloud.google.com/storage/docs/listing-objects#filter-by-object-contexts-syntax
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jules modify the docblock and add the link |
||
| :param filter_: | ||
| (Optional) Filter string used to filter objects. See: | ||
| https://docs.cloud.google.com/storage/docs/listing-objects#filter-by-object-contexts-syntax | ||
|
|
||
| :type page_size: int | ||
| :param page_size: | ||
| (Optional) Maximum number of blobs to return in each page. | ||
|
|
@@ -1545,6 +1552,7 @@ def list_blobs( | |
| match_glob=match_glob, | ||
| include_folders_as_prefixes=include_folders_as_prefixes, | ||
| soft_deleted=soft_deleted, | ||
| filter_=filter_, | ||
| ) | ||
|
|
||
| def list_notifications( | ||
|
|
@@ -1972,6 +1980,7 @@ def copy_blob( | |
| if_source_metageneration_not_match=None, | ||
| timeout=_DEFAULT_TIMEOUT, | ||
| retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, | ||
| destination_contexts=None, | ||
| ): | ||
| """Copy the given blob to the given bucket, optionally with a new name. | ||
|
|
||
|
|
@@ -2065,6 +2074,10 @@ def copy_blob( | |
| to enable retries regardless of generation precondition setting. | ||
| See [Configuring Retries](https://cloud.google.com/python/docs/reference/storage/latest/retry_timeout). | ||
|
|
||
| :type destination_contexts: :class:`~google.cloud.storage.blob.ObjectContexts` or dict | ||
| :param destination_contexts: | ||
| (Optional) New contexts to set for the destination object. | ||
| See: https://docs.cloud.google.com/storage/docs/use-object-contexts#manage_object_contexts_during_object_operations | ||
| :rtype: :class:`google.cloud.storage.blob.Blob` | ||
| :returns: The new Blob. | ||
| """ | ||
|
|
@@ -2094,10 +2107,22 @@ def copy_blob( | |
| new_name = blob.name | ||
|
|
||
| new_blob = Blob(bucket=destination_bucket, name=new_name) | ||
|
|
||
| if destination_contexts is not None: | ||
| if isinstance(destination_contexts, ObjectContexts): | ||
| new_blob.contexts = destination_contexts | ||
| else: | ||
| raise ValueError( | ||
| "destination_contexts must be an ObjectContexts object" | ||
| ) | ||
| request_body = new_blob._properties.copy() | ||
| else: | ||
| request_body = None | ||
|
|
||
| api_path = blob.path + "/copyTo" + new_blob.path | ||
| copy_result = client._post_resource( | ||
| api_path, | ||
| None, | ||
| request_body, | ||
| query_params=query_params, | ||
| timeout=timeout, | ||
| retry=retry, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1291,6 +1291,7 @@ def list_blobs( | |
| match_glob=None, | ||
| include_folders_as_prefixes=None, | ||
| soft_deleted=None, | ||
| filter_=None, | ||
| ): | ||
| """Return an iterator used to find blobs in the bucket. | ||
|
|
||
|
|
@@ -1400,6 +1401,10 @@ def list_blobs( | |
| Note ``soft_deleted`` and ``versions`` cannot be set to True simultaneously. See: | ||
| https://cloud.google.com/storage/docs/soft-delete | ||
|
|
||
| filter_ (str): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add link to the syntax for filter - https://docs.cloud.google.com/storage/docs/listing-objects#filter-by-object-contexts-syntax
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jules modify the docblock and add the link |
||
| (Optional) Filter string used to filter objects. See: | ||
| https://docs.cloud.google.com/storage/docs/listing-objects#filter-by-object-contexts-syntax | ||
|
|
||
| Returns: | ||
| Iterator of all :class:`~google.cloud.storage.blob.Blob` | ||
| in this bucket matching the arguments. The RPC call | ||
|
|
@@ -1443,6 +1448,9 @@ def list_blobs( | |
| if soft_deleted is not None: | ||
| extra_params["softDeleted"] = soft_deleted | ||
|
|
||
| if filter_ is not None: | ||
| extra_params["filter"] = filter_ | ||
|
|
||
| if bucket.user_project is not None: | ||
| extra_params["userProject"] = bucket.user_project | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file will be used grpc ,hence can you write one system test for zonal buckets ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jules add a system test in test_zonal.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a system test for object contexts in
test_zonal.py.