cloud-sql-python-connector 1.9.1__tar.gz → 1.9.2__tar.gz

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.
Files changed (25) hide show
  1. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/PKG-INFO +1 -1
  2. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/cloud_sql_python_connector.egg-info/PKG-INFO +1 -1
  3. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/connector.py +12 -14
  4. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/instance.py +37 -46
  5. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/version.py +1 -1
  6. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/LICENSE +0 -0
  7. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/README.md +0 -0
  8. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/cloud_sql_python_connector.egg-info/SOURCES.txt +0 -0
  9. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/cloud_sql_python_connector.egg-info/dependency_links.txt +0 -0
  10. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/cloud_sql_python_connector.egg-info/not-zip-safe +0 -0
  11. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/cloud_sql_python_connector.egg-info/requires.txt +0 -0
  12. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/cloud_sql_python_connector.egg-info/top_level.txt +0 -0
  13. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/__init__.py +0 -0
  14. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/asyncpg.py +0 -0
  15. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/client.py +0 -0
  16. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/exceptions.py +0 -0
  17. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/pg8000.py +0 -0
  18. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/py.typed +0 -0
  19. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/pymysql.py +0 -0
  20. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/pytds.py +0 -0
  21. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/rate_limiter.py +0 -0
  22. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/refresh_utils.py +0 -0
  23. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/google/cloud/sql/connector/utils.py +0 -0
  24. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/setup.cfg +0 -0
  25. {cloud-sql-python-connector-1.9.1 → cloud-sql-python-connector-1.9.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cloud-sql-python-connector
3
- Version: 1.9.1
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cloud-sql-python-connector
3
- Version: 1.9.1
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
@@ -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._instances: Dict[str, Instance] = {}
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._instances:
259
- instance = self._instances[instance_connection_string]
260
- if enable_iam_auth != instance._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={instance._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
- instance = Instance(
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._instances[instance_connection_string] = instance
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 instance.connect_info(ip_type)
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 instance.force_refresh()
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 Instances' tasks
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 Instance:
148
- """A class to manage the details of the connection to a Cloud SQL
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
- _refresh_rate_limiter: AsyncRateLimiter
170
- _refresh_in_progress: asyncio.locks.Event
171
- _current: asyncio.Task # task wraps coroutine that returns ConnectionInfo
172
- _next: asyncio.Task # task wraps coroutine that returns another task
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
- :rtype: ConnectionInfo
215
- :returns: A dataclass containing a string representing the ephemeral certificate, a dict
216
- containing the instances IP adresses, a string representing a PEM-encoded private key
217
- and a string representing a PEM-encoded certificate authority.
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
- :type delay: int
294
- :param delay
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
- :rtype: asyncio.Task
298
- :returns: A Task representing the scheduled _perform_refresh.
290
+ Returns:
291
+ An asyncio.Task representing the scheduled refresh.
299
292
  """
300
293
 
301
- async def _refresh_task(self: Instance, delay: int) -> ConnectionInfo:
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
- :type ip_type: IPTypes
353
- :param ip_type: Enum specifying whether to look for public
354
- or private IP address.
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
- :rtype ip_address: str
360
- :returns: A string representing the IP address of
361
- the given Cloud SQL instance.
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"
@@ -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.9.1"
15
+ __version__ = "1.9.2"