-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Create database connections from pre-configured SSL Socket #71
Comments
What about |
The Cloud SQL connections are made via connecting to a server side proxy which then establishes the connection to the MySQL database itself. Because of this we need to skip the However, after thinking it through for the past few months I think a better approach is to use a Maybe for That way the Cloud SQL Python Connector could have the implementation code as follows: import asyncio
import ssl
from typing import Any, TYPE_CHECKING
SERVER_PROXY_PORT = 3307
if TYPE_CHECKING:
import asyncmy
async def connect(
ip_address: str, ctx: ssl.SSLContext, **kwargs: Any
) -> "asyncmy.Connection":
"""Helper function to create an asyncmy DB-API connection object.
:type ip_address: str
:param ip_address: A string containing an IP address for the Cloud SQL
instance.
:type ctx: ssl.SSLContext
:param ctx: An SSLContext object created from the Cloud SQL server CA
cert and ephemeral cert.
:type kwargs: Any
:param kwargs: Keyword arguments for establishing asyncmy connection
object to Cloud SQL instance.
:rtype: asyncmy.Connection
:returns: An asyncmy.Connection object to a Cloud SQL instance.
"""
try:
import asyncmy
except ImportError:
raise ImportError(
'Unable to import module "asyncmy." Please install and try again.'
)
user = kwargs.pop("user")
db = kwargs.pop("db")
# allow automatic IAM database authentication to not require password
passwd = kwargs.pop("password", None)
reader, writer = await asyncio.open_connection(ip_address, SERVER_PROXY_PORT, server_hostname=ip_address, ssl=ctx)
return await asyncmy.connect(
user=user,
database=db,
password=passwd,
sock=(reader, writer),
**kwargs,
) Is this something that seems like a viable feature request to you? Happy to begin working on it if so 😄 |
hey @long2ice -- is this something you'd be interested in taking as a PR? We'd love to add support for this driver in the Cloud SQL python connector |
Is there the ability in
asyncmy
to create database connections from a pre-configured SSL/TLS Socket?Pymysql allows a
sock
argument to it'sconnect
method (code) that allows passing in a pre-configured socket, wondering if asyncmy has something equivalent in the asyncio context?I ask because the Cloud SQL Python Connector would like to support
asyncmy
as a driver option for connecting to Google Cloud SQL instances. Currently the only MySQL driver we support ispymysql
(code) as we need the ability to pass in a pre-configured SSL socket/connection. I wonder if this is possible with asyncmy?Let me know, happy to give further details 😄
The text was updated successfully, but these errors were encountered: