Skip to content
Merged
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
6 changes: 5 additions & 1 deletion google/cloud/sql/connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ def __init__(
# set default params for connections
self._timeout = timeout
self._enable_iam_auth = enable_iam_auth
self._quota_project = quota_project
self._user_agent = user_agent
self._resolver = resolver()
# if ip_type is str, convert to IPTypes enum
if isinstance(ip_type, str):
ip_type = IPTypes._from_str(ip_type)
self._ip_type = ip_type
# check for quota project arg and then env var
if quota_project:
self._quota_project = quota_project
else:
self._quota_project = os.environ.get("GOOGLE_CLOUD_QUOTA_PROJECT") # type: ignore
# check for universe domain arg and then env var
if universe_domain:
self._universe_domain = universe_domain
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,20 @@ def test_configured_universe_domain_env_var(
assert connector._sqladmin_api_endpoint == f"https://sqladmin.{universe_domain}"
# unset env var
del os.environ["GOOGLE_CLOUD_UNIVERSE_DOMAIN"]


def test_configured_quota_project_env_var(
fake_credentials: Credentials,
) -> None:
"""Test that configured quota project succeeds with quota project
set via GOOGLE_CLOUD_QUOTA_PROJECT env var.
"""
quota_project = "my-cool-project"
# set environment variable
os.environ["GOOGLE_CLOUD_QUOTA_PROJECT"] = quota_project
# Note: we are not passing quota_project arg, env var should set it
with Connector(credentials=fake_credentials) as connector:
# test quota project was configured
assert connector._quota_project == quota_project
# unset env var
del os.environ["GOOGLE_CLOUD_QUOTA_PROJECT"]
Loading