1717from dataclasses import dataclass
1818import logging
1919import ssl
20- from tempfile import TemporaryDirectory
2120from typing import Any , Dict , Optional , TYPE_CHECKING
2221
22+ from aiofiles .tempfile import TemporaryDirectory
23+
2324from google .cloud .sql .connector .exceptions import CloudSQLIPTypeError
2425from google .cloud .sql .connector .exceptions import TLSVersionError
2526from google .cloud .sql .connector .utils import write_to_file
@@ -45,7 +46,7 @@ class ConnectionInfo:
4546 expiration : datetime .datetime
4647 context : Optional [ssl .SSLContext ] = None
4748
48- def create_ssl_context (self , enable_iam_auth : bool = False ) -> ssl .SSLContext :
49+ async def create_ssl_context (self , enable_iam_auth : bool = False ) -> ssl .SSLContext :
4950 """Constructs a SSL/TLS context for the given connection info.
5051
5152 Cache the SSL context to ensure we don't read from disk repeatedly when
@@ -83,8 +84,8 @@ def create_ssl_context(self, enable_iam_auth: bool = False) -> ssl.SSLContext:
8384 # tmpdir and its contents are automatically deleted after the CA cert
8485 # and ephemeral cert are loaded into the SSLcontext. The values
8586 # need to be written to files in order to be loaded by the SSLContext
86- with TemporaryDirectory () as tmpdir :
87- ca_filename , cert_filename , key_filename = write_to_file (
87+ async with TemporaryDirectory () as tmpdir :
88+ ca_filename , cert_filename , key_filename = await write_to_file (
8889 tmpdir , self .server_ca_cert , self .client_cert , self .private_key
8990 )
9091 context .load_cert_chain (cert_filename , keyfile = key_filename )
0 commit comments