-
Notifications
You must be signed in to change notification settings - Fork 83
test: update ip type for connectors #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eba2228
feat: update ip type for connectors
kgala2 6f06ebf
chore: update ip_type parameter in system tests
kgala2 6d60f5a
chore: update test_async_conn ip_type param
kgala2 8d614b9
chore: update lint for all files
kgala2 f497349
chore: update default ip_type for connector engine
kgala2 4a4d43d
chore: edit test_ip_types comment
kgala2 15a16e5
chore: update docstrings comment
kgala2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ async def create_sqlalchemy_engine( | |
| instance_connection_name: str, | ||
| user: str, | ||
| db: str, | ||
| ip_type: str = "public", | ||
| refresh_strategy: str = "background", | ||
| ) -> tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]: | ||
| """Creates a connection pool for a Cloud SQL instance and returns the pool | ||
|
|
@@ -55,6 +56,8 @@ async def create_sqlalchemy_engine( | |
| e.g., [email protected], [email protected] | ||
| db (str): | ||
| The name of the database, e.g., mydb | ||
| ip_type (str): | ||
| The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc". | ||
| refresh_strategy (Optional[str]): | ||
| Refresh strategy for the Cloud SQL Connector. Can be one of "lazy" | ||
| or "background". For serverless environments use "lazy" to avoid | ||
|
|
@@ -71,7 +74,7 @@ async def create_sqlalchemy_engine( | |
| "asyncpg", | ||
| user=user, | ||
| db=db, | ||
| ip_type="public", # can also be "private" or "psc" | ||
| ip_type=ip_type, # can be "public", "private" or "psc" | ||
| enable_iam_auth=True, | ||
| ), | ||
| execution_options={"isolation_level": "AUTOCOMMIT"}, | ||
|
|
@@ -84,8 +87,9 @@ async def test_iam_authn_connection_with_asyncpg() -> None: | |
| inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"] | ||
| user = os.environ["POSTGRES_IAM_USER"] | ||
| db = os.environ["POSTGRES_DB"] | ||
| ip_type = os.environ.get("IP_TYPE", "public") | ||
|
|
||
| pool, connector = await create_sqlalchemy_engine(inst_conn_name, user, db) | ||
| pool, connector = await create_sqlalchemy_engine(inst_conn_name, user, db, ip_type) | ||
|
|
||
| async with pool.connect() as conn: | ||
| res = (await conn.execute(sqlalchemy.text("SELECT 1"))).fetchone() | ||
|
|
@@ -99,8 +103,11 @@ async def test_lazy_iam_authn_connection_with_asyncpg() -> None: | |
| inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"] | ||
| user = os.environ["POSTGRES_IAM_USER"] | ||
| db = os.environ["POSTGRES_DB"] | ||
| ip_type = os.environ.get("IP_TYPE", "public") | ||
|
|
||
| pool, connector = await create_sqlalchemy_engine(inst_conn_name, user, db, "lazy") | ||
| pool, connector = await create_sqlalchemy_engine( | ||
| inst_conn_name, user, db, ip_type, "lazy" | ||
| ) | ||
|
|
||
| async with pool.connect() as conn: | ||
| res = (await conn.execute(sqlalchemy.text("SELECT 1"))).fetchone() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ def create_sqlalchemy_engine( | |
| instance_connection_name: str, | ||
| user: str, | ||
| db: str, | ||
| ip_type: str = "public", | ||
| refresh_strategy: str = "background", | ||
| ) -> tuple[sqlalchemy.engine.Engine, Connector]: | ||
| """Creates a connection pool for a Cloud SQL instance and returns the pool | ||
|
|
@@ -55,6 +56,8 @@ def create_sqlalchemy_engine( | |
| e.g., [email protected], [email protected] | ||
| db (str): | ||
| The name of the database, e.g., mydb | ||
| ip_type (str): | ||
| The IP type of the Cloud SQL instance. Can be one of "public", "private", or "psc". | ||
| refresh_strategy (Optional[str]): | ||
| Refresh strategy for the Cloud SQL Connector. Can be one of "lazy" | ||
| or "background". For serverless environments use "lazy" to avoid | ||
|
|
@@ -70,7 +73,7 @@ def create_sqlalchemy_engine( | |
| "pg8000", | ||
| user=user, | ||
| db=db, | ||
| ip_type="public", # can also be "private" or "psc" | ||
| ip_type=ip_type, # can be "public", "private" or "psc" | ||
| enable_iam_auth=True, | ||
| ), | ||
| ) | ||
|
|
@@ -82,8 +85,9 @@ def test_pg8000_iam_authn_connection() -> None: | |
| inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"] | ||
| user = os.environ["POSTGRES_IAM_USER"] | ||
| db = os.environ["POSTGRES_DB"] | ||
| ip_type = os.environ.get("IP_TYPE", "public") | ||
|
|
||
| engine, connector = create_sqlalchemy_engine(inst_conn_name, user, db) | ||
| engine, connector = create_sqlalchemy_engine(inst_conn_name, user, db, ip_type) | ||
| with engine.connect() as conn: | ||
| time = conn.execute(sqlalchemy.text("SELECT NOW()")).fetchone() | ||
| conn.commit() | ||
|
|
@@ -97,8 +101,11 @@ def test_lazy_pg8000_iam_authn_connection() -> None: | |
| inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"] | ||
| user = os.environ["POSTGRES_IAM_USER"] | ||
| db = os.environ["POSTGRES_DB"] | ||
| ip_type = os.environ.get("IP_TYPE", "public") | ||
|
|
||
| engine, connector = create_sqlalchemy_engine(inst_conn_name, user, db, "lazy") | ||
| engine, connector = create_sqlalchemy_engine( | ||
| inst_conn_name, user, db, ip_type, "lazy" | ||
| ) | ||
| with engine.connect() as conn: | ||
| time = conn.execute(sqlalchemy.text("SELECT NOW()")).fetchone() | ||
| conn.commit() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.