2525from google .api_core import retry as retries # type: ignore
2626from google .api_core import operations_v1 # type: ignore
2727from google .auth import credentials as ga_credentials # type: ignore
28+ from google .oauth2 import service_account # type: ignore
2829
2930from google .cloud .asset_v1 .types import asset_service
3031from google .longrunning import operations_pb2 # type: ignore
4647 except pkg_resources .DistributionNotFound : # pragma: NO COVER
4748 _GOOGLE_AUTH_VERSION = None
4849
49- _API_CORE_VERSION = google .api_core .__version__
50-
5150
5251class AssetServiceTransport (abc .ABC ):
5352 """Abstract transport class for AssetService."""
@@ -65,6 +64,7 @@ def __init__(
6564 scopes : Optional [Sequence [str ]] = None ,
6665 quota_project_id : Optional [str ] = None ,
6766 client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
67+ always_use_jwt_access : Optional [bool ] = False ,
6868 ** kwargs ,
6969 ) -> None :
7070 """Instantiate the transport.
@@ -88,6 +88,8 @@ def __init__(
8888 API requests. If ``None``, then default info will be used.
8989 Generally, you only need to set this if you're developing
9090 your own client library.
91+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
92+ be used for service account credentials.
9193 """
9294 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
9395 if ":" not in host :
@@ -97,7 +99,7 @@ def __init__(
9799 scopes_kwargs = self ._get_scopes_kwargs (self ._host , scopes )
98100
99101 # Save the scopes.
100- self ._scopes = scopes or self . AUTH_SCOPES
102+ self ._scopes = scopes
101103
102104 # If no credentials are provided, then determine the appropriate
103105 # defaults.
@@ -116,13 +118,20 @@ def __init__(
116118 ** scopes_kwargs , quota_project_id = quota_project_id
117119 )
118120
121+ # If the credentials is service account credentials, then always try to use self signed JWT.
122+ if (
123+ always_use_jwt_access
124+ and isinstance (credentials , service_account .Credentials )
125+ and hasattr (service_account .Credentials , "with_always_use_jwt_access" )
126+ ):
127+ credentials = credentials .with_always_use_jwt_access (True )
128+
119129 # Save the credentials.
120130 self ._credentials = credentials
121131
122- # TODO(busunkim): These two class methods are in the base transport
132+ # TODO(busunkim): This method is in the base transport
123133 # to avoid duplicating code across the transport classes. These functions
124- # should be deleted once the minimum required versions of google-api-core
125- # and google-auth are increased.
134+ # should be deleted once the minimum required versions of google-auth is increased.
126135
127136 # TODO: Remove this function once google-auth >= 1.25.0 is required
128137 @classmethod
@@ -143,27 +152,6 @@ def _get_scopes_kwargs(
143152
144153 return scopes_kwargs
145154
146- # TODO: Remove this function once google-api-core >= 1.26.0 is required
147- @classmethod
148- def _get_self_signed_jwt_kwargs (
149- cls , host : str , scopes : Optional [Sequence [str ]]
150- ) -> Dict [str , Union [Optional [Sequence [str ]], str ]]:
151- """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
152-
153- self_signed_jwt_kwargs : Dict [str , Union [Optional [Sequence [str ]], str ]] = {}
154-
155- if _API_CORE_VERSION and (
156- packaging .version .parse (_API_CORE_VERSION )
157- >= packaging .version .parse ("1.26.0" )
158- ):
159- self_signed_jwt_kwargs ["default_scopes" ] = cls .AUTH_SCOPES
160- self_signed_jwt_kwargs ["scopes" ] = scopes
161- self_signed_jwt_kwargs ["default_host" ] = cls .DEFAULT_HOST
162- else :
163- self_signed_jwt_kwargs ["scopes" ] = scopes or cls .AUTH_SCOPES
164-
165- return self_signed_jwt_kwargs
166-
167155 def _prep_wrapped_messages (self , client_info ):
168156 # Precompute the wrapped methods.
169157 self ._wrapped_methods = {
@@ -258,12 +246,11 @@ def _prep_wrapped_messages(self, client_info):
258246 maximum = 60.0 ,
259247 multiplier = 1.3 ,
260248 predicate = retries .if_exception_type (
261- core_exceptions .DeadlineExceeded ,
262249 core_exceptions .ServiceUnavailable ,
263250 ),
264- deadline = 15 .0 ,
251+ deadline = 30 .0 ,
265252 ),
266- default_timeout = 15 .0 ,
253+ default_timeout = 30 .0 ,
267254 client_info = client_info ,
268255 ),
269256 self .search_all_iam_policies : gapic_v1 .method .wrap_method (
@@ -273,12 +260,11 @@ def _prep_wrapped_messages(self, client_info):
273260 maximum = 60.0 ,
274261 multiplier = 1.3 ,
275262 predicate = retries .if_exception_type (
276- core_exceptions .DeadlineExceeded ,
277263 core_exceptions .ServiceUnavailable ,
278264 ),
279- deadline = 15 .0 ,
265+ deadline = 30 .0 ,
280266 ),
281- default_timeout = 15 .0 ,
267+ default_timeout = 30 .0 ,
282268 client_info = client_info ,
283269 ),
284270 self .analyze_iam_policy : gapic_v1 .method .wrap_method (
0 commit comments