24
24
from google .api_core import gapic_v1 # type: ignore
25
25
from google .api_core import retry as retries # type: ignore
26
26
from google .auth import credentials as ga_credentials # type: ignore
27
+ from google .oauth2 import service_account # type: ignore
27
28
28
29
from google .cloud .logging_v2 .types import logging_metrics
29
30
from google .protobuf import empty_pb2 # type: ignore
44
45
except pkg_resources .DistributionNotFound : # pragma: NO COVER
45
46
_GOOGLE_AUTH_VERSION = None
46
47
47
- _API_CORE_VERSION = google .api_core .__version__
48
-
49
48
50
49
class MetricsServiceV2Transport (abc .ABC ):
51
50
"""Abstract transport class for MetricsServiceV2."""
@@ -69,6 +68,7 @@ def __init__(
69
68
scopes : Optional [Sequence [str ]] = None ,
70
69
quota_project_id : Optional [str ] = None ,
71
70
client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
71
+ always_use_jwt_access : Optional [bool ] = False ,
72
72
** kwargs ,
73
73
) -> None :
74
74
"""Instantiate the transport.
@@ -92,6 +92,8 @@ def __init__(
92
92
API requests. If ``None``, then default info will be used.
93
93
Generally, you only need to set this if you're developing
94
94
your own client library.
95
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
96
+ be used for service account credentials.
95
97
"""
96
98
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
97
99
if ":" not in host :
@@ -120,13 +122,20 @@ def __init__(
120
122
** scopes_kwargs , quota_project_id = quota_project_id
121
123
)
122
124
125
+ # If the credentials is service account credentials, then always try to use self signed JWT.
126
+ if (
127
+ always_use_jwt_access
128
+ and isinstance (credentials , service_account .Credentials )
129
+ and hasattr (service_account .Credentials , "with_always_use_jwt_access" )
130
+ ):
131
+ credentials = credentials .with_always_use_jwt_access (True )
132
+
123
133
# Save the credentials.
124
134
self ._credentials = credentials
125
135
126
- # TODO(busunkim): These two class methods are in the base transport
136
+ # TODO(busunkim): This method is in the base transport
127
137
# to avoid duplicating code across the transport classes. These functions
128
- # should be deleted once the minimum required versions of google-api-core
129
- # and google-auth are increased.
138
+ # should be deleted once the minimum required versions of google-auth is increased.
130
139
131
140
# TODO: Remove this function once google-auth >= 1.25.0 is required
132
141
@classmethod
@@ -147,27 +156,6 @@ def _get_scopes_kwargs(
147
156
148
157
return scopes_kwargs
149
158
150
- # TODO: Remove this function once google-api-core >= 1.26.0 is required
151
- @classmethod
152
- def _get_self_signed_jwt_kwargs (
153
- cls , host : str , scopes : Optional [Sequence [str ]]
154
- ) -> Dict [str , Union [Optional [Sequence [str ]], str ]]:
155
- """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
156
-
157
- self_signed_jwt_kwargs : Dict [str , Union [Optional [Sequence [str ]], str ]] = {}
158
-
159
- if _API_CORE_VERSION and (
160
- packaging .version .parse (_API_CORE_VERSION )
161
- >= packaging .version .parse ("1.26.0" )
162
- ):
163
- self_signed_jwt_kwargs ["default_scopes" ] = cls .AUTH_SCOPES
164
- self_signed_jwt_kwargs ["scopes" ] = scopes
165
- self_signed_jwt_kwargs ["default_host" ] = cls .DEFAULT_HOST
166
- else :
167
- self_signed_jwt_kwargs ["scopes" ] = scopes or cls .AUTH_SCOPES
168
-
169
- return self_signed_jwt_kwargs
170
-
171
159
def _prep_wrapped_messages (self , client_info ):
172
160
# Precompute the wrapped methods.
173
161
self ._wrapped_methods = {
0 commit comments