2424from google .api_core import gapic_v1 # type: ignore
2525from google .api_core import retry as retries # type: ignore
2626from google .auth import credentials as ga_credentials # type: ignore
27+ from google .oauth2 import service_account # type: ignore
2728
2829from google .cloud .monitoring_v3 .types import alert
2930from google .cloud .monitoring_v3 .types import alert_service
4748 except pkg_resources .DistributionNotFound : # pragma: NO COVER
4849 _GOOGLE_AUTH_VERSION = None
4950
50- _API_CORE_VERSION = google .api_core .__version__
51-
5251
5352class AlertPolicyServiceTransport (abc .ABC ):
5453 """Abstract transport class for AlertPolicyService."""
@@ -70,6 +69,7 @@ def __init__(
7069 scopes : Optional [Sequence [str ]] = None ,
7170 quota_project_id : Optional [str ] = None ,
7271 client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
72+ always_use_jwt_access : Optional [bool ] = False ,
7373 ** kwargs ,
7474 ) -> None :
7575 """Instantiate the transport.
@@ -93,6 +93,8 @@ def __init__(
9393 API requests. If ``None``, then default info will be used.
9494 Generally, you only need to set this if you're developing
9595 your own client library.
96+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
97+ be used for service account credentials.
9698 """
9799 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
98100 if ":" not in host :
@@ -121,13 +123,20 @@ def __init__(
121123 ** scopes_kwargs , quota_project_id = quota_project_id
122124 )
123125
126+ # If the credentials is service account credentials, then always try to use self signed JWT.
127+ if (
128+ always_use_jwt_access
129+ and isinstance (credentials , service_account .Credentials )
130+ and hasattr (service_account .Credentials , "with_always_use_jwt_access" )
131+ ):
132+ credentials = credentials .with_always_use_jwt_access (True )
133+
124134 # Save the credentials.
125135 self ._credentials = credentials
126136
127- # TODO(busunkim): These two class methods are in the base transport
137+ # TODO(busunkim): This method is in the base transport
128138 # to avoid duplicating code across the transport classes. These functions
129- # should be deleted once the minimum required versions of google-api-core
130- # and google-auth are increased.
139+ # should be deleted once the minimum required versions of google-auth is increased.
131140
132141 # TODO: Remove this function once google-auth >= 1.25.0 is required
133142 @classmethod
@@ -148,27 +157,6 @@ def _get_scopes_kwargs(
148157
149158 return scopes_kwargs
150159
151- # TODO: Remove this function once google-api-core >= 1.26.0 is required
152- @classmethod
153- def _get_self_signed_jwt_kwargs (
154- cls , host : str , scopes : Optional [Sequence [str ]]
155- ) -> Dict [str , Union [Optional [Sequence [str ]], str ]]:
156- """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
157-
158- self_signed_jwt_kwargs : Dict [str , Union [Optional [Sequence [str ]], str ]] = {}
159-
160- if _API_CORE_VERSION and (
161- packaging .version .parse (_API_CORE_VERSION )
162- >= packaging .version .parse ("1.26.0" )
163- ):
164- self_signed_jwt_kwargs ["default_scopes" ] = cls .AUTH_SCOPES
165- self_signed_jwt_kwargs ["scopes" ] = scopes
166- self_signed_jwt_kwargs ["default_host" ] = cls .DEFAULT_HOST
167- else :
168- self_signed_jwt_kwargs ["scopes" ] = scopes or cls .AUTH_SCOPES
169-
170- return self_signed_jwt_kwargs
171-
172160 def _prep_wrapped_messages (self , client_info ):
173161 # Precompute the wrapped methods.
174162 self ._wrapped_methods = {
0 commit comments