Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b8b457a

Browse filesBrowse files
authored
fix: propagate quota_project_id and api_endpoint in AsyncGrpcClient (#16731)
This PR fixes b/503990490 where AsyncGrpcClient fails to propagate quota_project_id and api_endpoint from ClientOptions to the gRPC channel.
1 parent 668fec0 commit b8b457a
Copy full SHA for b8b457a

2 files changed

+49Lines changed: 49 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/google-cloud-storage/google/cloud/storage/asyncio/async_grpc_client.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-storage/google/cloud/storage/asyncio/async_grpc_client.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
)
2424
from google.cloud.storage import __version__
2525

26+
_DEFAULT_HOST = "storage.googleapis.com"
27+
2628

2729
class AsyncGrpcClient:
2830
"""An asynchronous client for interacting with Google Cloud Storage using the gRPC API.
@@ -109,7 +111,15 @@ def _create_async_grpc_client(
109111

110112
primary_user_agent = client_info.to_user_agent()
111113

114+
host = _DEFAULT_HOST
115+
quota_project_id = None
116+
if client_options:
117+
host = getattr(client_options, "api_endpoint", None) or _DEFAULT_HOST
118+
quota_project_id = getattr(client_options, "quota_project_id", None)
119+
112120
channel = transport_cls.create_channel(
121+
host=host,
122+
quota_project_id=quota_project_id,
113123
attempt_direct_path=attempt_direct_path,
114124
credentials=credentials,
115125
options=(("grpc.primary_user_agent", primary_user_agent),),
Collapse file

‎packages/google-cloud-storage/tests/unit/asyncio/test_async_grpc_client.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-storage/tests/unit/asyncio/test_async_grpc_client.py
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def test_constructor_default_options(self, mock_async_storage_client):
5353
expected_options = (("grpc.primary_user_agent", primary_user_agent),)
5454

5555
mock_transport_cls.create_channel.assert_called_once_with(
56+
host="storage.googleapis.com",
57+
quota_project_id=None,
5658
attempt_direct_path=True,
5759
credentials=mock_creds,
5860
options=expected_options,
@@ -82,6 +84,39 @@ def test_constructor_with_client_info(self, mock_async_storage_client):
8284
expected_options = (("grpc.primary_user_agent", primary_user_agent),)
8385

8486
mock_transport_cls.create_channel.assert_called_once_with(
87+
host="storage.googleapis.com",
88+
quota_project_id=None,
89+
attempt_direct_path=True,
90+
credentials=mock_creds,
91+
options=expected_options,
92+
)
93+
94+
@mock.patch("google.cloud._storage_v2.StorageAsyncClient")
95+
def test_constructor_with_quota_project_and_endpoint(
96+
self, mock_async_storage_client
97+
):
98+
mock_transport_cls = mock.MagicMock()
99+
mock_async_storage_client.get_transport_class.return_value = mock_transport_cls
100+
mock_creds = _make_credentials()
101+
102+
from google.api_core import client_options
103+
104+
mock_client_options = client_options.ClientOptions(
105+
api_endpoint="custom-endpoint.com", quota_project_id="my-quota-project"
106+
)
107+
108+
async_grpc_client.AsyncGrpcClient(
109+
credentials=mock_creds, client_options=mock_client_options
110+
)
111+
112+
kwargs = mock_async_storage_client.call_args.kwargs
113+
client_info = kwargs["client_info"]
114+
primary_user_agent = client_info.to_user_agent()
115+
expected_options = (("grpc.primary_user_agent", primary_user_agent),)
116+
117+
mock_transport_cls.create_channel.assert_called_once_with(
118+
host="custom-endpoint.com",
119+
quota_project_id="my-quota-project",
85120
attempt_direct_path=True,
86121
credentials=mock_creds,
87122
options=expected_options,
@@ -105,6 +140,8 @@ def test_constructor_disables_directpath(self, mock_async_storage_client):
105140
expected_options = (("grpc.primary_user_agent", primary_user_agent),)
106141

107142
mock_transport_cls.create_channel.assert_called_once_with(
143+
host="storage.googleapis.com",
144+
quota_project_id=None,
108145
attempt_direct_path=False,
109146
credentials=mock_creds,
110147
options=expected_options,
@@ -147,6 +184,8 @@ def test_grpc_client_property(self, mock_grpc_gapic_client):
147184
expected_options = (("grpc.primary_user_agent", primary_user_agent),)
148185

149186
mock_transport_cls.create_channel.assert_called_once_with(
187+
host="storage.googleapis.com",
188+
quota_project_id=None,
150189
attempt_direct_path=mock_attempt_direct_path,
151190
credentials=mock_creds,
152191
options=expected_options,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.