| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 668fec0 commit b8b457a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | ) | |
| 24 | 24 | from google.cloud.storage import __version__ | |
| 25 | 25 | ||
| 26 | + _DEFAULT_HOST = "storage.googleapis.com" | ||
| 27 | + | ||
| 26 | 28 | ||
| 27 | 29 | class AsyncGrpcClient: | |
| 28 | 30 | """An asynchronous client for interacting with Google Cloud Storage using the gRPC API. | |
@@ -109,7 +111,15 @@ def _create_async_grpc_client( | |||
| 109 | 111 | ||
| 110 | 112 | primary_user_agent = client_info.to_user_agent() | |
| 111 | 113 | ||
| 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 | + | ||
| 112 | 120 | channel = transport_cls.create_channel( | |
| 121 | + host=host, | ||
| 122 | + quota_project_id=quota_project_id, | ||
| 113 | 123 | attempt_direct_path=attempt_direct_path, | |
| 114 | 124 | credentials=credentials, | |
| 115 | 125 | options=(("grpc.primary_user_agent", primary_user_agent),), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,8 @@ def test_constructor_default_options(self, mock_async_storage_client): | |||
| 53 | 53 | expected_options = (("grpc.primary_user_agent", primary_user_agent),) | |
| 54 | 54 | ||
| 55 | 55 | mock_transport_cls.create_channel.assert_called_once_with( | |
| 56 | + host="storage.googleapis.com", | ||
| 57 | + quota_project_id=None, | ||
| 56 | 58 | attempt_direct_path=True, | |
| 57 | 59 | credentials=mock_creds, | |
| 58 | 60 | options=expected_options, | |
@@ -82,6 +84,39 @@ def test_constructor_with_client_info(self, mock_async_storage_client): | |||
| 82 | 84 | expected_options = (("grpc.primary_user_agent", primary_user_agent),) | |
| 83 | 85 | ||
| 84 | 86 | 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", | ||
| 85 | 120 | attempt_direct_path=True, | |
| 86 | 121 | credentials=mock_creds, | |
| 87 | 122 | options=expected_options, | |
@@ -105,6 +140,8 @@ def test_constructor_disables_directpath(self, mock_async_storage_client): | |||
| 105 | 140 | expected_options = (("grpc.primary_user_agent", primary_user_agent),) | |
| 106 | 141 | ||
| 107 | 142 | mock_transport_cls.create_channel.assert_called_once_with( | |
| 143 | + host="storage.googleapis.com", | ||
| 144 | + quota_project_id=None, | ||
| 108 | 145 | attempt_direct_path=False, | |
| 109 | 146 | credentials=mock_creds, | |
| 110 | 147 | options=expected_options, | |
@@ -147,6 +184,8 @@ def test_grpc_client_property(self, mock_grpc_gapic_client): | |||
| 147 | 184 | expected_options = (("grpc.primary_user_agent", primary_user_agent),) | |
| 148 | 185 | ||
| 149 | 186 | mock_transport_cls.create_channel.assert_called_once_with( | |
| 187 | + host="storage.googleapis.com", | ||
| 188 | + quota_project_id=None, | ||
| 150 | 189 | attempt_direct_path=mock_attempt_direct_path, | |
| 151 | 190 | credentials=mock_creds, | |
| 152 | 191 | options=expected_options, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments