cloud-sql-python-connector 1.7.0__py2.py3-none-any.whl → 1.9.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cloud-sql-python-connector
3
- Version: 1.7.0
3
+ Version: 1.9.0
4
4
  Summary: The Cloud SQL Python Connector is a library that can be used alongside a database driver to allow users with sufficient permissions to connect to a Cloud SQL database without having to manually allowlist IPs or manage SSL certificates.
5
5
  Home-page: https://github.com/GoogleCloudPlatform/cloud-sql-python-connector
6
6
  Author: Google LLC
@@ -26,7 +26,7 @@ Requires-Dist: google-auth
26
26
  Provides-Extra: asyncpg
27
27
  Requires-Dist: asyncpg (>=0.29.0) ; extra == 'asyncpg'
28
28
  Provides-Extra: pg8000
29
- Requires-Dist: pg8000 (>=1.30.4) ; extra == 'pg8000'
29
+ Requires-Dist: pg8000 (>=1.31.1) ; extra == 'pg8000'
30
30
  Provides-Extra: pymysql
31
31
  Requires-Dist: PyMySQL (>=1.1.0) ; extra == 'pymysql'
32
32
  Provides-Extra: pytds
@@ -222,7 +222,7 @@ from google.cloud.sql.connector import Connector, IPTypes
222
222
 
223
223
  # Note: all parameters below are optional
224
224
  connector = Connector(
225
- ip_type=IPTypes.PUBLIC,
225
+ ip_type="public", # can also be "private" or "psc"
226
226
  enable_iam_auth=False,
227
227
  timeout=30,
228
228
  credentials=custom_creds # google.auth.credentials.Credentials
@@ -295,18 +295,16 @@ using both public and private IP addresses, as well as
295
295
  with, set the `ip_type` keyword argument when initializing a `Connector()` or when
296
296
  calling `connector.connect()`.
297
297
 
298
- Possible values for `ip_type` are `IPTypes.PUBLIC` (default value),
299
- `IPTypes.PRIVATE`, and `IPTypes.PSC`.
298
+ Possible values for `ip_type` are `"public"` (default value),
299
+ `"private"`, and `"psc"`.
300
300
 
301
301
  Example:
302
302
 
303
303
  ```python
304
- from google.cloud.sql.connector import IPTypes
305
-
306
304
  conn = connector.connect(
307
305
  "project:region:instance",
308
306
  "pymysql",
309
- ip_type=IPTypes.PRIVATE # use private IP
307
+ ip_type="private" # use private IP
310
308
  ... insert other kwargs ...
311
309
  )
312
310
  ```
@@ -367,7 +365,7 @@ conn = connector.connect(
367
365
  db="my-db-name",
368
366
  active_directory_auth=True,
369
367
  server_name="private.[instance].[location].[project].cloudsql.[domain]",
370
- ip_type=IPTypes.PRIVATE
368
+ ip_type="private"
371
369
  )
372
370
  ```
373
371
 
@@ -392,7 +390,7 @@ your web application through the following:
392
390
  ```python
393
391
  from flask import Flask
394
392
  from flask_sqlalchemy import SQLAlchemy
395
- from google.cloud.sql.connector import Connector, IPTypes
393
+ from google.cloud.sql.connector import Connector
396
394
 
397
395
 
398
396
  # initialize Python Connector object
@@ -406,7 +404,7 @@ def getconn():
406
404
  user="my-user",
407
405
  password="my-password",
408
406
  db="my-database",
409
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
407
+ ip_type="public" # "private" for private IP
410
408
  )
411
409
  return conn
412
410
 
@@ -441,7 +439,7 @@ from sqlalchemy import create_engine
441
439
  from sqlalchemy.engine import Engine
442
440
  from sqlalchemy.ext.declarative import declarative_base
443
441
  from sqlalchemy.orm import sessionmaker
444
- from google.cloud.sql.connector import Connector, IPTypes
442
+ from google.cloud.sql.connector import Connector
445
443
 
446
444
  # helper function to return SQLAlchemy connection pool
447
445
  def init_connection_pool(connector: Connector) -> Engine:
@@ -453,7 +451,7 @@ def init_connection_pool(connector: Connector) -> Engine:
453
451
  user="my-user",
454
452
  password="my-password",
455
453
  db="my-database",
456
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
454
+ ip_type="public" # "private" for private IP
457
455
  )
458
456
  return conn
459
457
 
@@ -1,9 +1,9 @@
1
1
  google/cloud/sql/connector/__init__.py,sha256=Z3AkPOQwjNF1ogo2DR18GN-CnYvI4MTmhsCe8hURKUo,883
2
2
  google/cloud/sql/connector/asyncpg.py,sha256=c4lAlvEgGf_eBq0G8MVNPRAJQQvo6DcwybiXDW36qkU,1838
3
- google/cloud/sql/connector/client.py,sha256=n1v6xxtfuvNZYCUfNUWY6FdNw9uvgOnmFxpSE0NmN5M,8263
4
- google/cloud/sql/connector/connector.py,sha256=Us4Yw8B6bTvNHn8F89O8tj5b6RqMnW5XR8pSbPMnOhc,15636
3
+ google/cloud/sql/connector/client.py,sha256=NZZnPqE_f13S04tpRCs0UGF-RxR4EL-_vH7ebQBXTaA,8494
4
+ google/cloud/sql/connector/connector.py,sha256=WYWP5zUqGSgxWNARaVHO1720REVX-EdD5D4rmBw0Mbw,19188
5
5
  google/cloud/sql/connector/exceptions.py,sha256=rTBtbCoiZ3U5IFVsyXPw5baHbCODixx2hPDQeXUzgzs,1524
6
- google/cloud/sql/connector/instance.py,sha256=ZLOyMoqHm7dehgvTkO4ul9DORHxwePt78O6mYsnR0Z4,14432
6
+ google/cloud/sql/connector/instance.py,sha256=G7-SCqsLjZiOYZ-Ds2RIErs6oaT0ewnAN683fs7EebI,14920
7
7
  google/cloud/sql/connector/pg8000.py,sha256=EZuO7XgCkG_Y79NQlh3Vv8Ff2w85BFJyFVO237hx1GM,1814
8
8
  google/cloud/sql/connector/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  google/cloud/sql/connector/pymysql.py,sha256=wldUgwDPlPa8Nj5F3JaipuP8hJyvzlgOAJbRnOoaB1U,2105
@@ -11,9 +11,9 @@ google/cloud/sql/connector/pytds.py,sha256=vKJoE7E2P0GrhZojg8bGZkqCMLc8dgKAcXE4e
11
11
  google/cloud/sql/connector/rate_limiter.py,sha256=bPTupfM4f5QRSCmCAWMqjQylEB7bUM-50plVBU3W2CA,2993
12
12
  google/cloud/sql/connector/refresh_utils.py,sha256=P2ye3qDymdK1iOlGCXby4VIaqwvHdc9GEmuUsMcufxY,3680
13
13
  google/cloud/sql/connector/utils.py,sha256=FQs7RgoViJLIFgJIynVT-_DwAVWnpyXIKu5WZ4m10Ts,3448
14
- google/cloud/sql/connector/version.py,sha256=5_sx8G8Z2yXRHtm-eIsT3EeQQ6YXb_CPOYOw5xgs-AM,597
15
- cloud_sql_python_connector-1.7.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
16
- cloud_sql_python_connector-1.7.0.dist-info/METADATA,sha256=YKaK1VB25XvtfIwC0PqsBfxFP4YSYjfDdZuWhcXyEiQ,24195
17
- cloud_sql_python_connector-1.7.0.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
18
- cloud_sql_python_connector-1.7.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
19
- cloud_sql_python_connector-1.7.0.dist-info/RECORD,,
14
+ google/cloud/sql/connector/version.py,sha256=YbELZlL2XCm9DhI5YdFuGTTRXdNla7msYYRyECFExSQ,597
15
+ cloud_sql_python_connector-1.9.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
16
+ cloud_sql_python_connector-1.9.0.dist-info/METADATA,sha256=20TIdOSzRhkL8LmlNEH8pFpqv2EXtwUxoJKBEudmwps,24102
17
+ cloud_sql_python_connector-1.9.0.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
18
+ cloud_sql_python_connector-1.9.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
19
+ cloud_sql_python_connector-1.9.0.dist-info/RECORD,,
@@ -31,13 +31,14 @@ if TYPE_CHECKING:
31
31
 
32
32
  USER_AGENT: str = f"cloud-sql-python-connector/{version}"
33
33
  API_VERSION: str = "v1beta4"
34
+ DEFAULT_SERVICE_ENDPOINT: str = "https://sqladmin.googleapis.com"
34
35
 
35
36
  logger = logging.getLogger(name=__name__)
36
37
 
37
38
 
38
39
  def _format_user_agent(driver: Optional[str], custom: Optional[str]) -> str:
39
40
  agent = f"{USER_AGENT}+{driver}" if driver else USER_AGENT
40
- if custom:
41
+ if custom and isinstance(custom, str):
41
42
  agent = f"{agent} {custom}"
42
43
  return agent
43
44
 
@@ -45,7 +46,7 @@ def _format_user_agent(driver: Optional[str], custom: Optional[str]) -> str:
45
46
  class CloudSQLClient:
46
47
  def __init__(
47
48
  self,
48
- sqladmin_api_endpoint: str,
49
+ sqladmin_api_endpoint: Optional[str],
49
50
  quota_project: Optional[str],
50
51
  credentials: Credentials,
51
52
  client: Optional[aiohttp.ClientSession] = None,
@@ -81,7 +82,10 @@ class CloudSQLClient:
81
82
 
82
83
  self._client = client if client else aiohttp.ClientSession(headers=headers)
83
84
  self._credentials = credentials
84
- self._sqladmin_api_endpoint = sqladmin_api_endpoint
85
+ if sqladmin_api_endpoint is None:
86
+ self._sqladmin_api_endpoint = DEFAULT_SERVICE_ENDPOINT
87
+ else:
88
+ self._sqladmin_api_endpoint = sqladmin_api_endpoint
85
89
  self._user_agent = user_agent
86
90
 
87
91
  async def _get_metadata(
@@ -43,59 +43,62 @@ from google.cloud.sql.connector.utils import generate_keys
43
43
  logger = logging.getLogger(name=__name__)
44
44
 
45
45
  ASYNC_DRIVERS = ["asyncpg"]
46
+ _DEFAULT_SCHEME = "https://"
47
+ _DEFAULT_UNIVERSE_DOMAIN = "googleapis.com"
48
+ _SQLADMIN_HOST_TEMPLATE = "sqladmin.{universe_domain}"
46
49
 
47
50
 
48
51
  class Connector:
49
- """A class to configure and create connections to Cloud SQL instances.
50
-
51
- :type ip_type: IPTypes
52
- :param ip_type
53
- The IP type (public or private) used to connect. IP types
54
- can be either IPTypes.PUBLIC or IPTypes.PRIVATE.
55
-
56
- :type enable_iam_auth: bool
57
- :param enable_iam_auth
58
- Enables automatic IAM database authentication for Postgres or MySQL
59
- instances.
60
-
61
- :type timeout: int
62
- :param timeout
63
- The time limit for a connection before raising a TimeoutError.
64
-
65
- :type credentials: google.auth.credentials.Credentials
66
- :param credentials
67
- Credentials object used to authenticate connections to Cloud SQL server.
68
- If not specified, Application Default Credentials are used.
69
-
70
- :type quota_project: str
71
- :param quota_project
72
- The Project ID for an existing Google Cloud project. The project specified
73
- is used for quota and billing purposes. If not specified, defaults to
74
- project sourced from environment.
75
-
76
- :type loop: asyncio.AbstractEventLoop
77
- :param loop
78
- Event loop to run asyncio tasks, if not specified, defaults to
79
- creating new event loop on background thread.
80
-
81
- :type sqladmin_api_endpoint: str
82
- :param sqladmin_api_endpoint:
83
- Base URL to use when calling the Cloud SQL Admin API endpoint.
84
- Defaults to "https://sqladmin.googleapis.com", this argument should
85
- only be used in development.
86
- """
52
+ """Configure and create secure connections to Cloud SQL."""
87
53
 
88
54
  def __init__(
89
55
  self,
90
- ip_type: IPTypes = IPTypes.PUBLIC,
56
+ ip_type: str | IPTypes = IPTypes.PUBLIC,
91
57
  enable_iam_auth: bool = False,
92
58
  timeout: int = 30,
93
59
  credentials: Optional[Credentials] = None,
94
60
  loop: Optional[asyncio.AbstractEventLoop] = None,
95
61
  quota_project: Optional[str] = None,
96
- sqladmin_api_endpoint: str = "https://sqladmin.googleapis.com",
62
+ sqladmin_api_endpoint: Optional[str] = None,
97
63
  user_agent: Optional[str] = None,
64
+ universe_domain: Optional[str] = None,
98
65
  ) -> None:
66
+ """Initializes a Connector instance.
67
+
68
+ Args:
69
+ ip_type (str | IPTypes): The default IP address type used to connect to
70
+ Cloud SQL instances. Can be one of the following:
71
+ IPTypes.PUBLIC ("PUBLIC"), IPTypes.PRIVATE ("PRIVATE"), or
72
+ IPTypes.PSC ("PSC"). Default: IPTypes.PUBLIC
73
+
74
+ enable_iam_auth (bool): Enables automatic IAM database authentication
75
+ (Postgres and MySQL) as the default authentication method for all
76
+ connections.
77
+
78
+ timeout (int): The default time limit in seconds for a connection before
79
+ raising a TimeoutError.
80
+
81
+ credentials (google.auth.credentials.Credentials): A credentials object
82
+ created from the google-auth Python library to be used.
83
+ If not specified, Application Default Credentials (ADC) are used.
84
+
85
+ quota_project (str): The Project ID for an existing Google Cloud
86
+ project. The project specified is used for quota and billing
87
+ purposes. If not specified, defaults to project sourced from
88
+ environment.
89
+
90
+ loop (asyncio.AbstractEventLoop): Event loop to run asyncio tasks, if
91
+ not specified, defaults to creating new event loop on background
92
+ thread.
93
+
94
+ sqladmin_api_endpoint (str): Base URL to use when calling the Cloud SQL
95
+ Admin API endpoint. Defaults to "https://sqladmin.googleapis.com",
96
+ this argument should only be used in development.
97
+
98
+ universe_domain (str): The universe domain for Cloud SQL API calls.
99
+ Default: "googleapis.com".
100
+
101
+ """
99
102
  # if event loop is given, use for background tasks
100
103
  if loop:
101
104
  self._loop: asyncio.AbstractEventLoop = loop
@@ -130,36 +133,66 @@ class Connector:
130
133
  # set default params for connections
131
134
  self._timeout = timeout
132
135
  self._enable_iam_auth = enable_iam_auth
133
- self._ip_type = ip_type
134
136
  self._quota_project = quota_project
135
- self._sqladmin_api_endpoint = sqladmin_api_endpoint
136
137
  self._user_agent = user_agent
138
+ # if ip_type is str, convert to IPTypes enum
139
+ if isinstance(ip_type, str):
140
+ ip_type = IPTypes._from_str(ip_type)
141
+ self._ip_type = ip_type
142
+ self._universe_domain = universe_domain
143
+ # construct service endpoint for Cloud SQL Admin API calls
144
+ if not sqladmin_api_endpoint:
145
+ self._sqladmin_api_endpoint = (
146
+ _DEFAULT_SCHEME
147
+ + _SQLADMIN_HOST_TEMPLATE.format(universe_domain=self.universe_domain)
148
+ )
149
+ # otherwise if endpoint override is passed in use it
150
+ else:
151
+ self._sqladmin_api_endpoint = sqladmin_api_endpoint
152
+
153
+ # validate that the universe domain of the credentials matches the
154
+ # universe domain of the service endpoint
155
+ if self._credentials.universe_domain != self.universe_domain:
156
+ raise ValueError(
157
+ f"The configured universe domain ({self.universe_domain}) does "
158
+ "not match the universe domain found in the credentials "
159
+ f"({self._credentials.universe_domain}). If you haven't "
160
+ "configured the universe domain explicitly, `googleapis.com` "
161
+ "is the default."
162
+ )
163
+
164
+ @property
165
+ def universe_domain(self) -> str:
166
+ return self._universe_domain or _DEFAULT_UNIVERSE_DOMAIN
137
167
 
138
168
  def connect(
139
169
  self, instance_connection_string: str, driver: str, **kwargs: Any
140
170
  ) -> Any:
141
- """Prepares and returns a database connection object and starts a
142
- background task to refresh the certificates and metadata.
171
+ """Connect to a Cloud SQL instance.
172
+
173
+ Prepares and returns a database connection object connected to a Cloud
174
+ SQL instance using SSL/TLS. Starts a background refresh to periodically
175
+ retrieve up-to-date ephemeral certificate and instance metadata.
143
176
 
144
- :type instance_connection_string: str
145
- :param instance_connection_string:
146
- A string containing the GCP project name, region name, and instance
147
- name separated by colons.
177
+ Args:
178
+ instance_connection_string (str): The instance connection name of the
179
+ Cloud SQL instance to connect to. Takes the form of
180
+ "project-id:region:instance-name"
148
181
 
149
- Example: example-proj:example-region-us6:example-instance
182
+ Example: "my-project:us-central1:my-instance"
150
183
 
151
- :type driver: str
152
- :param: driver:
153
- A string representing the driver to connect with. Supported drivers are
154
- pymysql, pg8000, and pytds.
184
+ driver (str): A string representing the database driver to connect
185
+ with. Supported drivers are pymysql, pg8000, and pytds.
155
186
 
156
- :param kwargs:
157
- Pass in any driver-specific arguments needed to connect to the Cloud
158
- SQL instance.
187
+ **kwargs: Any driver-specific arguments to pass to the underlying
188
+ driver .connect call.
159
189
 
160
- :rtype: Connection
161
- :returns:
190
+ Returns:
162
191
  A DB-API connection to the specified Cloud SQL instance.
192
+
193
+ Raises:
194
+ ConnectorLoopError: Event loop for background refresh is running in
195
+ current thread. Error instead of hanging indefinitely.
163
196
  """
164
197
  try:
165
198
  # check if event loop is running in current thread
@@ -181,35 +214,37 @@ class Connector:
181
214
  async def connect_async(
182
215
  self, instance_connection_string: str, driver: str, **kwargs: Any
183
216
  ) -> Any:
184
- """Prepares and returns a database connection object and starts a
185
- background task to refresh the certificates and metadata.
217
+ """Connect asynchronously to a Cloud SQL instance.
218
+
219
+ Prepares and returns a database connection object connected to a Cloud
220
+ SQL instance using SSL/TLS. Schedules a refresh to periodically
221
+ retrieve up-to-date ephemeral certificate and instance metadata. Async
222
+ version of Connector.connect.
186
223
 
187
- :type instance_connection_string: str
188
- :param instance_connection_string:
189
- A string containing the GCP project name, region name, and instance
190
- name separated by colons.
224
+ Args:
225
+ instance_connection_string (str): The instance connection name of the
226
+ Cloud SQL instance to connect to. Takes the form of
227
+ "project-id:region:instance-name"
191
228
 
192
- Example: example-proj:example-region-us6:example-instance
229
+ Example: "my-project:us-central1:my-instance"
193
230
 
194
- :type driver: str
195
- :param: driver:
196
- A string representing the driver to connect with. Supported drivers are
197
- pymysql, pg8000, asyncpg, and pytds.
231
+ driver (str): A string representing the database driver to connect
232
+ with. Supported drivers are pymysql, asyncpg, pg8000, and pytds.
198
233
 
199
- :param kwargs:
200
- Pass in any driver-specific arguments needed to connect to the Cloud
201
- SQL instance.
234
+ **kwargs: Any driver-specific arguments to pass to the underlying
235
+ driver .connect call.
202
236
 
203
- :rtype: Connection
204
- :returns:
237
+ Returns:
205
238
  A DB-API connection to the specified Cloud SQL instance.
239
+
240
+ Raises:
241
+ ValueError: Connection attempt with built-in database authentication
242
+ and then subsequent attempt with IAM database authentication.
243
+ KeyError: Unsupported database driver Must be one of pymysql, asyncpg,
244
+ pg8000, and pytds.
245
+ DnsNameResolutionError: Could not resolve PSC IP address from DNS
246
+ host name.
206
247
  """
207
- # Create an Instance object from the connection string.
208
- # The Instance should verify arguments.
209
- #
210
- # Use the Instance to establish an SSL Connection.
211
- #
212
- # Return a DBAPI connection
213
248
  if self._client is None:
214
249
  # lazy init client as it has to be initialized in async context
215
250
  self._client = CloudSQLClient(
@@ -252,6 +287,9 @@ class Connector:
252
287
  raise KeyError(f"Driver '{driver}' is not supported.")
253
288
 
254
289
  ip_type = kwargs.pop("ip_type", self._ip_type)
290
+ # if ip_type is str, convert to IPTypes enum
291
+ if isinstance(ip_type, str):
292
+ ip_type = IPTypes._from_str(ip_type)
255
293
  kwargs["timeout"] = kwargs.get("timeout", self._timeout)
256
294
 
257
295
  # Host and ssl options come from the certificates and metadata, so we don't
@@ -357,41 +395,64 @@ class Connector:
357
395
 
358
396
 
359
397
  async def create_async_connector(
360
- ip_type: IPTypes = IPTypes.PUBLIC,
398
+ ip_type: str | IPTypes = IPTypes.PUBLIC,
361
399
  enable_iam_auth: bool = False,
362
400
  timeout: int = 30,
363
401
  credentials: Optional[Credentials] = None,
364
402
  loop: Optional[asyncio.AbstractEventLoop] = None,
403
+ quota_project: Optional[str] = None,
404
+ sqladmin_api_endpoint: Optional[str] = None,
405
+ user_agent: Optional[str] = None,
406
+ universe_domain: Optional[str] = None,
365
407
  ) -> Connector:
366
- """
367
- Create Connector object for asyncio connections that can auto-detect
368
- and use current thread's running event loop.
369
-
370
- :type ip_type: IPTypes
371
- :param ip_type
372
- The IP type (public or private) used to connect. IP types
373
- can be either IPTypes.PUBLIC or IPTypes.PRIVATE.
374
-
375
- :type enable_iam_auth: bool
376
- :param enable_iam_auth
377
- Enables automatic IAM database authentication for Postgres or MySQL
378
- instances.
379
-
380
- :type timeout: int
381
- :param timeout
382
- The time limit for a connection before raising a TimeoutError.
383
-
384
- :type credentials: google.auth.credentials.Credentials
385
- :param credentials
386
- Credentials object used to authenticate connections to Cloud SQL server.
387
- If not specified, Application Default Credentials are used.
388
-
389
- :type loop: asyncio.AbstractEventLoop
390
- :param loop
391
- Event loop to run asyncio tasks, if not specified, defaults
392
- to current thread's running event loop.
408
+ """Helper function to create Connector object for asyncio connections.
409
+
410
+ Force use of Connector in an asyncio context. Auto-detect and use current
411
+ thread's running event loop.
412
+
413
+ Args:
414
+ ip_type (str | IPTypes): The default IP address type used to connect to
415
+ Cloud SQL instances. Can be one of the following:
416
+ IPTypes.PUBLIC ("PUBLIC"), IPTypes.PRIVATE ("PRIVATE"), or
417
+ IPTypes.PSC ("PSC"). Default: IPTypes.PUBLIC
418
+
419
+ enable_iam_auth (bool): Enables automatic IAM database authentication
420
+ (Postgres and MySQL) as the default authentication method for all
421
+ connections.
422
+
423
+ timeout (int): The default time limit in seconds for a connection before
424
+ raising a TimeoutError.
425
+
426
+ credentials (google.auth.credentials.Credentials): A credentials object
427
+ created from the google-auth Python library to be used.
428
+ If not specified, Application Default Credentials (ADC) are used.
429
+
430
+ quota_project (str): The Project ID for an existing Google Cloud
431
+ project. The project specified is used for quota and billing
432
+ purposes. If not specified, defaults to project sourced from
433
+ environment.
434
+
435
+ loop (asyncio.AbstractEventLoop): Event loop to run asyncio tasks, if
436
+ not specified, defaults to creating new event loop on background
437
+ thread.
438
+
439
+ sqladmin_api_endpoint (str): Base URL to use when calling the Cloud SQL
440
+ Admin API endpoint. Defaults to "https://sqladmin.googleapis.com",
441
+ this argument should only be used in development.
442
+
443
+ Returns:
444
+ A Connector instance configured with running event loop.
393
445
  """
394
446
  # if no loop given, automatically detect running event loop
395
447
  if loop is None:
396
448
  loop = asyncio.get_running_loop()
397
- return Connector(ip_type, enable_iam_auth, timeout, credentials, loop)
449
+ return Connector(
450
+ ip_type=ip_type,
451
+ enable_iam_auth=enable_iam_auth,
452
+ timeout=timeout,
453
+ credentials=credentials,
454
+ loop=loop,
455
+ quota_project=quota_project,
456
+ sqladmin_api_endpoint=sqladmin_api_endpoint,
457
+ user_agent=user_agent,
458
+ )
@@ -64,6 +64,20 @@ class IPTypes(Enum):
64
64
  PRIVATE: str = "PRIVATE"
65
65
  PSC: str = "PSC"
66
66
 
67
+ @classmethod
68
+ def _missing_(cls, value: object) -> None:
69
+ raise ValueError(
70
+ f"Incorrect value for ip_type, got '{value}'. Want one of: "
71
+ f"{', '.join([repr(m.value) for m in cls])}, 'PUBLIC'."
72
+ )
73
+
74
+ @classmethod
75
+ def _from_str(cls, ip_type_str: str) -> IPTypes:
76
+ """Convert IP type from a str into IPTypes."""
77
+ if ip_type_str.upper() == "PUBLIC":
78
+ ip_type_str = "PRIMARY"
79
+ return cls(ip_type_str.upper())
80
+
67
81
 
68
82
  class ConnectionInfo:
69
83
  ip_addrs: Dict[str, Any]
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "1.7.0"
15
+ __version__ = "1.9.0"