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

feat: support basic user/password auth with MySQLEngine #17

Merged
merged 5 commits into from
Feb 9, 2024

Conversation

jackwotherspoon
Copy link
Contributor

Adding basic user/password auth support to MySQLEngine.from_instance() through optional user and password args.

@jackwotherspoon jackwotherspoon self-assigned this Feb 8, 2024
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner February 8, 2024 20:58
@product-auto-label product-auto-label bot added the api: cloudsql-mysql Issues related to the googleapis/langchain-google-cloud-sql-mysql-python API. label Feb 8, 2024
Comment on lines +30 to +31
# override MySQLEngine._connector to allow a new Connector to be initiated
MySQLEngine._connector = None
Copy link
Contributor Author

@jackwotherspoon jackwotherspoon Feb 8, 2024

Choose a reason for hiding this comment

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

this is required for testing purposes because MySQLEngine._connector is a class attribute to be re-used across engines. However, the Cloud SQL Python Connector does not allow the same connector to be called with enable_iam_auth set to False and then also be called with it set to True which happens when you create an engine with basic auth and then again with defaulting to iam authn.

I think customers would use one or the other, i don't see a use-case for customers wanting to use both.

)
iam_database_user = _get_iam_principal_email(credentials)
# if user and password are given, use basic auth
if user and password:
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we throw an error if they specify user and not password (or vica versa)?

Copy link
Contributor Author

@jackwotherspoon jackwotherspoon Feb 9, 2024

Choose a reason for hiding this comment

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

added an error, catching it up a level using XOR logic in the .from_instance() class method for easier developer experience with stacktrace coming from a public method instead of the internal _create_connector_engine

@jackwotherspoon jackwotherspoon merged commit d462a3c into main Feb 9, 2024
8 checks passed
@jackwotherspoon jackwotherspoon deleted the basic-auth branch February 9, 2024 02:24
@release-please release-please bot mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudsql-mysql Issues related to the googleapis/langchain-google-cloud-sql-mysql-python API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants