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 .spanner_admin_database_v1 .types import backup
3031from google .cloud .spanner_admin_database_v1 .types import backup as gsad_backup
5253 except pkg_resources .DistributionNotFound : # pragma: NO COVER
5354 _GOOGLE_AUTH_VERSION = None
5455
55- _API_CORE_VERSION = google .api_core .__version__
56-
5756
5857class DatabaseAdminTransport (abc .ABC ):
5958 """Abstract transport class for DatabaseAdmin."""
@@ -74,6 +73,7 @@ def __init__(
7473 scopes : Optional [Sequence [str ]] = None ,
7574 quota_project_id : Optional [str ] = None ,
7675 client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
76+ always_use_jwt_access : Optional [bool ] = False ,
7777 ** kwargs ,
7878 ) -> None :
7979 """Instantiate the transport.
@@ -97,6 +97,8 @@ def __init__(
9797 API requests. If ``None``, then default info will be used.
9898 Generally, you only need to set this if you're developing
9999 your own client library.
100+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
101+ be used for service account credentials.
100102 """
101103 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
102104 if ":" not in host :
@@ -125,13 +127,20 @@ def __init__(
125127 ** scopes_kwargs , quota_project_id = quota_project_id
126128 )
127129
130+ # If the credentials is service account credentials, then always try to use self signed JWT.
131+ if (
132+ always_use_jwt_access
133+ and isinstance (credentials , service_account .Credentials )
134+ and hasattr (service_account .Credentials , "with_always_use_jwt_access" )
135+ ):
136+ credentials = credentials .with_always_use_jwt_access (True )
137+
128138 # Save the credentials.
129139 self ._credentials = credentials
130140
131- # TODO(busunkim): These two class methods are in the base transport
141+ # TODO(busunkim): This method is in the base transport
132142 # to avoid duplicating code across the transport classes. These functions
133- # should be deleted once the minimum required versions of google-api-core
134- # and google-auth are increased.
143+ # should be deleted once the minimum required versions of google-auth is increased.
135144
136145 # TODO: Remove this function once google-auth >= 1.25.0 is required
137146 @classmethod
@@ -152,27 +161,6 @@ def _get_scopes_kwargs(
152161
153162 return scopes_kwargs
154163
155- # TODO: Remove this function once google-api-core >= 1.26.0 is required
156- @classmethod
157- def _get_self_signed_jwt_kwargs (
158- cls , host : str , scopes : Optional [Sequence [str ]]
159- ) -> Dict [str , Union [Optional [Sequence [str ]], str ]]:
160- """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
161-
162- self_signed_jwt_kwargs : Dict [str , Union [Optional [Sequence [str ]], str ]] = {}
163-
164- if _API_CORE_VERSION and (
165- packaging .version .parse (_API_CORE_VERSION )
166- >= packaging .version .parse ("1.26.0" )
167- ):
168- self_signed_jwt_kwargs ["default_scopes" ] = cls .AUTH_SCOPES
169- self_signed_jwt_kwargs ["scopes" ] = scopes
170- self_signed_jwt_kwargs ["default_host" ] = cls .DEFAULT_HOST
171- else :
172- self_signed_jwt_kwargs ["scopes" ] = scopes or cls .AUTH_SCOPES
173-
174- return self_signed_jwt_kwargs
175-
176164 def _prep_wrapped_messages (self , client_info ):
177165 # Precompute the wrapped methods.
178166 self ._wrapped_methods = {
0 commit comments