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

Commit 3f9bfc2

Browse files
fix: use correct retry deadline (#7)
1 parent 640e883 commit 3f9bfc2

File tree

18 files changed

+503
-306
lines changed

18 files changed

+503
-306
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ repos:
1212
hooks:
1313
- id: black
1414
- repo: https://gitlab.com/pycqa/flake8
15-
rev: 3.8.4
15+
rev: 3.9.0
1616
hooks:
1717
- id: flake8

google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,36 @@ class BinauthzManagementServiceV1Beta1AsyncClient:
104104
BinauthzManagementServiceV1Beta1Client.parse_common_location_path
105105
)
106106

107-
from_service_account_info = (
108-
BinauthzManagementServiceV1Beta1Client.from_service_account_info
109-
)
110-
from_service_account_file = (
111-
BinauthzManagementServiceV1Beta1Client.from_service_account_file
112-
)
107+
@classmethod
108+
def from_service_account_info(cls, info: dict, *args, **kwargs):
109+
"""Creates an instance of this client using the provided credentials info.
110+
111+
Args:
112+
info (dict): The service account private key info.
113+
args: Additional arguments to pass to the constructor.
114+
kwargs: Additional arguments to pass to the constructor.
115+
116+
Returns:
117+
BinauthzManagementServiceV1Beta1AsyncClient: The constructed client.
118+
"""
119+
return BinauthzManagementServiceV1Beta1Client.from_service_account_info.__func__(BinauthzManagementServiceV1Beta1AsyncClient, info, *args, **kwargs) # type: ignore
120+
121+
@classmethod
122+
def from_service_account_file(cls, filename: str, *args, **kwargs):
123+
"""Creates an instance of this client using the provided credentials
124+
file.
125+
126+
Args:
127+
filename (str): The path to the service account private key json
128+
file.
129+
args: Additional arguments to pass to the constructor.
130+
kwargs: Additional arguments to pass to the constructor.
131+
132+
Returns:
133+
BinauthzManagementServiceV1Beta1AsyncClient: The constructed client.
134+
"""
135+
return BinauthzManagementServiceV1Beta1Client.from_service_account_file.__func__(BinauthzManagementServiceV1Beta1AsyncClient, filename, *args, **kwargs) # type: ignore
136+
113137
from_service_account_json = from_service_account_file
114138

115139
@property
@@ -220,9 +244,8 @@ async def get_policy(
220244
221245
Returns:
222246
google.cloud.binaryauthorization_v1beta1.types.Policy:
223-
A
224-
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
225-
for container image binary authorization.
247+
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
248+
image binary authorization.
226249
227250
"""
228251
# Create or coerce a protobuf request object.
@@ -254,6 +277,7 @@ async def get_policy(
254277
predicate=retries.if_exception_type(
255278
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
256279
),
280+
deadline=600.0,
257281
),
258282
default_timeout=600.0,
259283
client_info=DEFAULT_CLIENT_INFO,
@@ -313,9 +337,8 @@ async def update_policy(
313337
314338
Returns:
315339
google.cloud.binaryauthorization_v1beta1.types.Policy:
316-
A
317-
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
318-
for container image binary authorization.
340+
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
341+
image binary authorization.
319342
320343
"""
321344
# Create or coerce a protobuf request object.
@@ -347,6 +370,7 @@ async def update_policy(
347370
predicate=retries.if_exception_type(
348371
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
349372
),
373+
deadline=600.0,
350374
),
351375
default_timeout=600.0,
352376
client_info=DEFAULT_CLIENT_INFO,
@@ -426,9 +450,9 @@ async def create_attestor(
426450
427451
Returns:
428452
google.cloud.binaryauthorization_v1beta1.types.Attestor:
429-
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
430-
artifacts. An existing attestor cannot be modified
431-
except where indicated.
453+
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
454+
to container image artifacts. An existing attestor
455+
cannot be modified except where indicated.
432456
433457
"""
434458
# Create or coerce a protobuf request object.
@@ -509,9 +533,9 @@ async def get_attestor(
509533
510534
Returns:
511535
google.cloud.binaryauthorization_v1beta1.types.Attestor:
512-
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
513-
artifacts. An existing attestor cannot be modified
514-
except where indicated.
536+
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
537+
to container image artifacts. An existing attestor
538+
cannot be modified except where indicated.
515539
516540
"""
517541
# Create or coerce a protobuf request object.
@@ -543,6 +567,7 @@ async def get_attestor(
543567
predicate=retries.if_exception_type(
544568
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
545569
),
570+
deadline=600.0,
546571
),
547572
default_timeout=600.0,
548573
client_info=DEFAULT_CLIENT_INFO,
@@ -599,9 +624,9 @@ async def update_attestor(
599624
600625
Returns:
601626
google.cloud.binaryauthorization_v1beta1.types.Attestor:
602-
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
603-
artifacts. An existing attestor cannot be modified
604-
except where indicated.
627+
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
628+
to container image artifacts. An existing attestor
629+
cannot be modified except where indicated.
605630
606631
"""
607632
# Create or coerce a protobuf request object.
@@ -633,6 +658,7 @@ async def update_attestor(
633658
predicate=retries.if_exception_type(
634659
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
635660
),
661+
deadline=600.0,
636662
),
637663
default_timeout=600.0,
638664
client_info=DEFAULT_CLIENT_INFO,
@@ -723,6 +749,7 @@ async def list_attestors(
723749
predicate=retries.if_exception_type(
724750
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
725751
),
752+
deadline=600.0,
726753
),
727754
default_timeout=600.0,
728755
client_info=DEFAULT_CLIENT_INFO,
@@ -809,6 +836,7 @@ async def delete_attestor(
809836
predicate=retries.if_exception_type(
810837
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
811838
),
839+
deadline=600.0,
812840
),
813841
default_timeout=600.0,
814842
client_info=DEFAULT_CLIENT_INFO,

google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,17 @@ def __init__(
315315
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
316316
)
317317

318-
ssl_credentials = None
318+
client_cert_source_func = None
319319
is_mtls = False
320320
if use_client_cert:
321321
if client_options.client_cert_source:
322-
import grpc # type: ignore
323-
324-
cert, key = client_options.client_cert_source()
325-
ssl_credentials = grpc.ssl_channel_credentials(
326-
certificate_chain=cert, private_key=key
327-
)
328322
is_mtls = True
323+
client_cert_source_func = client_options.client_cert_source
329324
else:
330-
creds = SslCredentials()
331-
is_mtls = creds.is_mtls
332-
ssl_credentials = creds.ssl_credentials if is_mtls else None
325+
is_mtls = mtls.has_default_client_cert_source()
326+
client_cert_source_func = (
327+
mtls.default_client_cert_source() if is_mtls else None
328+
)
333329

334330
# Figure out which api endpoint to use.
335331
if client_options.api_endpoint is not None:
@@ -372,7 +368,7 @@ def __init__(
372368
credentials_file=client_options.credentials_file,
373369
host=api_endpoint,
374370
scopes=client_options.scopes,
375-
ssl_channel_credentials=ssl_credentials,
371+
client_cert_source_for_mtls=client_cert_source_func,
376372
quota_project_id=client_options.quota_project_id,
377373
client_info=client_info,
378374
)
@@ -421,9 +417,8 @@ def get_policy(
421417
422418
Returns:
423419
google.cloud.binaryauthorization_v1beta1.types.Policy:
424-
A
425-
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
426-
for container image binary authorization.
420+
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
421+
image binary authorization.
427422
428423
"""
429424
# Create or coerce a protobuf request object.
@@ -507,9 +502,8 @@ def update_policy(
507502
508503
Returns:
509504
google.cloud.binaryauthorization_v1beta1.types.Policy:
510-
A
511-
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
512-
for container image binary authorization.
505+
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
506+
image binary authorization.
513507
514508
"""
515509
# Create or coerce a protobuf request object.
@@ -613,9 +607,9 @@ def create_attestor(
613607
614608
Returns:
615609
google.cloud.binaryauthorization_v1beta1.types.Attestor:
616-
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
617-
artifacts. An existing attestor cannot be modified
618-
except where indicated.
610+
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
611+
to container image artifacts. An existing attestor
612+
cannot be modified except where indicated.
619613
620614
"""
621615
# Create or coerce a protobuf request object.
@@ -697,9 +691,9 @@ def get_attestor(
697691
698692
Returns:
699693
google.cloud.binaryauthorization_v1beta1.types.Attestor:
700-
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
701-
artifacts. An existing attestor cannot be modified
702-
except where indicated.
694+
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
695+
to container image artifacts. An existing attestor
696+
cannot be modified except where indicated.
703697
704698
"""
705699
# Create or coerce a protobuf request object.
@@ -780,9 +774,9 @@ def update_attestor(
780774
781775
Returns:
782776
google.cloud.binaryauthorization_v1beta1.types.Attestor:
783-
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
784-
artifacts. An existing attestor cannot be modified
785-
except where indicated.
777+
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
778+
to container image artifacts. An existing attestor
779+
cannot be modified except where indicated.
786780
787781
"""
788782
# Create or coerce a protobuf request object.

google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
# limitations under the License.
1616
#
1717

18-
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple
18+
from typing import (
19+
Any,
20+
AsyncIterable,
21+
Awaitable,
22+
Callable,
23+
Iterable,
24+
Sequence,
25+
Tuple,
26+
Optional,
27+
)
1928

2029
from google.cloud.binaryauthorization_v1beta1.types import resources
2130
from google.cloud.binaryauthorization_v1beta1.types import service

google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py

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

85+
# Save the scopes.
86+
self._scopes = scopes or self.AUTH_SCOPES
87+
8588
# If no credentials are provided, then determine the appropriate
8689
# defaults.
8790
if credentials and credentials_file:
@@ -91,20 +94,17 @@ def __init__(
9194

9295
if credentials_file is not None:
9396
credentials, _ = auth.load_credentials_from_file(
94-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
97+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
9598
)
9699

97100
elif credentials is None:
98101
credentials, _ = auth.default(
99-
scopes=scopes, quota_project_id=quota_project_id
102+
scopes=self._scopes, quota_project_id=quota_project_id
100103
)
101104

102105
# Save the credentials.
103106
self._credentials = credentials
104107

105-
# Lifted into its own function so it can be stubbed out during tests.
106-
self._prep_wrapped_messages(client_info)
107-
108108
def _prep_wrapped_messages(self, client_info):
109109
# Precompute the wrapped methods.
110110
self._wrapped_methods = {
@@ -117,6 +117,7 @@ def _prep_wrapped_messages(self, client_info):
117117
predicate=retries.if_exception_type(
118118
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
119119
),
120+
deadline=600.0,
120121
),
121122
default_timeout=600.0,
122123
client_info=client_info,
@@ -130,6 +131,7 @@ def _prep_wrapped_messages(self, client_info):
130131
predicate=retries.if_exception_type(
131132
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
132133
),
134+
deadline=600.0,
133135
),
134136
default_timeout=600.0,
135137
client_info=client_info,
@@ -146,6 +148,7 @@ def _prep_wrapped_messages(self, client_info):
146148
predicate=retries.if_exception_type(
147149
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
148150
),
151+
deadline=600.0,
149152
),
150153
default_timeout=600.0,
151154
client_info=client_info,
@@ -159,6 +162,7 @@ def _prep_wrapped_messages(self, client_info):
159162
predicate=retries.if_exception_type(
160163
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
161164
),
165+
deadline=600.0,
162166
),
163167
default_timeout=600.0,
164168
client_info=client_info,
@@ -172,6 +176,7 @@ def _prep_wrapped_messages(self, client_info):
172176
predicate=retries.if_exception_type(
173177
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
174178
),
179+
deadline=600.0,
175180
),
176181
default_timeout=600.0,
177182
client_info=client_info,
@@ -185,6 +190,7 @@ def _prep_wrapped_messages(self, client_info):
185190
predicate=retries.if_exception_type(
186191
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
187192
),
193+
deadline=600.0,
188194
),
189195
default_timeout=600.0,
190196
client_info=client_info,

0 commit comments

Comments
 (0)