Skip to content

Commit

Permalink
fix: use correct retry deadline (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Apr 1, 2021
1 parent a267b22 commit 85d185c
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ repos:
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.0
hooks:
- id: flake8
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,36 @@ class BinauthzManagementServiceV1Beta1AsyncClient:
BinauthzManagementServiceV1Beta1Client.parse_common_location_path
)

from_service_account_info = (
BinauthzManagementServiceV1Beta1Client.from_service_account_info
)
from_service_account_file = (
BinauthzManagementServiceV1Beta1Client.from_service_account_file
)
@classmethod
def from_service_account_info(cls, info: dict, *args, **kwargs):
"""Creates an instance of this client using the provided credentials info.
Args:
info (dict): The service account private key info.
args: Additional arguments to pass to the constructor.
kwargs: Additional arguments to pass to the constructor.
Returns:
BinauthzManagementServiceV1Beta1AsyncClient: The constructed client.
"""
return BinauthzManagementServiceV1Beta1Client.from_service_account_info.__func__(BinauthzManagementServiceV1Beta1AsyncClient, info, *args, **kwargs) # type: ignore

@classmethod
def from_service_account_file(cls, filename: str, *args, **kwargs):
"""Creates an instance of this client using the provided credentials
file.
Args:
filename (str): The path to the service account private key json
file.
args: Additional arguments to pass to the constructor.
kwargs: Additional arguments to pass to the constructor.
Returns:
BinauthzManagementServiceV1Beta1AsyncClient: The constructed client.
"""
return BinauthzManagementServiceV1Beta1Client.from_service_account_file.__func__(BinauthzManagementServiceV1Beta1AsyncClient, filename, *args, **kwargs) # type: ignore

from_service_account_json = from_service_account_file

@property
Expand Down Expand Up @@ -220,9 +244,8 @@ async def get_policy(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Policy:
A
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
for container image binary authorization.
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
image binary authorization.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -254,6 +277,7 @@ async def get_policy(
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -313,9 +337,8 @@ async def update_policy(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Policy:
A
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
for container image binary authorization.
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
image binary authorization.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -347,6 +370,7 @@ async def update_policy(
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -426,9 +450,9 @@ async def create_attestor(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Attestor:
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
artifacts. An existing attestor cannot be modified
except where indicated.
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
to container image artifacts. An existing attestor
cannot be modified except where indicated.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -509,9 +533,9 @@ async def get_attestor(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Attestor:
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
artifacts. An existing attestor cannot be modified
except where indicated.
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
to container image artifacts. An existing attestor
cannot be modified except where indicated.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -543,6 +567,7 @@ async def get_attestor(
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -599,9 +624,9 @@ async def update_attestor(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Attestor:
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
artifacts. An existing attestor cannot be modified
except where indicated.
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
to container image artifacts. An existing attestor
cannot be modified except where indicated.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -633,6 +658,7 @@ async def update_attestor(
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -723,6 +749,7 @@ async def list_attestors(
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -809,6 +836,7 @@ async def delete_attestor(
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,17 @@ def __init__(
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
)

ssl_credentials = None
client_cert_source_func = None
is_mtls = False
if use_client_cert:
if client_options.client_cert_source:
import grpc # type: ignore

cert, key = client_options.client_cert_source()
ssl_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
is_mtls = True
client_cert_source_func = client_options.client_cert_source
else:
creds = SslCredentials()
is_mtls = creds.is_mtls
ssl_credentials = creds.ssl_credentials if is_mtls else None
is_mtls = mtls.has_default_client_cert_source()
client_cert_source_func = (
mtls.default_client_cert_source() if is_mtls else None
)

# Figure out which api endpoint to use.
if client_options.api_endpoint is not None:
Expand Down Expand Up @@ -372,7 +368,7 @@ def __init__(
credentials_file=client_options.credentials_file,
host=api_endpoint,
scopes=client_options.scopes,
ssl_channel_credentials=ssl_credentials,
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
)
Expand Down Expand Up @@ -421,9 +417,8 @@ def get_policy(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Policy:
A
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
for container image binary authorization.
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
image binary authorization.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -507,9 +502,8 @@ def update_policy(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Policy:
A
[policy][google.cloud.binaryauthorization.v1beta1.Policy]
for container image binary authorization.
A [policy][google.cloud.binaryauthorization.v1beta1.Policy] for container
image binary authorization.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -613,9 +607,9 @@ def create_attestor(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Attestor:
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
artifacts. An existing attestor cannot be modified
except where indicated.
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
to container image artifacts. An existing attestor
cannot be modified except where indicated.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -697,9 +691,9 @@ def get_attestor(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Attestor:
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
artifacts. An existing attestor cannot be modified
except where indicated.
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
to container image artifacts. An existing attestor
cannot be modified except where indicated.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -780,9 +774,9 @@ def update_attestor(
Returns:
google.cloud.binaryauthorization_v1beta1.types.Attestor:
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests to container image
artifacts. An existing attestor cannot be modified
except where indicated.
An [attestor][google.cloud.binaryauthorization.v1beta1.Attestor] that attests
to container image artifacts. An existing attestor
cannot be modified except where indicated.
"""
# Create or coerce a protobuf request object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
# limitations under the License.
#

from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple
from typing import (
Any,
AsyncIterable,
Awaitable,
Callable,
Iterable,
Sequence,
Tuple,
Optional,
)

from google.cloud.binaryauthorization_v1beta1.types import resources
from google.cloud.binaryauthorization_v1beta1.types import service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ def __init__(
scope (Optional[Sequence[str]]): A list of scopes.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
"""
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
if ":" not in host:
host += ":443"
self._host = host

# Save the scopes.
self._scopes = scopes or self.AUTH_SCOPES

# If no credentials are provided, then determine the appropriate
# defaults.
if credentials and credentials_file:
Expand All @@ -91,20 +94,17 @@ def __init__(

if credentials_file is not None:
credentials, _ = auth.load_credentials_from_file(
credentials_file, scopes=scopes, quota_project_id=quota_project_id
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
)

elif credentials is None:
credentials, _ = auth.default(
scopes=scopes, quota_project_id=quota_project_id
scopes=self._scopes, quota_project_id=quota_project_id
)

# Save the credentials.
self._credentials = credentials

# Lifted into its own function so it can be stubbed out during tests.
self._prep_wrapped_messages(client_info)

def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
self._wrapped_methods = {
Expand All @@ -117,6 +117,7 @@ def _prep_wrapped_messages(self, client_info):
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=client_info,
Expand All @@ -130,6 +131,7 @@ def _prep_wrapped_messages(self, client_info):
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=client_info,
Expand All @@ -146,6 +148,7 @@ def _prep_wrapped_messages(self, client_info):
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=client_info,
Expand All @@ -159,6 +162,7 @@ def _prep_wrapped_messages(self, client_info):
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=client_info,
Expand All @@ -172,6 +176,7 @@ def _prep_wrapped_messages(self, client_info):
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=client_info,
Expand All @@ -185,6 +190,7 @@ def _prep_wrapped_messages(self, client_info):
predicate=retries.if_exception_type(
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
),
deadline=600.0,
),
default_timeout=600.0,
client_info=client_info,
Expand Down
Loading

0 comments on commit 85d185c

Please sign in to comment.