23
23
from google .api_core .gapic_v1 .client_info import ClientInfo
24
24
from google .auth .credentials import TokenState
25
25
from google .auth .transport import requests
26
+ import google .cloud .alloydb_v1beta as v1beta
27
+ from google .protobuf import duration_pb2
26
28
27
- from google .cloud import alloydb_v1beta
28
29
from google .cloud .alloydb .connector .connection_info import ConnectionInfo
29
30
from google .cloud .alloydb .connector .version import __version__ as version
30
- from google .protobuf import duration_pb2
31
31
32
32
if TYPE_CHECKING :
33
33
from google .auth .credentials import Credentials
@@ -58,7 +58,7 @@ def __init__(
58
58
alloydb_api_endpoint : str ,
59
59
quota_project : Optional [str ],
60
60
credentials : Credentials ,
61
- client : Optional [alloydb_v1beta .AlloyDBAdminAsyncClient ] = None ,
61
+ client : Optional [v1beta .AlloyDBAdminAsyncClient ] = None ,
62
62
driver : Optional [str ] = None ,
63
63
user_agent : Optional [str ] = None ,
64
64
) -> None :
@@ -75,22 +75,26 @@ def __init__(
75
75
A credentials object created from the google-auth Python library.
76
76
Must have the AlloyDB Admin scopes. For more info check out
77
77
https://google-auth.readthedocs.io/en/latest/.
78
- client (alloydb_v1beta .AlloyDBAdminAsyncClient): Async client used to
79
- make requests to AlloyDB APIs.
78
+ client (v1beta .AlloyDBAdminAsyncClient): Async client used to make
79
+ requests to AlloyDB APIs.
80
80
Optional, defaults to None and creates new client.
81
81
driver (str): Database driver to be used by the client.
82
82
"""
83
83
user_agent = _format_user_agent (driver , user_agent )
84
84
85
- self ._client = client if client else alloydb_v1beta .AlloyDBAdminAsyncClient (
86
- credentials = credentials ,
87
- client_options = ClientOptions (
88
- api_endpoint = alloydb_api_endpoint ,
89
- quota_project_id = quota_project ,
90
- ),
91
- client_info = ClientInfo (
92
- user_agent = user_agent ,
93
- ),
85
+ self ._client = (
86
+ client
87
+ if client
88
+ else v1beta .AlloyDBAdminAsyncClient (
89
+ credentials = credentials ,
90
+ client_options = ClientOptions (
91
+ api_endpoint = alloydb_api_endpoint ,
92
+ quota_project_id = quota_project ,
93
+ ),
94
+ client_info = ClientInfo (
95
+ user_agent = user_agent ,
96
+ ),
97
+ )
94
98
)
95
99
self ._credentials = credentials
96
100
# asyncpg does not currently support using metadata exchange
@@ -122,9 +126,11 @@ async def _get_metadata(
122
126
Returns:
123
127
dict: IP addresses of the AlloyDB instance.
124
128
"""
125
- parent = f"projects/{ project } /locations/{ region } /clusters/{ cluster } /instances/{ name } "
129
+ parent = (
130
+ f"projects/{ project } /locations/{ region } /clusters/{ cluster } /instances/{ name } "
131
+ )
126
132
127
- req = alloydb_v1beta .GetConnectionInfoRequest (parent = parent )
133
+ req = v1beta .GetConnectionInfoRequest (parent = parent )
128
134
resp = await self ._client .get_connection_info (request = req )
129
135
130
136
# Remove trailing period from PSC DNS name.
@@ -166,7 +172,7 @@ async def _get_client_certificate(
166
172
parent = f"projects/{ project } /locations/{ region } /clusters/{ cluster } "
167
173
dur = duration_pb2 .Duration ()
168
174
dur .seconds = 3600
169
- req = alloydb_v1beta .GenerateClientCertificateRequest (
175
+ req = v1beta .GenerateClientCertificateRequest (
170
176
parent = parent ,
171
177
cert_duration = dur ,
172
178
public_key = pub_key ,
0 commit comments