Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ function write_e2e_env(){

}

## with_venv - runs a command with the venv activated
function with_venv() {
"$@"
}

## help - prints the help details
##
function help() {
Expand Down
33 changes: 33 additions & 0 deletions build/lib/google/cloud/sql/connector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Copyright 2019 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from google.cloud.sql.connector.connector import Connector
from google.cloud.sql.connector.connector import create_async_connector
from google.cloud.sql.connector.enums import IPTypes
from google.cloud.sql.connector.enums import RefreshStrategy
from google.cloud.sql.connector.resolver import DefaultResolver
from google.cloud.sql.connector.resolver import DnsResolver
from google.cloud.sql.connector.version import __version__

__all__ = [
"__version__",
"create_async_connector",
"Connector",
"DefaultResolver",
"DnsResolver",
"IPTypes",
"RefreshStrategy",
]
69 changes: 69 additions & 0 deletions build/lib/google/cloud/sql/connector/asyncpg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import ssl
from typing import Any, Optional, TYPE_CHECKING

SERVER_PROXY_PORT = 3307

if TYPE_CHECKING:
import asyncpg


async def connect(
ip_address: str, ctx: Optional[ssl.SSLContext], **kwargs: Any
) -> "asyncpg.Connection":
"""Helper function to create an asyncpg DB-API connection object.

Args:
ip_address (str): A string containing an IP address for the Cloud SQL
instance.
ctx (ssl.SSLContext): An SSLContext object created from the Cloud SQL
server CA cert and ephemeral cert. Pass None to disable SSL.
kwargs: Keyword arguments for establishing asyncpg connection
object to Cloud SQL instance.

Returns:
asyncpg.Connection: An asyncpg connection to the Cloud SQL
instance.
Raises:
ImportError: The asyncpg module cannot be imported.
"""

try:
import asyncpg
except ImportError:
raise ImportError(
'Unable to import module "asyncpg." Please install and try again.'
)
user = kwargs.pop("user")
db = kwargs.pop("db")
passwd = kwargs.pop("password", None)
port = kwargs.pop("port", SERVER_PROXY_PORT)

connect_args = {
"user": user,
"database": db,
"password": passwd,
"host": ip_address,
"port": port,
**kwargs,
}
if ctx is not None:
connect_args["ssl"] = ctx
connect_args["direct_tls"] = True

return await asyncpg.connect(**connect_args)
Loading