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