Skip to content
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

refactor: update AlloyDBClient and ConnectionInfo classes #335

Merged
merged 4 commits into from
Jun 24, 2024

Conversation

jackwotherspoon
Copy link
Collaborator

@jackwotherspoon jackwotherspoon commented Jun 24, 2024

Refactor of AlloyDBClient and ConnectionInfo classes.

Added the get_connection_info method to the AlloyDBClient.
This method does an immediate refresh and calls the AlloyDB APIs
to get a fresh ConnectionInfo. This allows better encapsulation.

Refactored ConnectionInfo to a dataclass and added two new methods;
create_ssl_context and get_preferred_ip. Moved all SSL/TLS configuration
within create_ssl_context. This way ConnectionInfo() prepares all the info
required to connect and then create_ssl_context will use the info to establish
the SSL/TLS connection when called from Connector.connect at the time of
connection.

Port of GoogleCloudPlatform/cloud-sql-python-connector#1079 and GoogleCloudPlatform/cloud-sql-python-connector#1090

Related to #298

@jackwotherspoon jackwotherspoon self-assigned this Jun 24, 2024
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner June 24, 2024 15:01
@@ -236,6 +238,55 @@ async def _get_client_certificate(
).decode("UTF-8")
return (server_cert, [client_cert, intermediate_cert, root_cert])

async def get_connection_info(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will have a follow-up PR to clean up the FakeAlloyDBClient mock to remove this copy/paste code.

@jackwotherspoon jackwotherspoon merged commit 5b1c57d into main Jun 24, 2024
14 of 15 checks passed
@jackwotherspoon jackwotherspoon deleted the connection-info branch June 24, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants