3737import  google .cloud .sql .connector .pg8000  as  pg8000 
3838import  google .cloud .sql .connector .pymysql  as  pymysql 
3939import  google .cloud .sql .connector .pytds  as  pytds 
40+ from  google .cloud .sql .connector .resolver  import  DefaultResolver 
41+ from  google .cloud .sql .connector .resolver  import  DnsResolver 
4042from  google .cloud .sql .connector .utils  import  format_database_user 
4143from  google .cloud .sql .connector .utils  import  generate_keys 
4244
@@ -63,6 +65,7 @@ def __init__(
6365        user_agent : Optional [str ] =  None ,
6466        universe_domain : Optional [str ] =  None ,
6567        refresh_strategy : str  |  RefreshStrategy  =  RefreshStrategy .BACKGROUND ,
68+         resolver : DefaultResolver  |  DnsResolver  =  DefaultResolver ,
6669    ) ->  None :
6770        """Initializes a Connector instance. 
6871
@@ -104,6 +107,12 @@ def __init__(
104107                of the following: RefreshStrategy.LAZY ("LAZY") or 
105108                RefreshStrategy.BACKGROUND ("BACKGROUND"). 
106109                Default: RefreshStrategy.BACKGROUND 
110+             resolver (DefaultResolver | DnsResolver): The class name of the 
111+                 resolver to use for resolving the Cloud SQL instance connection 
112+                 name. To resolve a DNS record to an instance connection name, use 
113+                 DnsResolver. 
114+                 Default: DefaultResolver 
115+ 
107116        """ 
108117        # if refresh_strategy is str, convert to RefreshStrategy enum 
109118        if  isinstance (refresh_strategy , str ):
@@ -157,6 +166,7 @@ def __init__(
157166        self ._enable_iam_auth  =  enable_iam_auth 
158167        self ._quota_project  =  quota_project 
159168        self ._user_agent  =  user_agent 
169+         self ._resolver  =  resolver ()
160170        # if ip_type is str, convert to IPTypes enum 
161171        if  isinstance (ip_type , str ):
162172            ip_type  =  IPTypes ._from_str (ip_type )
@@ -269,13 +279,14 @@ async def connect_async(
269279        if  (instance_connection_string , enable_iam_auth ) in  self ._cache :
270280            cache  =  self ._cache [(instance_connection_string , enable_iam_auth )]
271281        else :
282+             conn_name  =  await  self ._resolver .resolve (instance_connection_string )
272283            if  self ._refresh_strategy  ==  RefreshStrategy .LAZY :
273284                logger .debug (
274285                    f"['{ instance_connection_string }  ']: Refresh strategy is set" 
275286                    " to lazy refresh" 
276287                )
277288                cache  =  LazyRefreshCache (
278-                     instance_connection_string ,
289+                     conn_name ,
279290                    self ._client ,
280291                    self ._keys ,
281292                    enable_iam_auth ,
@@ -286,7 +297,7 @@ async def connect_async(
286297                    " to backgound refresh" 
287298                )
288299                cache  =  RefreshAheadCache (
289-                     instance_connection_string ,
300+                     conn_name ,
290301                    self ._client ,
291302                    self ._keys ,
292303                    enable_iam_auth ,
0 commit comments