GoogleCloudPlatform / alloydb-python-connector

A Python library for connecting securely to your AlloyDB instances.
Apache License 2.0
25 stars 6 forks source link

refactor: update AlloyDBClient and ConnectionInfo classes #335

Closed jackwotherspoon closed 2 weeks ago

jackwotherspoon commented 2 weeks ago

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 https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/pull/1079 and https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/pull/1090

Related to #298