Skip to content
This repository was archived by the owner on Oct 16, 2023. It is now read-only.

Commit 1fbdece

Browse files
fix: use correct retry deadlines (#63)
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/f041d1b5-526a-41af-bdb4-4cc8c013c941/targets - [ ] To automatically regenerate this PR, check this box. (May take up to 24 hours.) PiperOrigin-RevId: 364411656 Source-Link: googleapis/googleapis@149a3a8 PiperOrigin-RevId: 361662015 Source-Link: googleapis/googleapis@28a5919 PiperOrigin-RevId: 359562873 Source-Link: googleapis/googleapis@07932bb PiperOrigin-RevId: 355923884 Source-Link: googleapis/googleapis@5e3dace PiperOrigin-RevId: 354996675 Source-Link: googleapis/googleapis@20712b8
1 parent f6e099a commit 1fbdece

9 files changed

Lines changed: 368 additions & 251 deletions

File tree

‎google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,36 @@ class IAMCredentialsAsyncClient:
8989
IAMCredentialsClient.parse_common_location_path
9090
)
9191

92-
from_service_account_info = IAMCredentialsClient.from_service_account_info
93-
from_service_account_file = IAMCredentialsClient.from_service_account_file
92+
@classmethod
93+
def from_service_account_info(cls, info: dict, *args, **kwargs):
94+
"""Creates an instance of this client using the provided credentials info.
95+
96+
Args:
97+
info (dict): The service account private key info.
98+
args: Additional arguments to pass to the constructor.
99+
kwargs: Additional arguments to pass to the constructor.
100+
101+
Returns:
102+
IAMCredentialsAsyncClient: The constructed client.
103+
"""
104+
return IAMCredentialsClient.from_service_account_info.__func__(IAMCredentialsAsyncClient, info, *args, **kwargs) # type: ignore
105+
106+
@classmethod
107+
def from_service_account_file(cls, filename: str, *args, **kwargs):
108+
"""Creates an instance of this client using the provided credentials
109+
file.
110+
111+
Args:
112+
filename (str): The path to the service account private key json
113+
file.
114+
args: Additional arguments to pass to the constructor.
115+
kwargs: Additional arguments to pass to the constructor.
116+
117+
Returns:
118+
IAMCredentialsAsyncClient: The constructed client.
119+
"""
120+
return IAMCredentialsClient.from_service_account_file.__func__(IAMCredentialsAsyncClient, filename, *args, **kwargs) # type: ignore
121+
94122
from_service_account_json = from_service_account_file
95123

96124
@property
@@ -270,6 +298,7 @@ async def generate_access_token(
270298
predicate=retries.if_exception_type(
271299
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
272300
),
301+
deadline=60.0,
273302
),
274303
default_timeout=60.0,
275304
client_info=DEFAULT_CLIENT_INFO,
@@ -397,6 +426,7 @@ async def generate_id_token(
397426
predicate=retries.if_exception_type(
398427
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
399428
),
429+
deadline=60.0,
400430
),
401431
default_timeout=60.0,
402432
client_info=DEFAULT_CLIENT_INFO,
@@ -510,6 +540,7 @@ async def sign_blob(
510540
predicate=retries.if_exception_type(
511541
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
512542
),
543+
deadline=60.0,
513544
),
514545
default_timeout=60.0,
515546
client_info=DEFAULT_CLIENT_INFO,
@@ -626,6 +657,7 @@ async def sign_jwt(
626657
predicate=retries.if_exception_type(
627658
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
628659
),
660+
deadline=60.0,
629661
),
630662
default_timeout=60.0,
631663
client_info=DEFAULT_CLIENT_INFO,

‎google/cloud/iam_credentials_v1/services/iam_credentials/client.py‎

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -296,21 +296,17 @@ def __init__(
296296
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
297297
)
298298

299-
ssl_credentials = None
299+
client_cert_source_func = None
300300
is_mtls = False
301301
if use_client_cert:
302302
if client_options.client_cert_source:
303-
import grpc # type: ignore
304-
305-
cert, key = client_options.client_cert_source()
306-
ssl_credentials = grpc.ssl_channel_credentials(
307-
certificate_chain=cert, private_key=key
308-
)
309303
is_mtls = True
304+
client_cert_source_func = client_options.client_cert_source
310305
else:
311-
creds = SslCredentials()
312-
is_mtls = creds.is_mtls
313-
ssl_credentials = creds.ssl_credentials if is_mtls else None
306+
is_mtls = mtls.has_default_client_cert_source()
307+
client_cert_source_func = (
308+
mtls.default_client_cert_source() if is_mtls else None
309+
)
314310

315311
# Figure out which api endpoint to use.
316312
if client_options.api_endpoint is not None:
@@ -353,7 +349,7 @@ def __init__(
353349
credentials_file=client_options.credentials_file,
354350
host=api_endpoint,
355351
scopes=client_options.scopes,
356-
ssl_channel_credentials=ssl_credentials,
352+
client_cert_source_for_mtls=client_cert_source_func,
357353
quota_project_id=client_options.quota_project_id,
358354
client_info=client_info,
359355
)
@@ -460,14 +456,13 @@ def generate_access_token(
460456

461457
if name is not None:
462458
request.name = name
459+
if delegates is not None:
460+
request.delegates = delegates
461+
if scope is not None:
462+
request.scope = scope
463463
if lifetime is not None:
464464
request.lifetime = lifetime
465465

466-
if delegates:
467-
request.delegates.extend(delegates)
468-
if scope:
469-
request.scope.extend(scope)
470-
471466
# Wrap the RPC method; this adds retry and timeout information,
472467
# and friendly error handling.
473468
rpc = self._transport._wrapped_methods[self._transport.generate_access_token]
@@ -580,14 +575,13 @@ def generate_id_token(
580575

581576
if name is not None:
582577
request.name = name
578+
if delegates is not None:
579+
request.delegates = delegates
583580
if audience is not None:
584581
request.audience = audience
585582
if include_email is not None:
586583
request.include_email = include_email
587584

588-
if delegates:
589-
request.delegates.extend(delegates)
590-
591585
# Wrap the RPC method; this adds retry and timeout information,
592586
# and friendly error handling.
593587
rpc = self._transport._wrapped_methods[self._transport.generate_id_token]
@@ -688,12 +682,11 @@ def sign_blob(
688682

689683
if name is not None:
690684
request.name = name
685+
if delegates is not None:
686+
request.delegates = delegates
691687
if payload is not None:
692688
request.payload = payload
693689

694-
if delegates:
695-
request.delegates.extend(delegates)
696-
697690
# Wrap the RPC method; this adds retry and timeout information,
698691
# and friendly error handling.
699692
rpc = self._transport._wrapped_methods[self._transport.sign_blob]
@@ -797,12 +790,11 @@ def sign_jwt(
797790

798791
if name is not None:
799792
request.name = name
793+
if delegates is not None:
794+
request.delegates = delegates
800795
if payload is not None:
801796
request.payload = payload
802797

803-
if delegates:
804-
request.delegates.extend(delegates)
805-
806798
# Wrap the RPC method; this adds retry and timeout information,
807799
# and friendly error handling.
808800
rpc = self._transport._wrapped_methods[self._transport.sign_jwt]

‎google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,20 @@ def __init__(
6767
scope (Optional[Sequence[str]]): A list of scopes.
6868
quota_project_id (Optional[str]): An optional project to use for billing
6969
and quota.
70-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
71-
The client info used to send a user-agent string along with
72-
API requests. If ``None``, then default info will be used.
73-
Generally, you only need to set this if you're developing
70+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
71+
The client info used to send a user-agent string along with
72+
API requests. If ``None``, then default info will be used.
73+
Generally, you only need to set this if you're developing
7474
your own client library.
7575
"""
7676
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
7777
if ":" not in host:
7878
host += ":443"
7979
self._host = host
8080

81+
# Save the scopes.
82+
self._scopes = scopes or self.AUTH_SCOPES
83+
8184
# If no credentials are provided, then determine the appropriate
8285
# defaults.
8386
if credentials and credentials_file:
@@ -87,20 +90,17 @@ def __init__(
8790

8891
if credentials_file is not None:
8992
credentials, _ = auth.load_credentials_from_file(
90-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
93+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
9194
)
9295

9396
elif credentials is None:
9497
credentials, _ = auth.default(
95-
scopes=scopes, quota_project_id=quota_project_id
98+
scopes=self._scopes, quota_project_id=quota_project_id
9699
)
97100

98101
# Save the credentials.
99102
self._credentials = credentials
100103

101-
# Lifted into its own function so it can be stubbed out during tests.
102-
self._prep_wrapped_messages(client_info)
103-
104104
def _prep_wrapped_messages(self, client_info):
105105
# Precompute the wrapped methods.
106106
self._wrapped_methods = {
@@ -113,6 +113,7 @@ def _prep_wrapped_messages(self, client_info):
113113
predicate=retries.if_exception_type(
114114
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
115115
),
116+
deadline=60.0,
116117
),
117118
default_timeout=60.0,
118119
client_info=client_info,
@@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info):
126127
predicate=retries.if_exception_type(
127128
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
128129
),
130+
deadline=60.0,
129131
),
130132
default_timeout=60.0,
131133
client_info=client_info,
@@ -139,6 +141,7 @@ def _prep_wrapped_messages(self, client_info):
139141
predicate=retries.if_exception_type(
140142
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
141143
),
144+
deadline=60.0,
142145
),
143146
default_timeout=60.0,
144147
client_info=client_info,
@@ -152,6 +155,7 @@ def _prep_wrapped_messages(self, client_info):
152155
predicate=retries.if_exception_type(
153156
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
154157
),
158+
deadline=60.0,
155159
),
156160
default_timeout=60.0,
157161
client_info=client_info,

0 commit comments

Comments
 (0)