-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(storage): expose metadata parameter in asyncio gRPC calls #17634
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
Open
ankitaluthra1
wants to merge
5
commits into
googleapis:main
Choose a base branch
from
ankitaluthra1:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+110
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12649ff
exposes metadata parameter to be added in grpc calls to pass addition…
ankitaluthra1 72fa58c
Merge branch 'googleapis:main' into main
ankitaluthra1 b1c2b3b
lint fix
ankitaluthra1 10af2a5
persist custom metadata on append and download_ranges calls for resume
ankitaluthra1 ef11aeb
removes metadata from reader and writer | updates docstring
ankitaluthra1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,22 @@ | |
| _DEFAULT_HOST = "storage.googleapis.com" | ||
|
|
||
|
|
||
| def _validate_metadata(metadata): | ||
| """Validates that metadata is a sequence of (key, value) pairs.""" | ||
| if metadata is None: | ||
| return | ||
| if not isinstance(metadata, (list, tuple)): | ||
| raise TypeError("metadata must be a list or tuple of (key, value) pairs.") | ||
| for item in metadata: | ||
| if not isinstance(item, (list, tuple)) or len(item) != 2: | ||
| raise ValueError( | ||
| "Each element in metadata must be a list or tuple of exactly 2 strings (key, value)." | ||
| ) | ||
| key, value = item | ||
| if not isinstance(key, str) or not isinstance(value, str): | ||
| raise TypeError("Both key and value in metadata pairs must be strings.") | ||
|
|
||
|
|
||
| class AsyncGrpcClient: | ||
| """An asynchronous client for interacting with Google Cloud Storage using the gRPC API. | ||
|
|
||
|
|
@@ -154,6 +170,9 @@ async def delete_object( | |
| if_generation_not_match=None, | ||
| if_metageneration_match=None, | ||
| if_metageneration_not_match=None, | ||
| metadata=(), | ||
| timeout=None, | ||
| retry=None, | ||
| **kwargs, | ||
| ): | ||
| """Deletes an object and its metadata. | ||
|
|
@@ -181,8 +200,18 @@ async def delete_object( | |
| :type if_metageneration_not_match: int | ||
| :param if_metageneration_not_match: (Optional) | ||
|
|
||
| :type metadata: Sequence[Tuple[str, str]] | ||
| :param metadata: (Optional) Additional metadata that is provided to the method. | ||
|
|
||
| :type timeout: float or None | ||
| :param timeout: | ||
| (Optional) The amount of time, in seconds, to wait for the request to | ||
| complete. | ||
|
|
||
| :type retry: :class:`~google.api_core.retry_async.AsyncRetry` or :class:`~google.api_core.retry.Retry` or None | ||
| :param retry: (Optional) Designation of what errors, if any, should be retried. | ||
| """ | ||
| _validate_metadata(metadata) | ||
| # The gRPC API requires the bucket name to be in the format "projects/_/buckets/bucket_name" | ||
| bucket_path = f"projects/_/buckets/{bucket_name}" | ||
| request = storage_v2.DeleteObjectRequest( | ||
|
|
@@ -195,7 +224,12 @@ async def delete_object( | |
| if_metageneration_not_match=if_metageneration_not_match, | ||
| **kwargs, | ||
| ) | ||
| await self._grpc_client.delete_object(request=request) | ||
| await self._grpc_client.delete_object( | ||
| request=request, | ||
| metadata=metadata, | ||
|
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. can you validate the inputs before passing here ? like it should be list/tuple with key, value pairs. |
||
| timeout=timeout, | ||
| retry=retry, | ||
| ) | ||
|
|
||
| async def get_object( | ||
| self, | ||
|
|
@@ -207,6 +241,9 @@ async def get_object( | |
| if_metageneration_match=None, | ||
| if_metageneration_not_match=None, | ||
| soft_deleted=None, | ||
| metadata=(), | ||
| timeout=None, | ||
| retry=None, | ||
| **kwargs, | ||
| ): | ||
| """Retrieves an object's metadata. | ||
|
|
@@ -240,9 +277,21 @@ async def get_object( | |
| :param soft_deleted: | ||
| (Optional) If True, return the soft-deleted version of this object. | ||
|
|
||
| :type metadata: Sequence[Tuple[str, str]] | ||
| :param metadata: (Optional) Additional metadata that is provided to the method. | ||
|
|
||
| :type timeout: float or None | ||
| :param timeout: | ||
| (Optional) The amount of time, in seconds, to wait for the request to | ||
| complete. | ||
|
|
||
| :type retry: :class:`~google.api_core.retry_async.AsyncRetry` or :class:`~google.api_core.retry.Retry` or None | ||
| :param retry: (Optional) Designation of what errors, if any, should be retried. | ||
|
|
||
| :rtype: :class:`google.cloud._storage_v2.types.Object` | ||
| :returns: The object metadata resource. | ||
| """ | ||
| _validate_metadata(metadata) | ||
| bucket_path = f"projects/_/buckets/{bucket_name}" | ||
|
|
||
| request = storage_v2.GetObjectRequest( | ||
|
|
@@ -258,4 +307,9 @@ async def get_object( | |
| ) | ||
|
|
||
| # Calls the underlying GAPIC StorageAsyncClient.get_object method | ||
| return await self._grpc_client.get_object(request=request) | ||
| return await self._grpc_client.get_object( | ||
| request=request, | ||
| metadata=metadata, | ||
| timeout=timeout, | ||
| retry=retry, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.