|
20 | 20 |
|
21 | 21 | import six |
22 | 22 |
|
| 23 | +from google.auth import exceptions |
23 | 24 | from google.auth.transport import _mtls_helper |
24 | 25 |
|
25 | 26 | try: |
@@ -217,17 +218,8 @@ def my_client_cert_callback(): |
217 | 218 | grpc.Channel: The created gRPC channel. |
218 | 219 |
|
219 | 220 | Raises: |
220 | | - OSError: If the cert provider command launch fails during the application |
221 | | - default SSL credentials loading process on devices with endpoint |
222 | | - verification support. |
223 | | - RuntimeError: If the cert provider command has a runtime error during the |
224 | | - application default SSL credentials loading process on devices with |
225 | | - endpoint verification support. |
226 | | - ValueError: |
227 | | - If the context aware metadata file is malformed or if the cert provider |
228 | | - command doesn't produce both client certificate and key during the |
229 | | - application default SSL credentials loading process on devices with |
230 | | - endpoint verification support. |
| 221 | + google.auth.exceptions.MutualTLSChannelError: If mutual TLS channel |
| 222 | + creation failed for any reason. |
231 | 223 | """ |
232 | 224 | # Create the metadata plugin for inserting the authorization header. |
233 | 225 | metadata_plugin = AuthMetadataPlugin(credentials, request) |
@@ -293,20 +285,21 @@ def ssl_credentials(self): |
293 | 285 | grpc.ChannelCredentials: The created grpc channel credentials. |
294 | 286 |
|
295 | 287 | Raises: |
296 | | - OSError: If the cert provider command launch fails. |
297 | | - RuntimeError: If the cert provider command has a runtime error. |
298 | | - ValueError: |
299 | | - If the context aware metadata file is malformed or if the cert provider |
300 | | - command doesn't produce both the client certificate and key. |
| 288 | + google.auth.exceptions.MutualTLSChannelError: If mutual TLS channel |
| 289 | + creation failed for any reason. |
301 | 290 | """ |
302 | 291 | if self._context_aware_metadata_path: |
303 | | - metadata = _mtls_helper._read_dca_metadata_file( |
304 | | - self._context_aware_metadata_path |
305 | | - ) |
306 | | - cert, key = _mtls_helper.get_client_ssl_credentials(metadata) |
307 | | - self._ssl_credentials = grpc.ssl_channel_credentials( |
308 | | - certificate_chain=cert, private_key=key |
309 | | - ) |
| 292 | + try: |
| 293 | + metadata = _mtls_helper._read_dca_metadata_file( |
| 294 | + self._context_aware_metadata_path |
| 295 | + ) |
| 296 | + cert, key = _mtls_helper.get_client_ssl_credentials(metadata) |
| 297 | + self._ssl_credentials = grpc.ssl_channel_credentials( |
| 298 | + certificate_chain=cert, private_key=key |
| 299 | + ) |
| 300 | + except (OSError, RuntimeError, ValueError) as caught_exc: |
| 301 | + new_exc = exceptions.MutualTLSChannelError(caught_exc) |
| 302 | + six.raise_from(new_exc, caught_exc) |
310 | 303 | else: |
311 | 304 | self._ssl_credentials = grpc.ssl_channel_credentials() |
312 | 305 |
|
|
0 commit comments