cloud-sql-python-connector 1.9.1__py2.py3-none-any.whl → 1.9.2__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.
- {cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/METADATA +1 -1
- {cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/RECORD +8 -8
- google/cloud/sql/connector/connector.py +12 -14
- google/cloud/sql/connector/instance.py +37 -46
- google/cloud/sql/connector/version.py +1 -1
- {cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/LICENSE +0 -0
- {cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/WHEEL +0 -0
- {cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/top_level.txt +0 -0
{cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cloud-sql-python-connector
|
|
3
|
-
Version: 1.9.
|
|
3
|
+
Version: 1.9.2
|
|
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
|
{cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/RECORD
RENAMED
|
@@ -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
3
|
google/cloud/sql/connector/client.py,sha256=NZZnPqE_f13S04tpRCs0UGF-RxR4EL-_vH7ebQBXTaA,8494
|
|
4
|
-
google/cloud/sql/connector/connector.py,sha256=
|
|
4
|
+
google/cloud/sql/connector/connector.py,sha256=q1P0lqDjU5O5U8FQjNa9punrdExwcjvVz7SodbaVmSw,19147
|
|
5
5
|
google/cloud/sql/connector/exceptions.py,sha256=rTBtbCoiZ3U5IFVsyXPw5baHbCODixx2hPDQeXUzgzs,1524
|
|
6
|
-
google/cloud/sql/connector/instance.py,sha256=
|
|
6
|
+
google/cloud/sql/connector/instance.py,sha256=Oed1kFTaVolce74DzsSRbooj6mUthwZtt75OamTfOQs,14966
|
|
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=
|
|
15
|
-
cloud_sql_python_connector-1.9.
|
|
16
|
-
cloud_sql_python_connector-1.9.
|
|
17
|
-
cloud_sql_python_connector-1.9.
|
|
18
|
-
cloud_sql_python_connector-1.9.
|
|
19
|
-
cloud_sql_python_connector-1.9.
|
|
14
|
+
google/cloud/sql/connector/version.py,sha256=x6crtIS26FuBXZ_fZ636i8UD16NlwWdlYJf5SEIqLIc,597
|
|
15
|
+
cloud_sql_python_connector-1.9.2.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
16
|
+
cloud_sql_python_connector-1.9.2.dist-info/METADATA,sha256=5ufJWE8PP34QHa8_1oh1vPJmzaOY-Byqfso7o_BbCnw,24113
|
|
17
|
+
cloud_sql_python_connector-1.9.2.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
|
|
18
|
+
cloud_sql_python_connector-1.9.2.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
|
19
|
+
cloud_sql_python_connector-1.9.2.dist-info/RECORD,,
|
|
@@ -32,8 +32,8 @@ import google.cloud.sql.connector.asyncpg as asyncpg
|
|
|
32
32
|
from google.cloud.sql.connector.client import CloudSQLClient
|
|
33
33
|
from google.cloud.sql.connector.exceptions import ConnectorLoopError
|
|
34
34
|
from google.cloud.sql.connector.exceptions import DnsNameResolutionError
|
|
35
|
-
from google.cloud.sql.connector.instance import Instance
|
|
36
35
|
from google.cloud.sql.connector.instance import IPTypes
|
|
36
|
+
from google.cloud.sql.connector.instance import RefreshAheadCache
|
|
37
37
|
import google.cloud.sql.connector.pg8000 as pg8000
|
|
38
38
|
import google.cloud.sql.connector.pymysql as pymysql
|
|
39
39
|
import google.cloud.sql.connector.pytds as pytds
|
|
@@ -113,7 +113,7 @@ class Connector:
|
|
|
113
113
|
asyncio.run_coroutine_threadsafe(generate_keys(), self._loop),
|
|
114
114
|
loop=self._loop,
|
|
115
115
|
)
|
|
116
|
-
self.
|
|
116
|
+
self._cache: Dict[str, RefreshAheadCache] = {}
|
|
117
117
|
self._client: Optional[CloudSQLClient] = None
|
|
118
118
|
|
|
119
119
|
# initialize credentials
|
|
@@ -255,23 +255,23 @@ class Connector:
|
|
|
255
255
|
driver=driver,
|
|
256
256
|
)
|
|
257
257
|
enable_iam_auth = kwargs.pop("enable_iam_auth", self._enable_iam_auth)
|
|
258
|
-
if instance_connection_string in self.
|
|
259
|
-
|
|
260
|
-
if enable_iam_auth !=
|
|
258
|
+
if instance_connection_string in self._cache:
|
|
259
|
+
cache = self._cache[instance_connection_string]
|
|
260
|
+
if enable_iam_auth != cache._enable_iam_auth:
|
|
261
261
|
raise ValueError(
|
|
262
262
|
f"connect() called with 'enable_iam_auth={enable_iam_auth}', "
|
|
263
|
-
f"but previously used 'enable_iam_auth={
|
|
263
|
+
f"but previously used 'enable_iam_auth={cache._enable_iam_auth}'. "
|
|
264
264
|
"If you require both for your use case, please use a new "
|
|
265
265
|
"connector.Connector object."
|
|
266
266
|
)
|
|
267
267
|
else:
|
|
268
|
-
|
|
268
|
+
cache = RefreshAheadCache(
|
|
269
269
|
instance_connection_string,
|
|
270
270
|
self._client,
|
|
271
271
|
self._keys,
|
|
272
272
|
enable_iam_auth,
|
|
273
273
|
)
|
|
274
|
-
self.
|
|
274
|
+
self._cache[instance_connection_string] = cache
|
|
275
275
|
|
|
276
276
|
connect_func = {
|
|
277
277
|
"pymysql": pymysql.connect,
|
|
@@ -300,7 +300,7 @@ class Connector:
|
|
|
300
300
|
|
|
301
301
|
# attempt to make connection to Cloud SQL instance
|
|
302
302
|
try:
|
|
303
|
-
instance_data, ip_address = await
|
|
303
|
+
instance_data, ip_address = await cache.connect_info(ip_type)
|
|
304
304
|
# resolve DNS name into IP address for PSC
|
|
305
305
|
if ip_type.value == "PSC":
|
|
306
306
|
addr_info = await self._loop.getaddrinfo(
|
|
@@ -339,7 +339,7 @@ class Connector:
|
|
|
339
339
|
|
|
340
340
|
except Exception:
|
|
341
341
|
# with any exception, we attempt a force refresh, then throw the error
|
|
342
|
-
await
|
|
342
|
+
await cache.force_refresh()
|
|
343
343
|
raise
|
|
344
344
|
|
|
345
345
|
def __enter__(self) -> Any:
|
|
@@ -385,11 +385,9 @@ class Connector:
|
|
|
385
385
|
self._thread.join()
|
|
386
386
|
|
|
387
387
|
async def close_async(self) -> None:
|
|
388
|
-
"""Helper function to cancel
|
|
388
|
+
"""Helper function to cancel the cache's tasks
|
|
389
389
|
and close aiohttp.ClientSession."""
|
|
390
|
-
await asyncio.gather(
|
|
391
|
-
*[instance.close() for instance in self._instances.values()]
|
|
392
|
-
)
|
|
390
|
+
await asyncio.gather(*[cache.close() for cache in self._cache.values()])
|
|
393
391
|
if self._client:
|
|
394
392
|
await self._client.close()
|
|
395
393
|
|
|
@@ -144,32 +144,13 @@ class ConnectionInfo:
|
|
|
144
144
|
)
|
|
145
145
|
|
|
146
146
|
|
|
147
|
-
class
|
|
148
|
-
"""
|
|
149
|
-
instance, including refreshing the credentials.
|
|
150
|
-
|
|
151
|
-
:param instance_connection_string:
|
|
152
|
-
The Google Cloud SQL Instance's connection
|
|
153
|
-
string.
|
|
154
|
-
:type instance_connection_string: str
|
|
155
|
-
|
|
156
|
-
:param enable_iam_auth
|
|
157
|
-
Enables automatic IAM database authentication for Postgres or MySQL
|
|
158
|
-
instances.
|
|
159
|
-
:type enable_iam_auth: bool
|
|
160
|
-
"""
|
|
161
|
-
|
|
162
|
-
_enable_iam_auth: bool
|
|
163
|
-
_keys: asyncio.Future
|
|
164
|
-
_instance_connection_string: str
|
|
165
|
-
_instance: str
|
|
166
|
-
_project: str
|
|
167
|
-
_region: str
|
|
147
|
+
class RefreshAheadCache:
|
|
148
|
+
"""Cache that refreshes connection info in the background prior to expiration.
|
|
168
149
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
150
|
+
Background tasks are used to schedule refresh attempts to get a new
|
|
151
|
+
ephemeral certificate and Cloud SQL metadata (IP addresses, etc.) ahead of
|
|
152
|
+
expiration.
|
|
153
|
+
"""
|
|
173
154
|
|
|
174
155
|
def __init__(
|
|
175
156
|
self,
|
|
@@ -178,6 +159,18 @@ class Instance:
|
|
|
178
159
|
keys: asyncio.Future,
|
|
179
160
|
enable_iam_auth: bool = False,
|
|
180
161
|
) -> None:
|
|
162
|
+
"""Initializes a RefreshAheadCache instance.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
instance_connection_string (str): The Cloud SQL Instance's
|
|
166
|
+
connection string (also known as an instance connection name).
|
|
167
|
+
client (CloudSQLClient): The Cloud SQL Client instance.
|
|
168
|
+
keys (asyncio.Future): A future to the client's public-private key
|
|
169
|
+
pair.
|
|
170
|
+
enable_iam_auth (bool): Enables automatic IAM database authentication
|
|
171
|
+
(Postgres and MySQL) as the default authentication method for all
|
|
172
|
+
connections.
|
|
173
|
+
"""
|
|
181
174
|
# validate and parse instance connection name
|
|
182
175
|
self._project, self._region, self._instance = _parse_instance_connection_name(
|
|
183
176
|
instance_connection_string
|
|
@@ -192,8 +185,8 @@ class Instance:
|
|
|
192
185
|
rate=1 / 30,
|
|
193
186
|
)
|
|
194
187
|
self._refresh_in_progress = asyncio.locks.Event()
|
|
195
|
-
self._current = self._schedule_refresh(0)
|
|
196
|
-
self._next = self._current
|
|
188
|
+
self._current: asyncio.Task = self._schedule_refresh(0)
|
|
189
|
+
self._next: asyncio.Task = self._current
|
|
197
190
|
|
|
198
191
|
async def force_refresh(self) -> None:
|
|
199
192
|
"""
|
|
@@ -211,10 +204,11 @@ class Instance:
|
|
|
211
204
|
"""Retrieves instance metadata and ephemeral certificate from the
|
|
212
205
|
Cloud SQL Instance.
|
|
213
206
|
|
|
214
|
-
:
|
|
215
|
-
|
|
216
|
-
containing the instances IP adresses,
|
|
217
|
-
|
|
207
|
+
Returns:
|
|
208
|
+
A ConnectionInfo instance containing a string representing the
|
|
209
|
+
ephemeral certificate, a dict containing the instances IP adresses,
|
|
210
|
+
a string representing a PEM-encoded private key and a string
|
|
211
|
+
representing a PEM-encoded certificate authority.
|
|
218
212
|
"""
|
|
219
213
|
self._refresh_in_progress.set()
|
|
220
214
|
logger.debug(
|
|
@@ -290,15 +284,14 @@ class Instance:
|
|
|
290
284
|
"""
|
|
291
285
|
Schedule task to sleep and then perform refresh to get ConnectionInfo.
|
|
292
286
|
|
|
293
|
-
:
|
|
294
|
-
|
|
295
|
-
Time in seconds to sleep before running _perform_refresh.
|
|
287
|
+
Args:
|
|
288
|
+
delay (int): Time in seconds to sleep before performing a refresh.
|
|
296
289
|
|
|
297
|
-
:
|
|
298
|
-
|
|
290
|
+
Returns:
|
|
291
|
+
An asyncio.Task representing the scheduled refresh.
|
|
299
292
|
"""
|
|
300
293
|
|
|
301
|
-
async def _refresh_task(self:
|
|
294
|
+
async def _refresh_task(self: RefreshAheadCache, delay: int) -> ConnectionInfo:
|
|
302
295
|
"""
|
|
303
296
|
A coroutine that sleeps for the specified amount of time before
|
|
304
297
|
running _perform_refresh.
|
|
@@ -349,16 +342,14 @@ class Instance:
|
|
|
349
342
|
"""Retrieve instance metadata and ip address required
|
|
350
343
|
for making connection to Cloud SQL instance.
|
|
351
344
|
|
|
352
|
-
:
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
:rtype instance_data: ConnectionInfo
|
|
357
|
-
:returns: Instance metadata for Cloud SQL instance.
|
|
345
|
+
Args:
|
|
346
|
+
ip_type (IPTypes): Enum specifying type of IP address to lookup and
|
|
347
|
+
use for connection.
|
|
358
348
|
|
|
359
|
-
:
|
|
360
|
-
|
|
361
|
-
the
|
|
349
|
+
Returns:
|
|
350
|
+
A tuple with the first item being the ConnectionInfo instance for
|
|
351
|
+
establishing the connection, and the second item being the IP
|
|
352
|
+
address of the Cloud SQL instance matching the specified IP type.
|
|
362
353
|
"""
|
|
363
354
|
logger.debug(
|
|
364
355
|
f"['{self._instance_connection_string}']: Entered connect_info method"
|
{cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cloud_sql_python_connector-1.9.1.dist-info → cloud_sql_python_connector-1.9.2.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|