Skip to content

Commit 5fe0823

Browse files
address PR comments
1 parent 73b9ac3 commit 5fe0823

4 files changed

Lines changed: 9 additions & 40 deletions

File tree

google/cloud/alloydbconnector/async_connector.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ class AsyncConnector:
5252
Admin API.
5353
db_credentials (google.auth.credentials.Credentials):
5454
A credentials object created from the google-auth Python library.
55+
This is only used when Auto IAM AuthN is enabled.
5556
If not specified, the credentials used for authenticating with the
5657
AlloyDB Admin API will also be used to authenticate with the DB.
58+
If specified, the credential's scope should be
59+
"https://www.googleapis.com/auth/alloydb.login".
5760
quota_project (str): The Project ID for an existing Google Cloud
5861
project. The project specified is used for quota and
5962
billing purposes.
@@ -103,14 +106,12 @@ def __init__(
103106
else:
104107
self._credentials, _ = google.auth.default(scopes=scopes)
105108
# initialize credentials for authenticating with the DB
106-
scopes = ["https://www.googleapis.com/auth/alloydb.login"]
107109
if db_credentials:
108-
self._db_credentials = with_scopes_if_required(
109-
db_credentials, scopes=scopes
110-
)
110+
self._db_credentials = db_credentials
111111
# otherwise use the same credentials as the one for authenticating with
112112
# AlloyDB Admin API
113113
else:
114+
scopes = ["https://www.googleapis.com/auth/alloydb.login"]
114115
self._db_credentials = with_scopes_if_required(
115116
self._credentials, scopes=scopes
116117
)

google/cloud/alloydbconnector/connector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class Connector:
6868
A credentials object created from the google-auth Python library.
6969
If not specified, the credentials used for authenticating with the
7070
AlloyDB Admin API will also be used to authenticate with the DB.
71+
If specified, the credential's scope should be
72+
"https://www.googleapis.com/auth/alloydb.login".
7173
quota_project (str): The Project ID for an existing Google Cloud
7274
project. The project specified is used for quota and
7375
billing purposes.
@@ -128,14 +130,12 @@ def __init__(
128130
else:
129131
self._credentials, _ = default(scopes=scopes)
130132
# initialize credentials for authenticating with the DB
131-
scopes = ["https://www.googleapis.com/auth/alloydb.login"]
132133
if db_credentials:
133-
self._db_credentials = with_scopes_if_required(
134-
db_credentials, scopes=scopes
135-
)
134+
self._db_credentials = db_credentials
136135
# otherwise use the same credentials as the one for authenticating with
137136
# AlloyDB Admin API
138137
else:
138+
scopes = ["https://www.googleapis.com/auth/alloydb.login"]
139139
self._db_credentials = with_scopes_if_required(
140140
self._credentials, scopes=scopes
141141
)

tests/unit/test_async_connector.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,6 @@ async def test_AsyncConnector_init_scopes() -> None:
8181
await connector.close()
8282

8383

84-
async def test_AsyncConnector_init_db_credentials_scopes(
85-
credentials: FakeCredentials,
86-
) -> None:
87-
"""
88-
Test to check whether the __init__ method of AsyncConnector
89-
properly sets the DB credential's scopes when DB credentials
90-
are specified.
91-
"""
92-
db_credentials = FakeCredentialsRequiresScopes()
93-
connector = AsyncConnector(credentials, db_credentials)
94-
assert connector._db_credentials != db_credentials
95-
assert connector._db_credentials._scopes == [
96-
"https://www.googleapis.com/auth/alloydb.login"
97-
]
98-
await connector.close()
99-
100-
10184
@pytest.mark.parametrize(
10285
"ip_type, expected",
10386
[

tests/unit/test_connector.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,6 @@ def test_Connector_init_scopes() -> None:
7878
connector.close()
7979

8080

81-
def test_Connector_init_db_credentials_scopes(credentials: FakeCredentials) -> None:
82-
"""
83-
Test to check whether the __init__ method of Connector
84-
properly sets the DB credential's scopes when DB credentials
85-
are specified.
86-
"""
87-
db_credentials = FakeCredentialsRequiresScopes()
88-
connector = Connector(credentials, db_credentials)
89-
assert connector._db_credentials != db_credentials
90-
assert connector._db_credentials._scopes == [
91-
"https://www.googleapis.com/auth/alloydb.login"
92-
]
93-
connector.close()
94-
95-
9681
def test_Connector_init_bad_ip_type(credentials: FakeCredentials) -> None:
9782
"""Test that Connector errors due to bad ip_type str."""
9883
bad_ip_type = "BAD-IP-TYPE"

0 commit comments

Comments
 (0)