Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 6f34fc2

Browse files
chore: respond to reviewer comments to add docstrings and fix timeout logic
Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
1 parent 382fb70 commit 6f34fc2

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

google/auth/aio/transport/mtls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def make_client_cert_ssl_context(
5959
"""Creates an SSLContext with the given client certificate and key.
6060
This function writes the certificate and key to temporary files so that
6161
ssl.create_default_context can load them, as the ssl module requires
62-
file paths for client certificates.
62+
file paths for client certificates. These temporary files are deleted
63+
immediately after the SSL context is created.
6364
Args:
6465
cert_bytes (bytes): The client certificate content in PEM format.
6566
key_bytes (bytes): The client private key content in PEM format.

google/auth/aio/transport/sessions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from contextlib import asynccontextmanager
1717
import functools
1818
import time
19-
import typing
2019
from typing import Mapping, Optional, TYPE_CHECKING, Union
2120

2221
from google.auth import _exponential_backoff, exceptions
@@ -27,16 +26,17 @@
2726
import google.auth.transport._mtls_helper
2827

2928
if TYPE_CHECKING: # pragma: NO COVER
29+
import aiohttp
3030
from aiohttp import ClientTimeout # type: ignore
3131

3232
else:
3333
try:
34+
import aiohttp
3435
from aiohttp import ClientTimeout
3536
except (ImportError, AttributeError):
3637
ClientTimeout = None
3738

3839
try:
39-
import aiohttp
4040
from google.auth.aio.transport.aiohttp import Request as AiohttpRequest
4141

4242
AIOHTTP_INSTALLED = True
@@ -154,7 +154,7 @@ async def configure_mtls_channel(self, client_cert_callback=None):
154154
default SSL credentials), the underlying transport will be reconfigured
155155
to use mTLS.
156156
Note: This function does nothing if the `aiohttp` library is not
157-
installed.
157+
installed. Plus, will close any ongoing API requests.
158158
159159
Args:
160160
client_cert_callback (Optional[Callable[[], (bytes, bytes)]]):
@@ -260,13 +260,13 @@ async def request(
260260
self._auth_request, method, url, headers
261261
)
262262
)
263-
if AIOHTTP_INSTALLED and hasattr(timeout, "total"):
264-
# If it's a ClientTimeout, extract the total float
265-
actual_timeout = typing.cast(float, timeout.total)
266-
elif timeout is None:
267-
actual_timeout = 0.0
263+
actual_timeout: float = 0.0
264+
if AIOHTTP_INSTALLED and isinstance(timeout, aiohttp.ClientTimeout):
265+
actual_timeout = timeout.total if timeout.total is not None else 0.0
266+
elif isinstance(timeout, (int, float)):
267+
actual_timeout = float(timeout)
268268
else:
269-
actual_timeout = typing.cast(float, timeout)
269+
actual_timeout = 0.0
270270
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
271271
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
272272
async for _ in retries: # pragma: no branch

0 commit comments

Comments
 (0)