cloud-sql-python-connector 1.18.5__py3-none-any.whl → 1.20.0__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.
- {cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/METADATA +18 -5
- {cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/RECORD +9 -9
- google/cloud/sql/connector/connector.py +43 -1
- google/cloud/sql/connector/exceptions.py +7 -0
- google/cloud/sql/connector/resolver.py +12 -0
- google/cloud/sql/connector/version.py +1 -1
- {cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/WHEEL +0 -0
- {cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/licenses/LICENSE +0 -0
- {cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/top_level.txt +0 -0
{cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-sql-python-connector
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.20.0
|
|
4
4
|
Summary: Google Cloud SQL Python Connector library
|
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -387,14 +387,27 @@ conn = connector.connect(
|
|
|
387
387
|
)
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
-
### Using DNS domain names to identify instances
|
|
390
|
+
### Using Advanced Disaster Recovery and DNS domain names to identify instances
|
|
391
391
|
|
|
392
|
-
The connector can be configured to use DNS to look up an instance.
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
The connector can be configured to use DNS to look up an instance.
|
|
393
|
+
Use a DNS name managed by Cloud SQL [Advanced Disaster Recovery](https://docs.cloud.google.com/sql/docs/mysql/use-advanced-disaster-recovery),
|
|
394
|
+
or a domain name that you manage.
|
|
395
|
+
|
|
396
|
+
#### Using Advanced Recovery Write Endpoint DNS Name
|
|
397
|
+
|
|
398
|
+
[Advanced Disaster Recovery](https://docs.cloud.google.com/sql/docs/mysql/use-advanced-disaster-recovery)
|
|
399
|
+
creates geographically distributed replicas of your Cloud SQL database instance. When you perform
|
|
400
|
+
switchover or failover on the database instance, the connector will gracefully disconnect from the
|
|
401
|
+
old primary instance and reconnect to the new primary instance.
|
|
402
|
+
|
|
403
|
+
Follow the instructions in [Connect using Write Endpoint](https://docs.cloud.google.com/sql/docs/mysql/connect-to-instance-using-write-endpoint)
|
|
404
|
+
to get the write endpoint DNS name for your primary instance. Then, use this write endpoint DNS
|
|
405
|
+
name to configure the connector.
|
|
395
406
|
|
|
396
407
|
#### Configure your DNS Records
|
|
397
408
|
|
|
409
|
+
The connector may be configured to use DNS that you define as well.
|
|
410
|
+
|
|
398
411
|
Add a DNS TXT record for the Cloud SQL instance to a **private** DNS server
|
|
399
412
|
or a private Google Cloud DNS Zone used by your application.
|
|
400
413
|
|
{cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/RECORD
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
cloud_sql_python_connector-1.
|
|
1
|
+
cloud_sql_python_connector-1.20.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
2
2
|
google/cloud/sql/connector/__init__.py,sha256=w6w35V-m2QlpcL-ShKd2BvNF-xXOwJ2FoidE7npPE7c,1148
|
|
3
3
|
google/cloud/sql/connector/asyncpg.py,sha256=v4ohOnSYjHTOvJPhTE761xP1KKo4FUJQW_WAnNW_2g4,1918
|
|
4
4
|
google/cloud/sql/connector/client.py,sha256=uVOMnRe1AxiSh6BnK4-SuSYrRID_jnm7SgMMN6s5jp4,13076
|
|
5
5
|
google/cloud/sql/connector/connection_info.py,sha256=BSuW-ovtEUYTIvDzQkaE3GofCs3Xoi0TtztFaAq4Kvo,4868
|
|
6
6
|
google/cloud/sql/connector/connection_name.py,sha256=bI4M3Qa2mtBHyD08oF41FF5W9FBOXWu4dGGg50Na_A4,2606
|
|
7
|
-
google/cloud/sql/connector/connector.py,sha256=
|
|
7
|
+
google/cloud/sql/connector/connector.py,sha256=MqL4iX9xK0Vys59L0VQpxf4VY39UUyYeL7I3rnFYSdY,26792
|
|
8
8
|
google/cloud/sql/connector/enums.py,sha256=dVBS9eEWNrHtzze0AJlmtbdUogG3EocNWOQcI_8qPd0,2937
|
|
9
|
-
google/cloud/sql/connector/exceptions.py,sha256=
|
|
9
|
+
google/cloud/sql/connector/exceptions.py,sha256=BtuE5bkMLxNPYZo2SrFlRBHp3ueWKZ0otnPbfnvr2TM,2125
|
|
10
10
|
google/cloud/sql/connector/instance.py,sha256=jDEQf-OXFzqKO9a4bnzRQ0qUyO3_xKuiEIRWc_7wpyE,8694
|
|
11
11
|
google/cloud/sql/connector/lazy.py,sha256=oB6F-O2fk8ZguY4J7Vrts91bqbVb6P5wj72Lf6UJIQA,4948
|
|
12
12
|
google/cloud/sql/connector/monitored_cache.py,sha256=LFYjX8hsdN_Dt0cMwLSWgAhWWQpZ35qA0CLlpc6xhsE,5587
|
|
@@ -16,10 +16,10 @@ google/cloud/sql/connector/pymysql.py,sha256=PrTQ1lB5EWAcN4BPX_5hb-WerncS4X76bBk
|
|
|
16
16
|
google/cloud/sql/connector/pytds.py,sha256=KZxmJQQG9XfmsmUoEGX7RpMirWdoreJ2-_FuHO6Td-s,2280
|
|
17
17
|
google/cloud/sql/connector/rate_limiter.py,sha256=zqZ9pVXHan4LWoGT8Bq6U3HpZcrdzKhlXVYwsX3ftA0,2928
|
|
18
18
|
google/cloud/sql/connector/refresh_utils.py,sha256=jaYLHrKlJtqeZBM8gOrZtI-6mbh6-1PTi8o0aFGH5Yo,5151
|
|
19
|
-
google/cloud/sql/connector/resolver.py,sha256=
|
|
19
|
+
google/cloud/sql/connector/resolver.py,sha256=pKcdPCr0iwFwKf2cv0F3HtCyOWNas1JsrnRMOudnEr8,3714
|
|
20
20
|
google/cloud/sql/connector/utils.py,sha256=AA_oBBxRuULb7-hHHK8HQJU5fttzBpzdIZwMNZ5kNCM,3473
|
|
21
|
-
google/cloud/sql/connector/version.py,sha256=
|
|
22
|
-
cloud_sql_python_connector-1.
|
|
23
|
-
cloud_sql_python_connector-1.
|
|
24
|
-
cloud_sql_python_connector-1.
|
|
25
|
-
cloud_sql_python_connector-1.
|
|
21
|
+
google/cloud/sql/connector/version.py,sha256=2L1KkIvUJEP5w-XgkCMs-yRM0AiHFvPXOIdjsF6d1hs,598
|
|
22
|
+
cloud_sql_python_connector-1.20.0.dist-info/METADATA,sha256=tjuCIYWzWY8fVvVw_VPfQA8p6N_eZTCmRYxa542zuj8,31181
|
|
23
|
+
cloud_sql_python_connector-1.20.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
24
|
+
cloud_sql_python_connector-1.20.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
|
25
|
+
cloud_sql_python_connector-1.20.0.dist-info/RECORD,,
|
|
@@ -34,6 +34,7 @@ from google.cloud.sql.connector.client import CloudSQLClient
|
|
|
34
34
|
from google.cloud.sql.connector.enums import DriverMapping
|
|
35
35
|
from google.cloud.sql.connector.enums import IPTypes
|
|
36
36
|
from google.cloud.sql.connector.enums import RefreshStrategy
|
|
37
|
+
from google.cloud.sql.connector.exceptions import ClosedConnectorError
|
|
37
38
|
from google.cloud.sql.connector.exceptions import ConnectorLoopError
|
|
38
39
|
from google.cloud.sql.connector.instance import RefreshAheadCache
|
|
39
40
|
from google.cloud.sql.connector.lazy import LazyRefreshCache
|
|
@@ -155,6 +156,7 @@ class Connector:
|
|
|
155
156
|
# connection name string and enable_iam_auth boolean flag
|
|
156
157
|
self._cache: dict[tuple[str, bool], MonitoredCache] = {}
|
|
157
158
|
self._client: Optional[CloudSQLClient] = None
|
|
159
|
+
self._closed: bool = False
|
|
158
160
|
|
|
159
161
|
# initialize credentials
|
|
160
162
|
scopes = ["https://www.googleapis.com/auth/sqlservice.admin"]
|
|
@@ -244,6 +246,12 @@ class Connector:
|
|
|
244
246
|
# connect runs sync database connections on background thread.
|
|
245
247
|
# Async database connections should call 'connect_async' directly to
|
|
246
248
|
# avoid hanging indefinitely.
|
|
249
|
+
|
|
250
|
+
# Check if the connector is closed before attempting to connect.
|
|
251
|
+
if self._closed:
|
|
252
|
+
raise ClosedConnectorError(
|
|
253
|
+
"Connection attempt failed because the connector has already been closed."
|
|
254
|
+
)
|
|
247
255
|
connect_future = asyncio.run_coroutine_threadsafe(
|
|
248
256
|
self.connect_async(instance_connection_string, driver, **kwargs),
|
|
249
257
|
self._loop,
|
|
@@ -281,7 +289,13 @@ class Connector:
|
|
|
281
289
|
and then subsequent attempt with IAM database authentication.
|
|
282
290
|
KeyError: Unsupported database driver Must be one of pymysql, asyncpg,
|
|
283
291
|
pg8000, and pytds.
|
|
292
|
+
RuntimeError: Connector has been closed. Cannot connect using a closed
|
|
293
|
+
Connector.
|
|
284
294
|
"""
|
|
295
|
+
if self._closed:
|
|
296
|
+
raise ClosedConnectorError(
|
|
297
|
+
"Connection attempt failed because the connector has already been closed."
|
|
298
|
+
)
|
|
285
299
|
# check if event loop is running in current thread
|
|
286
300
|
if self._loop != asyncio.get_running_loop():
|
|
287
301
|
raise ConnectorLoopError(
|
|
@@ -376,6 +390,33 @@ class Connector:
|
|
|
376
390
|
# the cache and re-raise the error
|
|
377
391
|
await self._remove_cached(str(conn_name), enable_iam_auth)
|
|
378
392
|
raise
|
|
393
|
+
|
|
394
|
+
# If the connector is configured with a custom DNS name, attempt to use
|
|
395
|
+
# that DNS name to connect to the instance. Fall back to the metadata IP
|
|
396
|
+
# address if the DNS name does not resolve to an IP address.
|
|
397
|
+
if conn_info.conn_name.domain_name and isinstance(self._resolver, DnsResolver):
|
|
398
|
+
try:
|
|
399
|
+
ips = await self._resolver.resolve_a_record(conn_info.conn_name.domain_name)
|
|
400
|
+
if ips:
|
|
401
|
+
ip_address = ips[0]
|
|
402
|
+
logger.debug(
|
|
403
|
+
f"['{instance_connection_string}']: Custom DNS name "
|
|
404
|
+
f"'{conn_info.conn_name.domain_name}' resolved to '{ip_address}', "
|
|
405
|
+
"using it to connect"
|
|
406
|
+
)
|
|
407
|
+
else:
|
|
408
|
+
logger.debug(
|
|
409
|
+
f"['{instance_connection_string}']: Custom DNS name "
|
|
410
|
+
f"'{conn_info.conn_name.domain_name}' resolved but returned no "
|
|
411
|
+
f"entries, using '{ip_address}' from instance metadata"
|
|
412
|
+
)
|
|
413
|
+
except Exception as e:
|
|
414
|
+
logger.debug(
|
|
415
|
+
f"['{instance_connection_string}']: Custom DNS name "
|
|
416
|
+
f"'{conn_info.conn_name.domain_name}' did not resolve to an IP "
|
|
417
|
+
f"address: {e}, using '{ip_address}' from instance metadata"
|
|
418
|
+
)
|
|
419
|
+
|
|
379
420
|
logger.debug(f"['{conn_info.conn_name}']: Connecting to {ip_address}:3307")
|
|
380
421
|
# format `user` param for automatic IAM database authn
|
|
381
422
|
if enable_iam_auth:
|
|
@@ -477,9 +518,10 @@ class Connector:
|
|
|
477
518
|
async def close_async(self) -> None:
|
|
478
519
|
"""Helper function to cancel the cache's tasks
|
|
479
520
|
and close aiohttp.ClientSession."""
|
|
480
|
-
|
|
521
|
+
self._closed = True
|
|
481
522
|
if self._client:
|
|
482
523
|
await self._client.close()
|
|
524
|
+
await asyncio.gather(*[cache.close() for cache in self._cache.values()])
|
|
483
525
|
|
|
484
526
|
|
|
485
527
|
async def create_async_connector(
|
|
@@ -84,3 +84,10 @@ class CacheClosedError(Exception):
|
|
|
84
84
|
Exception to be raised when a ConnectionInfoCache can not be accessed after
|
|
85
85
|
it is closed.
|
|
86
86
|
"""
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ClosedConnectorError(Exception):
|
|
90
|
+
"""
|
|
91
|
+
Exception to be raised when a Connector is closed and connect method is
|
|
92
|
+
called on it.
|
|
93
|
+
"""
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from typing import List
|
|
16
|
+
|
|
15
17
|
import dns.asyncresolver
|
|
16
18
|
|
|
17
19
|
from google.cloud.sql.connector.connection_name import _is_valid_domain
|
|
@@ -53,6 +55,16 @@ class DnsResolver(dns.asyncresolver.Resolver):
|
|
|
53
55
|
)
|
|
54
56
|
return conn_name
|
|
55
57
|
|
|
58
|
+
async def resolve_a_record(self, dns: str) -> List[str]:
|
|
59
|
+
try:
|
|
60
|
+
# Attempt to query the A records.
|
|
61
|
+
records = await super().resolve(dns, "A", raise_on_no_answer=True)
|
|
62
|
+
# return IP addresses as strings
|
|
63
|
+
return [record.to_text() for record in records]
|
|
64
|
+
except Exception:
|
|
65
|
+
# On any error, return empty list
|
|
66
|
+
return []
|
|
67
|
+
|
|
56
68
|
async def query_dns(self, dns: str) -> ConnectionName:
|
|
57
69
|
try:
|
|
58
70
|
# Attempt to query the TXT records.
|
{cloud_sql_python_connector-1.18.5.dist-info → cloud_sql_python_connector-1.20.0.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|