cloud-sql-python-connector 1.18.0__py3-none-any.whl → 1.18.2__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.0.dist-info → cloud_sql_python_connector-1.18.2.dist-info}/METADATA +62 -127
- cloud_sql_python_connector-1.18.2.dist-info/RECORD +25 -0
- {cloud_sql_python_connector-1.18.0.dist-info → cloud_sql_python_connector-1.18.2.dist-info}/WHEEL +1 -1
- google/cloud/sql/connector/asyncpg.py +14 -13
- google/cloud/sql/connector/client.py +25 -34
- google/cloud/sql/connector/connector.py +0 -1
- google/cloud/sql/connector/pg8000.py +13 -11
- google/cloud/sql/connector/pymysql.py +12 -10
- google/cloud/sql/connector/pytds.py +10 -9
- google/cloud/sql/connector/rate_limiter.py +9 -17
- google/cloud/sql/connector/refresh_utils.py +13 -11
- google/cloud/sql/connector/resolver.py +2 -2
- google/cloud/sql/connector/utils.py +6 -8
- google/cloud/sql/connector/version.py +1 -1
- cloud_sql_python_connector-1.18.0.dist-info/RECORD +0 -25
- {cloud_sql_python_connector-1.18.0.dist-info → cloud_sql_python_connector-1.18.2.dist-info}/licenses/LICENSE +0 -0
- {cloud_sql_python_connector-1.18.0.dist-info → cloud_sql_python_connector-1.18.2.dist-info}/top_level.txt +0 -0
{cloud_sql_python_connector-1.18.0.dist-info → cloud_sql_python_connector-1.18.2.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-sql-python-connector
|
|
3
|
-
Version: 1.18.
|
|
3
|
+
Version: 1.18.2
|
|
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
|
|
@@ -165,21 +165,16 @@ import sqlalchemy
|
|
|
165
165
|
# initialize Connector object
|
|
166
166
|
connector = Connector()
|
|
167
167
|
|
|
168
|
-
#
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
# initialize SQLAlchemy connection pool with Connector
|
|
169
|
+
pool = sqlalchemy.create_engine(
|
|
170
|
+
"mysql+pymysql://",
|
|
171
|
+
creator=lambda: connector.connect(
|
|
171
172
|
"project:region:instance",
|
|
172
173
|
"pymysql",
|
|
173
174
|
user="my-user",
|
|
174
175
|
password="my-password",
|
|
175
176
|
db="my-db-name"
|
|
176
|
-
)
|
|
177
|
-
return conn
|
|
178
|
-
|
|
179
|
-
# create connection pool
|
|
180
|
-
pool = sqlalchemy.create_engine(
|
|
181
|
-
"mysql+pymysql://",
|
|
182
|
-
creator=getconn,
|
|
177
|
+
),
|
|
183
178
|
)
|
|
184
179
|
```
|
|
185
180
|
|
|
@@ -246,33 +241,21 @@ Connector as a context manager:
|
|
|
246
241
|
|
|
247
242
|
```python
|
|
248
243
|
from google.cloud.sql.connector import Connector
|
|
249
|
-
import pymysql
|
|
250
244
|
import sqlalchemy
|
|
251
245
|
|
|
252
|
-
#
|
|
253
|
-
|
|
254
|
-
#
|
|
255
|
-
|
|
256
|
-
|
|
246
|
+
# initialize Cloud SQL Python Connector as context manager
|
|
247
|
+
with Connector() as connector:
|
|
248
|
+
# initialize SQLAlchemy connection pool with Connector
|
|
249
|
+
pool = sqlalchemy.create_engine(
|
|
250
|
+
"mysql+pymysql://",
|
|
251
|
+
creator=lambda: connector.connect(
|
|
257
252
|
"project:region:instance",
|
|
258
253
|
"pymysql",
|
|
259
254
|
user="my-user",
|
|
260
255
|
password="my-password",
|
|
261
256
|
db="my-db-name"
|
|
262
|
-
)
|
|
263
|
-
return conn
|
|
264
|
-
|
|
265
|
-
# create connection pool
|
|
266
|
-
pool = sqlalchemy.create_engine(
|
|
267
|
-
"mysql+pymysql://",
|
|
268
|
-
creator=getconn,
|
|
257
|
+
),
|
|
269
258
|
)
|
|
270
|
-
return pool
|
|
271
|
-
|
|
272
|
-
# initialize Cloud SQL Python Connector as context manager
|
|
273
|
-
with Connector() as connector:
|
|
274
|
-
# initialize connection pool
|
|
275
|
-
pool = init_connection_pool(connector)
|
|
276
259
|
# insert statement
|
|
277
260
|
insert_stmt = sqlalchemy.text(
|
|
278
261
|
"INSERT INTO my_table (id, title) VALUES (:id, :title)",
|
|
@@ -440,30 +423,19 @@ from google.cloud.sql.connector import Connector, DnsResolver
|
|
|
440
423
|
import pymysql
|
|
441
424
|
import sqlalchemy
|
|
442
425
|
|
|
443
|
-
#
|
|
444
|
-
|
|
445
|
-
#
|
|
446
|
-
|
|
447
|
-
|
|
426
|
+
# initialize Cloud SQL Python Connector with `resolver=DnsResolver`
|
|
427
|
+
with Connector(resolver=DnsResolver) as connector:
|
|
428
|
+
# initialize SQLAlchemy connection pool with Connector
|
|
429
|
+
pool = sqlalchemy.create_engine(
|
|
430
|
+
"mysql+pymysql://",
|
|
431
|
+
creator=lambda: connector.connect(
|
|
448
432
|
"prod-db.mycompany.example.com", # using DNS name
|
|
449
433
|
"pymysql",
|
|
450
434
|
user="my-user",
|
|
451
435
|
password="my-password",
|
|
452
436
|
db="my-db-name"
|
|
453
|
-
)
|
|
454
|
-
return conn
|
|
455
|
-
|
|
456
|
-
# create connection pool
|
|
457
|
-
pool = sqlalchemy.create_engine(
|
|
458
|
-
"mysql+pymysql://",
|
|
459
|
-
creator=getconn,
|
|
437
|
+
),
|
|
460
438
|
)
|
|
461
|
-
return pool
|
|
462
|
-
|
|
463
|
-
# initialize Cloud SQL Python Connector with `resolver=DnsResolver`
|
|
464
|
-
with Connector(resolver=DnsResolver) as connector:
|
|
465
|
-
# initialize connection pool
|
|
466
|
-
pool = init_connection_pool(connector)
|
|
467
439
|
# ... use SQLAlchemy engine normally
|
|
468
440
|
```
|
|
469
441
|
|
|
@@ -540,9 +512,12 @@ from google.cloud.sql.connector import Connector
|
|
|
540
512
|
# initialize Python Connector object
|
|
541
513
|
connector = Connector()
|
|
542
514
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
515
|
+
app = Flask(__name__)
|
|
516
|
+
|
|
517
|
+
# configure Flask-SQLAlchemy to use Python Connector
|
|
518
|
+
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql+pg8000://"
|
|
519
|
+
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {
|
|
520
|
+
"creator": lambda: conn = connector.connect(
|
|
546
521
|
"project:region:instance-name", # Cloud SQL Instance Connection Name
|
|
547
522
|
"pg8000",
|
|
548
523
|
user="my-user",
|
|
@@ -550,15 +525,6 @@ def getconn():
|
|
|
550
525
|
db="my-database",
|
|
551
526
|
ip_type="public" # "private" for private IP
|
|
552
527
|
)
|
|
553
|
-
return conn
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
app = Flask(__name__)
|
|
557
|
-
|
|
558
|
-
# configure Flask-SQLAlchemy to use Python Connector
|
|
559
|
-
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql+pg8000://"
|
|
560
|
-
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {
|
|
561
|
-
"creator": getconn
|
|
562
528
|
}
|
|
563
529
|
|
|
564
530
|
# initialize the app with the extension
|
|
@@ -579,38 +545,27 @@ your web application using [SQLAlchemy ORM](https://docs.sqlalchemy.org/en/14/or
|
|
|
579
545
|
through the following:
|
|
580
546
|
|
|
581
547
|
```python
|
|
582
|
-
|
|
583
|
-
from sqlalchemy.engine import Engine
|
|
548
|
+
import sqlalchemy
|
|
584
549
|
from sqlalchemy.ext.declarative import declarative_base
|
|
585
550
|
from sqlalchemy.orm import sessionmaker
|
|
586
551
|
from google.cloud.sql.connector import Connector
|
|
587
552
|
|
|
588
|
-
# helper function to return SQLAlchemy connection pool
|
|
589
|
-
def init_connection_pool(connector: Connector) -> Engine:
|
|
590
|
-
# Python Connector database connection function
|
|
591
|
-
def getconn():
|
|
592
|
-
conn = connector.connect(
|
|
593
|
-
"project:region:instance-name", # Cloud SQL Instance Connection Name
|
|
594
|
-
"pg8000",
|
|
595
|
-
user="my-user",
|
|
596
|
-
password="my-password",
|
|
597
|
-
db="my-database",
|
|
598
|
-
ip_type="public" # "private" for private IP
|
|
599
|
-
)
|
|
600
|
-
return conn
|
|
601
|
-
|
|
602
|
-
SQLALCHEMY_DATABASE_URL = "postgresql+pg8000://"
|
|
603
|
-
|
|
604
|
-
engine = create_engine(
|
|
605
|
-
SQLALCHEMY_DATABASE_URL , creator=getconn
|
|
606
|
-
)
|
|
607
|
-
return engine
|
|
608
553
|
|
|
609
554
|
# initialize Cloud SQL Python Connector
|
|
610
555
|
connector = Connector()
|
|
611
556
|
|
|
612
557
|
# create connection pool engine
|
|
613
|
-
engine =
|
|
558
|
+
engine = sqlalchemy.create_engine(
|
|
559
|
+
"postgresql+pg8000://",
|
|
560
|
+
creator=lambda: connector.connect(
|
|
561
|
+
"project:region:instance-name", # Cloud SQL Instance Connection Name
|
|
562
|
+
"pg8000",
|
|
563
|
+
user="my-user",
|
|
564
|
+
password="my-password",
|
|
565
|
+
db="my-database",
|
|
566
|
+
ip_type="public" # "private" for private IP
|
|
567
|
+
),
|
|
568
|
+
)
|
|
614
569
|
|
|
615
570
|
# create SQLAlchemy ORM session
|
|
616
571
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
@@ -679,40 +634,29 @@ async def main():
|
|
|
679
634
|
#### SQLAlchemy Async Engine
|
|
680
635
|
|
|
681
636
|
```python
|
|
682
|
-
import asyncpg
|
|
683
|
-
|
|
684
637
|
import sqlalchemy
|
|
685
638
|
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
|
686
639
|
|
|
687
640
|
from google.cloud.sql.connector import Connector, create_async_connector
|
|
688
641
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
642
|
+
|
|
643
|
+
async def main():
|
|
644
|
+
# initialize Connector object for connections to Cloud SQL
|
|
645
|
+
connector = await create_async_connector()
|
|
646
|
+
|
|
647
|
+
# The Cloud SQL Python Connector can be used along with SQLAlchemy using the
|
|
648
|
+
# 'async_creator' argument to 'create_async_engine'
|
|
649
|
+
pool = create_async_engine(
|
|
650
|
+
"postgresql+asyncpg://",
|
|
651
|
+
async_creator=lambda: connector.connect_async(
|
|
693
652
|
"project:region:instance", # Cloud SQL instance connection name
|
|
694
653
|
"asyncpg",
|
|
695
654
|
user="my-user",
|
|
696
655
|
password="my-password",
|
|
697
656
|
db="my-db-name"
|
|
698
657
|
# ... additional database driver args
|
|
699
|
-
)
|
|
700
|
-
return conn
|
|
701
|
-
|
|
702
|
-
# The Cloud SQL Python Connector can be used along with SQLAlchemy using the
|
|
703
|
-
# 'async_creator' argument to 'create_async_engine'
|
|
704
|
-
pool = create_async_engine(
|
|
705
|
-
"postgresql+asyncpg://",
|
|
706
|
-
async_creator=getconn,
|
|
658
|
+
),
|
|
707
659
|
)
|
|
708
|
-
return pool
|
|
709
|
-
|
|
710
|
-
async def main():
|
|
711
|
-
# initialize Connector object for connections to Cloud SQL
|
|
712
|
-
connector = await create_async_connector()
|
|
713
|
-
|
|
714
|
-
# initialize connection pool
|
|
715
|
-
pool = await init_connection_pool(connector)
|
|
716
660
|
|
|
717
661
|
# example query
|
|
718
662
|
async with pool.connect() as conn:
|
|
@@ -783,33 +727,24 @@ from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
|
|
783
727
|
|
|
784
728
|
from google.cloud.sql.connector import Connector
|
|
785
729
|
|
|
786
|
-
async def init_connection_pool(connector: Connector) -> AsyncEngine:
|
|
787
|
-
# creation function to generate asyncpg connections as 'async_creator' arg
|
|
788
|
-
async def getconn() -> asyncpg.Connection:
|
|
789
|
-
conn: asyncpg.Connection = await connector.connect_async(
|
|
790
|
-
"project:region:instance", # Cloud SQL instance connection name
|
|
791
|
-
"asyncpg",
|
|
792
|
-
user="my-user",
|
|
793
|
-
password="my-password",
|
|
794
|
-
db="my-db-name"
|
|
795
|
-
# ... additional database driver args
|
|
796
|
-
)
|
|
797
|
-
return conn
|
|
798
|
-
|
|
799
|
-
# The Cloud SQL Python Connector can be used along with SQLAlchemy using the
|
|
800
|
-
# 'async_creator' argument to 'create_async_engine'
|
|
801
|
-
pool = create_async_engine(
|
|
802
|
-
"postgresql+asyncpg://",
|
|
803
|
-
async_creator=getconn,
|
|
804
|
-
)
|
|
805
|
-
return pool
|
|
806
730
|
|
|
807
731
|
async def main():
|
|
808
732
|
# initialize Connector object for connections to Cloud SQL
|
|
809
733
|
loop = asyncio.get_running_loop()
|
|
810
734
|
async with Connector(loop=loop) as connector:
|
|
811
|
-
#
|
|
812
|
-
|
|
735
|
+
# The Cloud SQL Python Connector can be used along with SQLAlchemy using the
|
|
736
|
+
# 'async_creator' argument to 'create_async_engine'
|
|
737
|
+
pool = create_async_engine(
|
|
738
|
+
"postgresql+asyncpg://",
|
|
739
|
+
async_creator=lambda: connector.connect_async(
|
|
740
|
+
"project:region:instance", # Cloud SQL instance connection name
|
|
741
|
+
"asyncpg",
|
|
742
|
+
user="my-user",
|
|
743
|
+
password="my-password",
|
|
744
|
+
db="my-db-name"
|
|
745
|
+
# ... additional database driver args
|
|
746
|
+
),
|
|
747
|
+
)
|
|
813
748
|
|
|
814
749
|
# example query
|
|
815
750
|
async with pool.connect() as conn:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
cloud_sql_python_connector-1.18.2.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
2
|
+
google/cloud/sql/connector/__init__.py,sha256=w6w35V-m2QlpcL-ShKd2BvNF-xXOwJ2FoidE7npPE7c,1148
|
|
3
|
+
google/cloud/sql/connector/asyncpg.py,sha256=v4ohOnSYjHTOvJPhTE761xP1KKo4FUJQW_WAnNW_2g4,1918
|
|
4
|
+
google/cloud/sql/connector/client.py,sha256=QhxoCLn1KFKpBsLKU46GPvWI7GYuSo0oPXm_QGI-7fI,13076
|
|
5
|
+
google/cloud/sql/connector/connection_info.py,sha256=BSuW-ovtEUYTIvDzQkaE3GofCs3Xoi0TtztFaAq4Kvo,4868
|
|
6
|
+
google/cloud/sql/connector/connection_name.py,sha256=bI4M3Qa2mtBHyD08oF41FF5W9FBOXWu4dGGg50Na_A4,2606
|
|
7
|
+
google/cloud/sql/connector/connector.py,sha256=H2vDRZ-N8mz8oO_OnKCY-LODbsAnzaxEMGPl4zv10sc,24182
|
|
8
|
+
google/cloud/sql/connector/enums.py,sha256=dVBS9eEWNrHtzze0AJlmtbdUogG3EocNWOQcI_8qPd0,2937
|
|
9
|
+
google/cloud/sql/connector/exceptions.py,sha256=QdQBzZ3t1RE5V744wW4sGaucWD2cEedB-dWNCkh8SAA,1974
|
|
10
|
+
google/cloud/sql/connector/instance.py,sha256=jDEQf-OXFzqKO9a4bnzRQ0qUyO3_xKuiEIRWc_7wpyE,8694
|
|
11
|
+
google/cloud/sql/connector/lazy.py,sha256=oB6F-O2fk8ZguY4J7Vrts91bqbVb6P5wj72Lf6UJIQA,4948
|
|
12
|
+
google/cloud/sql/connector/monitored_cache.py,sha256=LFYjX8hsdN_Dt0cMwLSWgAhWWQpZ35qA0CLlpc6xhsE,5587
|
|
13
|
+
google/cloud/sql/connector/pg8000.py,sha256=TnS_SNbgY19oNEawOx-qJyW-f_k42-SnR3VTBOSr5FI,1717
|
|
14
|
+
google/cloud/sql/connector/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
google/cloud/sql/connector/pymysql.py,sha256=PrTQ1lB5EWAcN4BPX_5hb-WerncS4X76bBk4y0es0ks,1948
|
|
16
|
+
google/cloud/sql/connector/pytds.py,sha256=KZxmJQQG9XfmsmUoEGX7RpMirWdoreJ2-_FuHO6Td-s,2280
|
|
17
|
+
google/cloud/sql/connector/rate_limiter.py,sha256=zqZ9pVXHan4LWoGT8Bq6U3HpZcrdzKhlXVYwsX3ftA0,2928
|
|
18
|
+
google/cloud/sql/connector/refresh_utils.py,sha256=WeLwc1Fd2Er68tYyfqEF8ZUIUe4-yxvfYURcwiUKzs0,5123
|
|
19
|
+
google/cloud/sql/connector/resolver.py,sha256=DUU7swlBjMJjlDqa_M4XtIctPiJBnz-OusFUk5GLc1Y,3290
|
|
20
|
+
google/cloud/sql/connector/utils.py,sha256=AA_oBBxRuULb7-hHHK8HQJU5fttzBpzdIZwMNZ5kNCM,3473
|
|
21
|
+
google/cloud/sql/connector/version.py,sha256=gCmJi1gRtjm8lOXKRNamw2YjccdBKqHgqQtePcqdtYk,598
|
|
22
|
+
cloud_sql_python_connector-1.18.2.dist-info/METADATA,sha256=RSQZMbUhcWfpSiZfeSLFhm-gdtFhWr-jkcIdIiscoc4,30340
|
|
23
|
+
cloud_sql_python_connector-1.18.2.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
24
|
+
cloud_sql_python_connector-1.18.2.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
|
25
|
+
cloud_sql_python_connector-1.18.2.dist-info/RECORD,,
|
|
@@ -28,21 +28,22 @@ async def connect(
|
|
|
28
28
|
) -> "asyncpg.Connection":
|
|
29
29
|
"""Helper function to create an asyncpg DB-API connection object.
|
|
30
30
|
|
|
31
|
-
:
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
Args:
|
|
32
|
+
ip_address (str): A string containing an IP address for the Cloud SQL
|
|
33
|
+
instance.
|
|
34
|
+
ctx (ssl.SSLContext): An SSLContext object created from the Cloud SQL
|
|
35
|
+
server CA cert and ephemeral cert.
|
|
36
|
+
server CA cert and ephemeral cert.
|
|
37
|
+
kwargs: Keyword arguments for establishing asyncpg connection
|
|
38
|
+
object to Cloud SQL instance.
|
|
34
39
|
|
|
35
|
-
:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
:param kwargs: Keyword arguments for establishing asyncpg connection
|
|
41
|
-
object to Cloud SQL instance.
|
|
42
|
-
|
|
43
|
-
:rtype: asyncpg.Connection
|
|
44
|
-
:returns: An asyncpg.Connection object to a Cloud SQL instance.
|
|
40
|
+
Returns:
|
|
41
|
+
asyncpg.Connection: An asyncpg connection to the Cloud SQL
|
|
42
|
+
instance.
|
|
43
|
+
Raises:
|
|
44
|
+
ImportError: The asyncpg module cannot be imported.
|
|
45
45
|
"""
|
|
46
|
+
|
|
46
47
|
try:
|
|
47
48
|
import asyncpg
|
|
48
49
|
except ImportError:
|
|
@@ -22,9 +22,9 @@ from typing import Any, Optional, TYPE_CHECKING
|
|
|
22
22
|
import aiohttp
|
|
23
23
|
from cryptography.hazmat.backends import default_backend
|
|
24
24
|
from cryptography.x509 import load_pem_x509_certificate
|
|
25
|
+
|
|
25
26
|
from google.auth.credentials import TokenState
|
|
26
27
|
from google.auth.transport import requests
|
|
27
|
-
|
|
28
28
|
from google.cloud.sql.connector.connection_info import ConnectionInfo
|
|
29
29
|
from google.cloud.sql.connector.connection_name import ConnectionName
|
|
30
30
|
from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported
|
|
@@ -59,8 +59,7 @@ class CloudSQLClient:
|
|
|
59
59
|
driver: Optional[str] = None,
|
|
60
60
|
user_agent: Optional[str] = None,
|
|
61
61
|
) -> None:
|
|
62
|
-
"""
|
|
63
|
-
Establish the client to be used for Cloud SQL Admin API requests.
|
|
62
|
+
"""Establishes the client to be used for Cloud SQL Admin API requests.
|
|
64
63
|
|
|
65
64
|
Args:
|
|
66
65
|
sqladmin_api_endpoint (str): Base URL to use when calling
|
|
@@ -100,24 +99,22 @@ class CloudSQLClient:
|
|
|
100
99
|
region: str,
|
|
101
100
|
instance: str,
|
|
102
101
|
) -> dict[str, Any]:
|
|
103
|
-
"""Requests metadata from the Cloud SQL Instance
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
"""Requests metadata from the Cloud SQL Instance and returns a dictionary
|
|
103
|
+
containing the IP addresses and certificate authority of the Cloud SQL
|
|
104
|
+
Instance.
|
|
106
105
|
|
|
107
|
-
:
|
|
108
|
-
|
|
109
|
-
A string representing the name of the
|
|
110
|
-
|
|
111
|
-
:type region: str
|
|
112
|
-
:param region : A string representing the name of the region.
|
|
106
|
+
Args:
|
|
107
|
+
project (str): A string representing the name of the project.
|
|
108
|
+
region (str): A string representing the name of the region.
|
|
109
|
+
instance (str): A string representing the name of the instance.
|
|
113
110
|
|
|
114
|
-
:
|
|
115
|
-
|
|
111
|
+
Returns:
|
|
112
|
+
A dictionary containing a dictionary of all IP addresses
|
|
113
|
+
and their type and a string representing the certificate authority.
|
|
116
114
|
|
|
117
|
-
:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
certificate authority.
|
|
115
|
+
Raises:
|
|
116
|
+
ValueError: Provided region does not match the region of the
|
|
117
|
+
Cloud SQL instance.
|
|
121
118
|
"""
|
|
122
119
|
|
|
123
120
|
headers = {
|
|
@@ -189,23 +186,17 @@ class CloudSQLClient:
|
|
|
189
186
|
) -> tuple[str, datetime.datetime]:
|
|
190
187
|
"""Asynchronously requests an ephemeral certificate from the Cloud SQL Instance.
|
|
191
188
|
|
|
192
|
-
:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
:type pub_key:
|
|
199
|
-
:param str: A string representing PEM-encoded RSA public key.
|
|
200
|
-
|
|
201
|
-
:type enable_iam_auth: bool
|
|
202
|
-
:param enable_iam_auth
|
|
203
|
-
Enables automatic IAM database authentication for Postgres or MySQL
|
|
204
|
-
instances.
|
|
189
|
+
Args:
|
|
190
|
+
project (str): A string representing the name of the project.
|
|
191
|
+
instance (str): string representing the name of the instance.
|
|
192
|
+
pub_key (str): A string representing PEM-encoded RSA public key.
|
|
193
|
+
enable_iam_auth (bool): Enables automatic IAM database
|
|
194
|
+
authentication for Postgres or MySQL instances.
|
|
205
195
|
|
|
206
|
-
:
|
|
207
|
-
|
|
208
|
-
|
|
196
|
+
Returns:
|
|
197
|
+
A tuple containing an ephemeral certificate from
|
|
198
|
+
the Cloud SQL instance as well as a datetime object
|
|
199
|
+
representing the expiration time of the certificate.
|
|
209
200
|
"""
|
|
210
201
|
headers = {
|
|
211
202
|
"Authorization": f"Bearer {self._credentials.token}",
|
|
@@ -28,7 +28,6 @@ from typing import Any, Callable, Optional, Union
|
|
|
28
28
|
import google.auth
|
|
29
29
|
from google.auth.credentials import Credentials
|
|
30
30
|
from google.auth.credentials import with_scopes_if_required
|
|
31
|
-
|
|
32
31
|
import google.cloud.sql.connector.asyncpg as asyncpg
|
|
33
32
|
from google.cloud.sql.connector.client import CloudSQLClient
|
|
34
33
|
from google.cloud.sql.connector.enums import DriverMapping
|
|
@@ -26,17 +26,19 @@ def connect(
|
|
|
26
26
|
) -> "pg8000.dbapi.Connection":
|
|
27
27
|
"""Helper function to create a pg8000 DB-API connection object.
|
|
28
28
|
|
|
29
|
-
:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
Args:
|
|
30
|
+
ip_address (str): A string containing an IP address for the Cloud SQL
|
|
31
|
+
instance.
|
|
32
|
+
sock (ssl.SSLSocket): An SSLSocket object created from the Cloud SQL
|
|
33
|
+
server CA cert and ephemeral cert.
|
|
34
|
+
kwargs: Additional arguments to pass to the pg8000 connect method.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
pg8000.dbapi.Connection: A pg8000 connection to the Cloud SQL
|
|
38
|
+
instance.
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
ImportError: The pg8000 module cannot be imported.
|
|
40
42
|
"""
|
|
41
43
|
try:
|
|
42
44
|
import pg8000
|
|
@@ -26,16 +26,18 @@ def connect(
|
|
|
26
26
|
) -> "pymysql.connections.Connection":
|
|
27
27
|
"""Helper function to create a pymysql DB-API connection object.
|
|
28
28
|
|
|
29
|
-
:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
Args:
|
|
30
|
+
ip_address (str): A string containing an IP address for the Cloud SQL
|
|
31
|
+
instance.
|
|
32
|
+
sock (ssl.SSLSocket): An SSLSocket object created from the Cloud SQL
|
|
33
|
+
server CA cert and ephemeral cert.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
pymysql.connections.Connection: A pymysql connection to the Cloud SQL
|
|
37
|
+
instance.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
ImportError: The pymysql module cannot be imported.
|
|
39
41
|
"""
|
|
40
42
|
try:
|
|
41
43
|
import pymysql
|
|
@@ -27,17 +27,18 @@ if TYPE_CHECKING:
|
|
|
27
27
|
def connect(ip_address: str, sock: ssl.SSLSocket, **kwargs: Any) -> "pytds.Connection":
|
|
28
28
|
"""Helper function to create a pytds DB-API connection object.
|
|
29
29
|
|
|
30
|
-
:
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
Args:
|
|
31
|
+
ip_address (str): A string containing an IP address for the Cloud SQL
|
|
32
|
+
instance.
|
|
33
|
+
sock (ssl.SSLSocket): An SSLSocket object created from the Cloud SQL
|
|
34
|
+
server CA cert and ephemeral cert.
|
|
33
35
|
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
Returns:
|
|
37
|
+
pytds.Connection: A pytds connection to the Cloud SQL
|
|
38
|
+
instance.
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
:returns: A pytds Connection object for the Cloud SQL instance.
|
|
40
|
+
Raises:
|
|
41
|
+
ImportError: The pytds module cannot be imported.
|
|
41
42
|
"""
|
|
42
43
|
try:
|
|
43
44
|
import pytds
|
|
@@ -19,24 +19,16 @@ from typing import Optional
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class AsyncRateLimiter(object):
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
:type max_capacity: int
|
|
27
|
-
:param: max_capacity:
|
|
28
|
-
The maximum capacity of tokens the bucket will store at any one time.
|
|
29
|
-
Default: 1
|
|
30
|
-
|
|
31
|
-
:type rate: float
|
|
32
|
-
:param: rate:
|
|
33
|
-
The number of tokens that should be added per second.
|
|
34
|
-
|
|
35
|
-
:type loop: asyncio.AbstractEventLoop
|
|
36
|
-
:param: loop:
|
|
37
|
-
The event loop to use. If not provided, the default event loop will be used.
|
|
38
|
-
|
|
22
|
+
"""An asyncio-compatible rate limiter which uses the Token Bucket algorithm
|
|
23
|
+
(https://en.wikipedia.org/wiki/Token_bucket) to limit the number
|
|
24
|
+
of function calls over a time interval using an event queue.
|
|
39
25
|
|
|
26
|
+
Args:
|
|
27
|
+
max_capacity (int): The maximum capacity of tokens the bucket
|
|
28
|
+
will store at any one time. Default: 1
|
|
29
|
+
rate (float): The number of tokens that should be added per second.
|
|
30
|
+
loop (asyncio.AbstractEventLoop): The event loop to use.
|
|
31
|
+
If not provided, the default event loop will be used.
|
|
40
32
|
"""
|
|
41
33
|
|
|
42
34
|
def __init__(
|
|
@@ -24,6 +24,7 @@ import random
|
|
|
24
24
|
from typing import Any, Callable
|
|
25
25
|
|
|
26
26
|
import aiohttp
|
|
27
|
+
|
|
27
28
|
from google.auth.credentials import Credentials
|
|
28
29
|
from google.auth.credentials import Scoped
|
|
29
30
|
import google.auth.transport.requests
|
|
@@ -44,8 +45,11 @@ def _seconds_until_refresh(
|
|
|
44
45
|
Usually the duration will be half of the time until certificate
|
|
45
46
|
expiration.
|
|
46
47
|
|
|
47
|
-
:
|
|
48
|
-
|
|
48
|
+
Args:
|
|
49
|
+
expiration (datetime.datetime): The expiration time of the certificate.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
int: Time in seconds to wait before performing next refresh.
|
|
49
53
|
"""
|
|
50
54
|
|
|
51
55
|
duration = int(
|
|
@@ -81,16 +85,14 @@ def _downscope_credentials(
|
|
|
81
85
|
) -> Credentials:
|
|
82
86
|
"""Generate a down-scoped credential.
|
|
83
87
|
|
|
84
|
-
:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
:param scopes
|
|
90
|
-
List of Google scopes to include in down-scoped credentials object.
|
|
88
|
+
Args:
|
|
89
|
+
credentials (google.auth.credentials.Credentials):
|
|
90
|
+
Credentials object used to generate down-scoped credentials.
|
|
91
|
+
scopes (list[str]): List of Google scopes to
|
|
92
|
+
include in down-scoped credentials object.
|
|
91
93
|
|
|
92
|
-
:
|
|
93
|
-
|
|
94
|
+
Returns:
|
|
95
|
+
google.auth.credentials.Credentials: Down-scoped credentials object.
|
|
94
96
|
"""
|
|
95
97
|
# credentials sourced from a service account or metadata are children of
|
|
96
98
|
# Scoped class and are capable of being re-scoped
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
|
|
15
15
|
import dns.asyncresolver
|
|
16
16
|
|
|
17
|
+
from google.cloud.sql.connector.connection_name import _is_valid_domain
|
|
18
|
+
from google.cloud.sql.connector.connection_name import _parse_connection_name
|
|
17
19
|
from google.cloud.sql.connector.connection_name import (
|
|
18
20
|
_parse_connection_name_with_domain_name,
|
|
19
21
|
)
|
|
20
|
-
from google.cloud.sql.connector.connection_name import _is_valid_domain
|
|
21
|
-
from google.cloud.sql.connector.connection_name import _parse_connection_name
|
|
22
22
|
from google.cloud.sql.connector.connection_name import ConnectionName
|
|
23
23
|
from google.cloud.sql.connector.exceptions import DnsResolutionError
|
|
24
24
|
|
|
@@ -79,16 +79,14 @@ async def write_to_file(
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
def format_database_user(database_version: str, user: str) -> str:
|
|
82
|
-
"""
|
|
83
|
-
Format database `user` param for Cloud SQL automatic IAM authentication.
|
|
82
|
+
"""Format database `user` param for Cloud SQL automatic IAM authentication.
|
|
84
83
|
|
|
85
|
-
:
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
Args:
|
|
85
|
+
database_version (str): Cloud SQL database version.
|
|
86
|
+
user (str): Database username to connect to Cloud SQL database with.
|
|
88
87
|
|
|
89
|
-
:
|
|
90
|
-
|
|
91
|
-
Database username to connect to Cloud SQL database with.
|
|
88
|
+
Returns:
|
|
89
|
+
str: Formatted database username.
|
|
92
90
|
"""
|
|
93
91
|
# remove suffix for Postgres service accounts
|
|
94
92
|
if database_version.startswith("POSTGRES"):
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
cloud_sql_python_connector-1.18.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
2
|
-
google/cloud/sql/connector/__init__.py,sha256=w6w35V-m2QlpcL-ShKd2BvNF-xXOwJ2FoidE7npPE7c,1148
|
|
3
|
-
google/cloud/sql/connector/asyncpg.py,sha256=HUOB0rRhr2-zMbygDtdWTDNlYqEPkN0ADqCIpM3waDc,1839
|
|
4
|
-
google/cloud/sql/connector/client.py,sha256=ITZNJsIEAeCSKgH2B-cFklg_zVEPaskIzo7t_Q85F4M,13124
|
|
5
|
-
google/cloud/sql/connector/connection_info.py,sha256=BSuW-ovtEUYTIvDzQkaE3GofCs3Xoi0TtztFaAq4Kvo,4868
|
|
6
|
-
google/cloud/sql/connector/connection_name.py,sha256=bI4M3Qa2mtBHyD08oF41FF5W9FBOXWu4dGGg50Na_A4,2606
|
|
7
|
-
google/cloud/sql/connector/connector.py,sha256=jukyYD75FElLvKgSHg4o91Wug21jIn87nJWNbeoTZUc,24183
|
|
8
|
-
google/cloud/sql/connector/enums.py,sha256=dVBS9eEWNrHtzze0AJlmtbdUogG3EocNWOQcI_8qPd0,2937
|
|
9
|
-
google/cloud/sql/connector/exceptions.py,sha256=QdQBzZ3t1RE5V744wW4sGaucWD2cEedB-dWNCkh8SAA,1974
|
|
10
|
-
google/cloud/sql/connector/instance.py,sha256=jDEQf-OXFzqKO9a4bnzRQ0qUyO3_xKuiEIRWc_7wpyE,8694
|
|
11
|
-
google/cloud/sql/connector/lazy.py,sha256=oB6F-O2fk8ZguY4J7Vrts91bqbVb6P5wj72Lf6UJIQA,4948
|
|
12
|
-
google/cloud/sql/connector/monitored_cache.py,sha256=LFYjX8hsdN_Dt0cMwLSWgAhWWQpZ35qA0CLlpc6xhsE,5587
|
|
13
|
-
google/cloud/sql/connector/pg8000.py,sha256=3p4CJixaiYrjUtG3DWTQrh6qCkmUEbQyoX25SQSvyX4,1594
|
|
14
|
-
google/cloud/sql/connector/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
google/cloud/sql/connector/pymysql.py,sha256=U1HEf0jBtnMiLjIuhp6ZGMJDg8IKQH24m2IRsy3k3tw,1886
|
|
16
|
-
google/cloud/sql/connector/pytds.py,sha256=s3_LvC-CfNwz7VKmmMVd0MwaC3vQigDLszsre3xLZC4,2233
|
|
17
|
-
google/cloud/sql/connector/rate_limiter.py,sha256=bPTupfM4f5QRSCmCAWMqjQylEB7bUM-50plVBU3W2CA,2993
|
|
18
|
-
google/cloud/sql/connector/refresh_utils.py,sha256=HfuuLdlqg2IxusB4T3BMj-BJlGsXtHsrCX_Hp-eJ_j0,5063
|
|
19
|
-
google/cloud/sql/connector/resolver.py,sha256=1KYN0E-oTca8wRyW2nqCw56XRHtq-QGYpPvkk-UhjnY,3290
|
|
20
|
-
google/cloud/sql/connector/utils.py,sha256=7g1fX-JsZc7xOgTuxrAiroFHQIQk_BEJZNYaKOinwQY,3508
|
|
21
|
-
google/cloud/sql/connector/version.py,sha256=t8RiJsR1VPKxNkKjjeAvtxSWJtJ2z_lMfWNUWDFzRk8,598
|
|
22
|
-
cloud_sql_python_connector-1.18.0.dist-info/METADATA,sha256=pFnUd-5DK_0daO_QGMMb4zWVI0EGFMGNrMoprHhVVw8,32331
|
|
23
|
-
cloud_sql_python_connector-1.18.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
|
24
|
-
cloud_sql_python_connector-1.18.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
|
25
|
-
cloud_sql_python_connector-1.18.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|