1414
1515from __future__ import annotations
1616
17- import abc
1817from dataclasses import dataclass
1918import logging
20- import socket
2119import ssl
22- from typing import Any , Optional , TYPE_CHECKING , Union
20+ from typing import Any , Optional , TYPE_CHECKING
2321
2422from aiofiles .tempfile import TemporaryDirectory
2523
2624from google .cloud .sql .connector .connection_name import ConnectionName
27- from google .cloud .sql .connector .enums import IPTypes
2825from google .cloud .sql .connector .exceptions import CloudSQLIPTypeError
2926from google .cloud .sql .connector .exceptions import TLSVersionError
3027from google .cloud .sql .connector .utils import write_to_file
3128
3229if TYPE_CHECKING :
3330 import datetime
3431
32+ from google .cloud .sql .connector .enums import IPTypes
3533
3634logger = logging .getLogger (name = __name__ )
3735
3836
39- class ConnectionInfoCache (abc .ABC ):
40- """Abstract class for Connector connection info caches."""
41-
42- @abc .abstractmethod
43- async def connect_info (self ) -> ConnectionInfo :
44- pass
45-
46- @abc .abstractmethod
47- async def force_refresh (self ) -> None :
48- pass
49-
50- @abc .abstractmethod
51- async def close (self ) -> None :
52- pass
53-
54- @property
55- @abc .abstractmethod
56- def closed (self ) -> bool :
57- pass
58-
59-
6037@dataclass
6138class ConnectionInfo :
6239 """Contains all necessary information to connect securely to the
@@ -70,21 +47,13 @@ class ConnectionInfo:
7047 database_version : str
7148 expiration : datetime .datetime
7249 context : Optional [ssl .SSLContext ] = None
73- sock : Optional [ssl .SSLSocket ] = None
7450
75- async def create_ssl_context (
76- self , enable_iam_auth : bool = False , return_socket : bool = False
77- ) -> Union [ssl .SSLContext , ssl .SSLSocket ]:
51+ async def create_ssl_context (self , enable_iam_auth : bool = False ) -> ssl .SSLContext :
7852 """Constructs a SSL/TLS context for the given connection info.
7953
8054 Cache the SSL context to ensure we don't read from disk repeatedly when
8155 configuring a secure connection.
8256 """
83- # Return socket if socket is cached and return_socket is set to True
84- if self .sock is not None and return_socket :
85- logger .debug ("Socket in cache, returning it!" )
86- return self .sock
87-
8857 # if SSL context is cached, use it
8958 if self .context is not None :
9059 return self .context
@@ -125,15 +94,6 @@ async def create_ssl_context(
12594 context .load_verify_locations (cafile = ca_filename )
12695 # set class attribute to cache context for subsequent calls
12796 self .context = context
128- # If return_socket is True, cache socket and return it
129- if return_socket :
130- logger .debug ("Returning socket instead of context!" )
131- sock = self .context .wrap_socket (
132- socket .create_connection ((self .get_preferred_ip (IPTypes .PUBLIC ), 3307 )),
133- server_hostname = "blah" ,
134- )
135- self .sock = sock
136- return sock
13797 return context
13898
13999 def get_preferred_ip (self , ip_type : IPTypes ) -> str :
0 commit comments