Skip to content

Commit f497349

Browse files
committed
chore: update default ip_type for connector engine
1 parent 8d614b9 commit f497349

File tree

8 files changed

+45
-45
lines changed

8 files changed

+45
-45
lines changed

tests/system/test_asyncpg_connection.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def create_sqlalchemy_engine(
3232
user: str,
3333
password: str,
3434
db: str,
35-
ip_type: str,
35+
ip_type: str = "public",
3636
refresh_strategy: str = "background",
3737
resolver: Union[type[DefaultResolver], type[DnsResolver]] = DefaultResolver,
3838
) -> tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]:
@@ -65,7 +65,7 @@ async def create_sqlalchemy_engine(
6565
db (str):
6666
The name of the database, e.g., mydb
6767
ip_type (str):
68-
The IP type of the Cloud SQL instance.
68+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
6969
refresh_strategy (Optional[str]):
7070
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
7171
or "background". For serverless environments use "lazy" to avoid
@@ -90,7 +90,7 @@ async def create_sqlalchemy_engine(
9090
user=user,
9191
password=password,
9292
db=db,
93-
ip_type=ip_type,
93+
ip_type=ip_type, # can be "public", "private" or "psc"
9494
),
9595
execution_options={"isolation_level": "AUTOCOMMIT"},
9696
)
@@ -102,7 +102,7 @@ async def create_asyncpg_pool(
102102
user: str,
103103
password: str,
104104
db: str,
105-
ip_type: str,
105+
ip_type: str = "public",
106106
refresh_strategy: str = "background",
107107
) -> tuple[asyncpg.Pool, Connector]:
108108
"""Creates a native asyncpg connection pool for a Cloud SQL instance and
@@ -133,7 +133,7 @@ async def create_asyncpg_pool(
133133
db (str):
134134
The name of the database, e.g., mydb
135135
ip_type (str):
136-
The IP type of the Cloud SQL instance.
136+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
137137
refresh_strategy (Optional[str]):
138138
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
139139
or "background". For serverless environments use "lazy" to avoid
@@ -151,7 +151,7 @@ async def getconn(
151151
user=user,
152152
password=password,
153153
db=db,
154-
ip_type=ip_type,
154+
ip_type=ip_type, # can be "public", "private" or "psc"
155155
**kwargs,
156156
)
157157
return conn
@@ -167,7 +167,7 @@ async def test_sqlalchemy_connection_with_asyncpg() -> None:
167167
user = os.environ["POSTGRES_USER"]
168168
password = os.environ["POSTGRES_PASS"]
169169
db = os.environ["POSTGRES_DB"]
170-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
170+
ip_type = os.environ.get("IP_TYPE", "public")
171171

172172
pool, connector = await create_sqlalchemy_engine(
173173
inst_conn_name, user, password, db, ip_type
@@ -186,7 +186,7 @@ async def test_lazy_sqlalchemy_connection_with_asyncpg() -> None:
186186
user = os.environ["POSTGRES_USER"]
187187
password = os.environ["POSTGRES_PASS"]
188188
db = os.environ["POSTGRES_DB"]
189-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
189+
ip_type = os.environ.get("IP_TYPE", "public")
190190

191191
pool, connector = await create_sqlalchemy_engine(
192192
inst_conn_name, user, password, db, ip_type, "lazy"
@@ -205,7 +205,7 @@ async def test_custom_SAN_with_dns_sqlalchemy_connection_with_asyncpg() -> None:
205205
user = os.environ["POSTGRES_USER"]
206206
password = os.environ["POSTGRES_CUSTOMER_CAS_PASS"]
207207
db = os.environ["POSTGRES_DB"]
208-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
208+
ip_type = os.environ.get("IP_TYPE", "public")
209209

210210
pool, connector = await create_sqlalchemy_engine(
211211
inst_conn_name, user, password, db, ip_type, resolver=DnsResolver
@@ -224,7 +224,7 @@ async def test_connection_with_asyncpg() -> None:
224224
user = os.environ["POSTGRES_USER"]
225225
password = os.environ["POSTGRES_PASS"]
226226
db = os.environ["POSTGRES_DB"]
227-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
227+
ip_type = os.environ.get("IP_TYPE", "public")
228228

229229
pool, connector = await create_asyncpg_pool(
230230
inst_conn_name, user, password, db, ip_type
@@ -243,7 +243,7 @@ async def test_lazy_connection_with_asyncpg() -> None:
243243
user = os.environ["POSTGRES_USER"]
244244
password = os.environ["POSTGRES_PASS"]
245245
db = os.environ["POSTGRES_DB"]
246-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
246+
ip_type = os.environ.get("IP_TYPE", "public")
247247

248248
pool, connector = await create_asyncpg_pool(
249249
inst_conn_name, user, password, db, ip_type, "lazy"

tests/system/test_asyncpg_iam_auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def create_sqlalchemy_engine(
2727
instance_connection_name: str,
2828
user: str,
2929
db: str,
30-
ip_type: str,
30+
ip_type: str = "public",
3131
refresh_strategy: str = "background",
3232
) -> tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]:
3333
"""Creates a connection pool for a Cloud SQL instance and returns the pool
@@ -57,7 +57,7 @@ async def create_sqlalchemy_engine(
5757
db (str):
5858
The name of the database, e.g., mydb
5959
ip_type (str):
60-
The IP type of the Cloud SQL instance.
60+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
6161
refresh_strategy (Optional[str]):
6262
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
6363
or "background". For serverless environments use "lazy" to avoid
@@ -74,7 +74,7 @@ async def create_sqlalchemy_engine(
7474
"asyncpg",
7575
user=user,
7676
db=db,
77-
ip_type=ip_type,
77+
ip_type=ip_type, # can be "public", "private" or "psc"
7878
enable_iam_auth=True,
7979
),
8080
execution_options={"isolation_level": "AUTOCOMMIT"},
@@ -87,7 +87,7 @@ async def test_iam_authn_connection_with_asyncpg() -> None:
8787
inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"]
8888
user = os.environ["POSTGRES_IAM_USER"]
8989
db = os.environ["POSTGRES_DB"]
90-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
90+
ip_type = os.environ.get("IP_TYPE", "public")
9191

9292
pool, connector = await create_sqlalchemy_engine(inst_conn_name, user, db, ip_type)
9393

@@ -103,7 +103,7 @@ async def test_lazy_iam_authn_connection_with_asyncpg() -> None:
103103
inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"]
104104
user = os.environ["POSTGRES_IAM_USER"]
105105
db = os.environ["POSTGRES_DB"]
106-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
106+
ip_type = os.environ.get("IP_TYPE", "public")
107107

108108
pool, connector = await create_sqlalchemy_engine(
109109
inst_conn_name, user, db, ip_type, "lazy"

tests/system/test_ip_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def getconn() -> pymysql.connections.Connection:
3434
conn: pymysql.connections.Connection = connector.connect(
3535
os.environ["MYSQL_CONNECTION_NAME"],
3636
"pymysql",
37-
ip_type=ip_type,
37+
ip_type=ip_type, # can be "public", "private" or "psc"
3838
user=os.environ["MYSQL_USER"],
3939
password=os.environ["MYSQL_PASS"],
4040
db=os.environ["MYSQL_DB"],

tests/system/test_pg8000_connection.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def create_sqlalchemy_engine(
3232
user: str,
3333
password: str,
3434
db: str,
35-
ip_type: str,
35+
ip_type: str = "public",
3636
refresh_strategy: str = "background",
3737
resolver: Union[type[DefaultResolver], type[DnsResolver]] = DefaultResolver,
3838
) -> tuple[sqlalchemy.engine.Engine, Connector]:
@@ -66,7 +66,7 @@ def create_sqlalchemy_engine(
6666
db (str):
6767
The name of the database, e.g., mydb
6868
ip_type (str):
69-
The IP type of the Cloud SQL instance.
69+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
7070
refresh_strategy (Optional[str]):
7171
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
7272
or "background". For serverless environments use "lazy" to avoid
@@ -88,7 +88,7 @@ def create_sqlalchemy_engine(
8888
user=user,
8989
password=password,
9090
db=db,
91-
ip_type=ip_type,
91+
ip_type=ip_type, # can be "public", "private" or "psc"
9292
),
9393
)
9494
return engine, connector
@@ -103,7 +103,7 @@ def test_pg8000_connection() -> None:
103103
user = os.environ["POSTGRES_USER"]
104104
password = os.environ["POSTGRES_PASS"]
105105
db = os.environ["POSTGRES_DB"]
106-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
106+
ip_type = os.environ.get("IP_TYPE", "public")
107107

108108
engine, connector = create_sqlalchemy_engine(
109109
inst_conn_name, user, password, db, ip_type
@@ -122,7 +122,7 @@ def test_lazy_pg8000_connection() -> None:
122122
user = os.environ["POSTGRES_USER"]
123123
password = os.environ["POSTGRES_PASS"]
124124
db = os.environ["POSTGRES_DB"]
125-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
125+
ip_type = os.environ.get("IP_TYPE", "public")
126126

127127
engine, connector = create_sqlalchemy_engine(
128128
inst_conn_name, user, password, db, ip_type, "lazy"
@@ -141,7 +141,7 @@ def test_CAS_pg8000_connection() -> None:
141141
user = os.environ["POSTGRES_USER"]
142142
password = os.environ["POSTGRES_CAS_PASS"]
143143
db = os.environ["POSTGRES_DB"]
144-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
144+
ip_type = os.environ.get("IP_TYPE", "public")
145145

146146
engine, connector = create_sqlalchemy_engine(
147147
inst_conn_name, user, password, db, ip_type
@@ -160,7 +160,7 @@ def test_customer_managed_CAS_pg8000_connection() -> None:
160160
user = os.environ["POSTGRES_USER"]
161161
password = os.environ["POSTGRES_CUSTOMER_CAS_PASS"]
162162
db = os.environ["POSTGRES_DB"]
163-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
163+
ip_type = os.environ.get("IP_TYPE", "public")
164164

165165
engine, connector = create_sqlalchemy_engine(
166166
inst_conn_name, user, password, db, ip_type
@@ -179,7 +179,7 @@ def test_custom_SAN_with_dns_pg8000_connection() -> None:
179179
user = os.environ["POSTGRES_USER"]
180180
password = os.environ["POSTGRES_CUSTOMER_CAS_PASS"]
181181
db = os.environ["POSTGRES_DB"]
182-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
182+
ip_type = os.environ.get("IP_TYPE", "public")
183183

184184
engine, connector = create_sqlalchemy_engine(
185185
inst_conn_name, user, password, db, ip_type, resolver=DnsResolver

tests/system/test_pg8000_iam_auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create_sqlalchemy_engine(
2626
instance_connection_name: str,
2727
user: str,
2828
db: str,
29-
ip_type: str,
29+
ip_type: str = "public",
3030
refresh_strategy: str = "background",
3131
) -> tuple[sqlalchemy.engine.Engine, Connector]:
3232
"""Creates a connection pool for a Cloud SQL instance and returns the pool
@@ -57,7 +57,7 @@ def create_sqlalchemy_engine(
5757
db (str):
5858
The name of the database, e.g., mydb
5959
ip_type (str):
60-
The IP type of the Cloud SQL instance.
60+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
6161
refresh_strategy (Optional[str]):
6262
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
6363
or "background". For serverless environments use "lazy" to avoid
@@ -73,7 +73,7 @@ def create_sqlalchemy_engine(
7373
"pg8000",
7474
user=user,
7575
db=db,
76-
ip_type=ip_type,
76+
ip_type=ip_type, # can be "public", "private" or "psc"
7777
enable_iam_auth=True,
7878
),
7979
)
@@ -85,7 +85,7 @@ def test_pg8000_iam_authn_connection() -> None:
8585
inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"]
8686
user = os.environ["POSTGRES_IAM_USER"]
8787
db = os.environ["POSTGRES_DB"]
88-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
88+
ip_type = os.environ.get("IP_TYPE", "public")
8989

9090
engine, connector = create_sqlalchemy_engine(inst_conn_name, user, db, ip_type)
9191
with engine.connect() as conn:
@@ -101,7 +101,7 @@ def test_lazy_pg8000_iam_authn_connection() -> None:
101101
inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"]
102102
user = os.environ["POSTGRES_IAM_USER"]
103103
db = os.environ["POSTGRES_DB"]
104-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
104+
ip_type = os.environ.get("IP_TYPE", "public")
105105

106106
engine, connector = create_sqlalchemy_engine(
107107
inst_conn_name, user, db, ip_type, "lazy"

tests/system/test_pymysql_connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create_sqlalchemy_engine(
2828
user: str,
2929
password: str,
3030
db: str,
31-
ip_type: str,
31+
ip_type: str = "public",
3232
refresh_strategy: str = "background",
3333
) -> tuple[sqlalchemy.engine.Engine, Connector]:
3434
"""Creates a connection pool for a Cloud SQL instance and returns the pool
@@ -61,7 +61,7 @@ def create_sqlalchemy_engine(
6161
db (str):
6262
The name of the database, e.g., mydb
6363
ip_type (str):
64-
The IP type of the Cloud SQL instance.
64+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
6565
refresh_strategy (Optional[str]):
6666
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
6767
or "background". For serverless environments use "lazy" to avoid
@@ -78,7 +78,7 @@ def create_sqlalchemy_engine(
7878
user=user,
7979
password=password,
8080
db=db,
81-
ip_type=ip_type,
81+
ip_type=ip_type, # can be "public", "private" or "psc"
8282
),
8383
)
8484
return engine, connector
@@ -93,7 +93,7 @@ def test_pymysql_connection() -> None:
9393
user = os.environ["MYSQL_USER"]
9494
password = os.environ["MYSQL_PASS"]
9595
db = os.environ["MYSQL_DB"]
96-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
96+
ip_type = os.environ.get("IP_TYPE", "public")
9797

9898
engine, connector = create_sqlalchemy_engine(
9999
inst_conn_name, user, password, db, ip_type
@@ -112,7 +112,7 @@ def test_lazy_pymysql_connection() -> None:
112112
user = os.environ["MYSQL_USER"]
113113
password = os.environ["MYSQL_PASS"]
114114
db = os.environ["MYSQL_DB"]
115-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
115+
ip_type = os.environ.get("IP_TYPE", "public")
116116

117117
engine, connector = create_sqlalchemy_engine(
118118
inst_conn_name, user, password, db, ip_type, "lazy"

tests/system/test_pymysql_iam_auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create_sqlalchemy_engine(
2626
instance_connection_name: str,
2727
user: str,
2828
db: str,
29-
ip_type: str,
29+
ip_type: str = "public",
3030
refresh_strategy: str = "background",
3131
) -> tuple[sqlalchemy.engine.Engine, Connector]:
3232
"""Creates a connection pool for a Cloud SQL instance and returns the pool
@@ -57,7 +57,7 @@ def create_sqlalchemy_engine(
5757
db (str):
5858
The name of the database, e.g., mydb
5959
ip_type (str):
60-
The IP type of the Cloud SQL instance.
60+
The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc".
6161
refresh_strategy (Optional[str]):
6262
Refresh strategy for the Cloud SQL Connector. Can be one of "lazy"
6363
or "background". For serverless environments use "lazy" to avoid
@@ -73,7 +73,7 @@ def create_sqlalchemy_engine(
7373
"pymysql",
7474
user=user,
7575
db=db,
76-
ip_type=ip_type,
76+
ip_type=ip_type, # can be "public", "private" or "psc"
7777
enable_iam_auth=True,
7878
),
7979
)
@@ -85,7 +85,7 @@ def test_pymysql_iam_authn_connection() -> None:
8585
inst_conn_name = os.environ["MYSQL_CONNECTION_NAME"]
8686
user = os.environ["MYSQL_IAM_USER"]
8787
db = os.environ["MYSQL_DB"]
88-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
88+
ip_type = os.environ.get("IP_TYPE", "public")
8989

9090
engine, connector = create_sqlalchemy_engine(inst_conn_name, user, db, ip_type)
9191
with engine.connect() as conn:
@@ -101,7 +101,7 @@ def test_lazy_pymysql_iam_authn_connection() -> None:
101101
inst_conn_name = os.environ["MYSQL_CONNECTION_NAME"]
102102
user = os.environ["MYSQL_IAM_USER"]
103103
db = os.environ["MYSQL_DB"]
104-
ip_type = os.environ.get("IP_TYPE", "public") # can be "public", "private" or "psc"
104+
ip_type = os.environ.get("IP_TYPE", "public")
105105

106106
engine, connector = create_sqlalchemy_engine(
107107
inst_conn_name, user, db, ip_type, "lazy"

0 commit comments

Comments
 (0)