19
19
from typing import Dict ,Optional ,Type ,Union
20
20
21
21
from google .api_core import client_options as client_options_lib # type: ignore
22
+ from google .api_core import exceptions as core_exceptions # type: ignore
22
23
from google .api_core import gapic_v1 # type: ignore
23
24
from google .api_core .operations_v1 .transports .base import (
24
25
DEFAULT_CLIENT_INFO ,
39
40
from google .auth import credentials as ga_credentials # type: ignore
40
41
from google .auth .exceptions import MutualTLSChannelError # type: ignore
41
42
from google .auth .transport import mtls # type: ignore
42
- from google .oauth2 import service_account # type: ignore
43
43
44
44
45
45
class AbstractOperationsBaseClientMeta (type ):
@@ -143,9 +143,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs):
143
143
Returns:
144
144
AbstractOperationsClient: The constructed client.
145
145
"""
146
- credentials = service_account .Credentials .from_service_account_info (info )
147
- kwargs ["credentials" ]= credentials
148
- return cls (* args ,** kwargs )
146
+ raise NotImplementedError ("`from_service_account_info` is not implemented." )
149
147
150
148
@classmethod
151
149
def from_service_account_file (cls ,filename :str ,* args ,** kwargs ):
@@ -161,9 +159,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
161
159
Returns:
162
160
AbstractOperationsClient: The constructed client.
163
161
"""
164
- credentials = service_account .Credentials .from_service_account_file (filename )
165
- kwargs ["credentials" ]= credentials
166
- return cls (* args ,** kwargs )
162
+ raise NotImplementedError ("`from_service_account_file` is not implemented." )
167
163
168
164
from_service_account_json = from_service_account_file
169
165
@@ -362,15 +358,38 @@ def __init__(
362
358
)
363
359
self ._transport = transport
364
360
else :
365
- # TODO (WIP): This code block will fail becuase async rest layer does not support all params.
366
361
Transport = type (self ).get_transport_class (transport )
367
- self ._transport = Transport (
368
- credentials = credentials ,
369
- credentials_file = client_options .credentials_file ,
370
- host = api_endpoint ,
371
- scopes = client_options .scopes ,
372
- client_cert_source_for_mtls = client_cert_source_func ,
373
- quota_project_id = client_options .quota_project_id ,
374
- client_info = client_info ,
375
- always_use_jwt_access = True ,
376
- )
362
+ if "async" in str (Transport ).lower ():
363
+ # TODO(https://github.com/googleapis/gapic-generator-python/issues/2136): Support the following parameters in async rest.
364
+ unsupported_params = {
365
+ "google.api_core.client_options.ClientOptions.credentials_file" :client_options .credentials_file ,
366
+ "google.api_core.client_options.ClientOptions.scopes" :client_options .scopes ,
367
+ "google.api_core.client_options.ClientOptions.quota_project_id" :client_options .quota_project_id ,
368
+ "google.api_core.client_options.ClientOptions.client_cert_source" :client_options .client_cert_source ,
369
+ "google.api_core.client_options.ClientOptions.api_audience" :client_options .api_audience ,
370
+ }
371
+ provided_unsupported_params = [
372
+ name
373
+ for name ,value in unsupported_params .items ()
374
+ if value is not None
375
+ ]
376
+ if provided_unsupported_params :
377
+ raise core_exceptions .AsyncRestUnsupportedParameterError (
378
+ f"The following provided parameters are not supported for `transport=rest_asyncio`:{ ', ' .join (provided_unsupported_params )} "
379
+ )
380
+ self ._transport = Transport (
381
+ credentials = credentials ,
382
+ host = api_endpoint ,
383
+ client_info = client_info ,
384
+ )
385
+ else :
386
+ self ._transport = Transport (
387
+ credentials = credentials ,
388
+ credentials_file = client_options .credentials_file ,
389
+ host = api_endpoint ,
390
+ scopes = client_options .scopes ,
391
+ client_cert_source_for_mtls = client_cert_source_func ,
392
+ quota_project_id = client_options .quota_project_id ,
393
+ client_info = client_info ,
394
+ always_use_jwt_access = True ,
395
+ )