@@ -112,97 +112,70 @@ def __init__(
112
112
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
113
113
and ``credentials_file`` are passed.
114
114
"""
115
+ self ._grpc_channel = None
115
116
self ._ssl_channel_credentials = ssl_channel_credentials
117
+ self ._stubs : Dict [str , Callable ] = {}
118
+ self ._operations_client = None
116
119
117
120
if api_mtls_endpoint :
118
121
warnings .warn ("api_mtls_endpoint is deprecated" , DeprecationWarning )
119
122
if client_cert_source :
120
123
warnings .warn ("client_cert_source is deprecated" , DeprecationWarning )
121
124
122
125
if channel :
123
- # Sanity check: Ensure that channel and credentials are not both
124
- # provided.
126
+ # Ignore credentials if a channel was passed.
125
127
credentials = False
126
-
127
128
# If a channel was explicitly provided, set it.
128
129
self ._grpc_channel = channel
129
130
self ._ssl_channel_credentials = None
130
- elif api_mtls_endpoint :
131
- host = (
132
- api_mtls_endpoint
133
- if ":" in api_mtls_endpoint
134
- else api_mtls_endpoint + ":443"
135
- )
136
-
137
- if credentials is None :
138
- credentials , _ = auth .default (
139
- scopes = self .AUTH_SCOPES , quota_project_id = quota_project_id
140
- )
141
-
142
- # Create SSL credentials with client_cert_source or application
143
- # default SSL credentials.
144
- if client_cert_source :
145
- cert , key = client_cert_source ()
146
- ssl_credentials = grpc .ssl_channel_credentials (
147
- certificate_chain = cert , private_key = key
148
- )
149
- else :
150
- ssl_credentials = SslCredentials ().ssl_credentials
151
131
152
- # create a new channel. The provided one is ignored.
153
- self ._grpc_channel = type (self ).create_channel (
154
- host ,
155
- credentials = credentials ,
156
- credentials_file = credentials_file ,
157
- ssl_credentials = ssl_credentials ,
158
- scopes = scopes or self .AUTH_SCOPES ,
159
- quota_project_id = quota_project_id ,
160
- options = [
161
- ("grpc.max_send_message_length" , - 1 ),
162
- ("grpc.max_receive_message_length" , - 1 ),
163
- ],
164
- )
165
- self ._ssl_channel_credentials = ssl_credentials
166
132
else :
167
- host = host if ":" in host else host + ":443"
133
+ if api_mtls_endpoint :
134
+ host = api_mtls_endpoint
135
+
136
+ # Create SSL credentials with client_cert_source or application
137
+ # default SSL credentials.
138
+ if client_cert_source :
139
+ cert , key = client_cert_source ()
140
+ self ._ssl_channel_credentials = grpc .ssl_channel_credentials (
141
+ certificate_chain = cert , private_key = key
142
+ )
143
+ else :
144
+ self ._ssl_channel_credentials = SslCredentials ().ssl_credentials
168
145
169
- if credentials is None :
170
- credentials , _ = auth .default (
171
- scopes = self .AUTH_SCOPES , quota_project_id = quota_project_id
172
- )
146
+ else :
147
+ if client_cert_source_for_mtls and not ssl_channel_credentials :
148
+ cert , key = client_cert_source_for_mtls ()
149
+ self ._ssl_channel_credentials = grpc .ssl_channel_credentials (
150
+ certificate_chain = cert , private_key = key
151
+ )
173
152
174
- if client_cert_source_for_mtls and not ssl_channel_credentials :
175
- cert , key = client_cert_source_for_mtls ()
176
- self ._ssl_channel_credentials = grpc .ssl_channel_credentials (
177
- certificate_chain = cert , private_key = key
178
- )
153
+ # The base transport sets the host, credentials and scopes
154
+ super ().__init__ (
155
+ host = host ,
156
+ credentials = credentials ,
157
+ credentials_file = credentials_file ,
158
+ scopes = scopes ,
159
+ quota_project_id = quota_project_id ,
160
+ client_info = client_info ,
161
+ )
179
162
180
- # create a new channel. The provided one is ignored.
163
+ if not self . _grpc_channel :
181
164
self ._grpc_channel = type (self ).create_channel (
182
- host ,
183
- credentials = credentials ,
165
+ self . _host ,
166
+ credentials = self . _credentials ,
184
167
credentials_file = credentials_file ,
168
+ scopes = self ._scopes ,
185
169
ssl_credentials = self ._ssl_channel_credentials ,
186
- scopes = scopes or self .AUTH_SCOPES ,
187
170
quota_project_id = quota_project_id ,
188
171
options = [
189
172
("grpc.max_send_message_length" , - 1 ),
190
173
("grpc.max_receive_message_length" , - 1 ),
191
174
],
192
175
)
193
176
194
- self ._stubs = {} # type: Dict[str, Callable]
195
- self ._operations_client = None
196
-
197
- # Run the base constructor.
198
- super ().__init__ (
199
- host = host ,
200
- credentials = credentials ,
201
- credentials_file = credentials_file ,
202
- scopes = scopes or self .AUTH_SCOPES ,
203
- quota_project_id = quota_project_id ,
204
- client_info = client_info ,
205
- )
177
+ # Wrap messages. This must be done after self._grpc_channel exists
178
+ self ._prep_wrapped_messages (client_info )
206
179
207
180
@classmethod
208
181
def create_channel (
@@ -216,7 +189,7 @@ def create_channel(
216
189
) -> grpc .Channel :
217
190
"""Create and return a gRPC channel object.
218
191
Args:
219
- address (Optional[str]): The host for the channel to use.
192
+ host (Optional[str]): The host for the channel to use.
220
193
credentials (Optional[~.Credentials]): The
221
194
authorization credentials to attach to requests. These
222
195
credentials identify this application to the service. If
0 commit comments