def _retry_from_retry_config(retry_params, retry_codes): """Creates a Retry object given a gapic retry configuration. Args: retry_params (dict): The retry parameter values, for example:: { "initial_retry_delay_millis": 1000, "retry_delay_multiplier": 2.5, "max_retry_delay_millis": 120000, "initial_rpc_timeout_millis": 120000, "rpc_timeout_multiplier": 1.0, "max_rpc_timeout_millis": 120000, "total_timeout_millis": 600000 } retry_codes (sequence[str]): The list of retryable gRPC error code names. Returns: google.api_core.retry.Retry: The default retry object for the method. """ exception_classes = [ _exception_class_for_grpc_status_name(code) for code in retry_codes] return retry.Retry( retry.if_exception_type(*exception_classes), initial=( retry_params['initial_retry_delay_millis'] / _MILLIS_PER_SECOND), maximum=( retry_params['max_retry_delay_millis'] / _MILLIS_PER_SECOND), multiplier=retry_params['retry_delay_multiplier'], deadline=retry_params['total_timeout_millis'] / _MILLIS_PER_SECOND)
def test_retry_target_non_retryable_error(utcnow, sleep): predicate = retry.if_exception_type(ValueError) exception = TypeError() target = mock.Mock(side_effect=exception) with pytest.raises(TypeError) as exc_info: retry.retry_target(target, predicate, range(10), None) assert exc_info.value == exception sleep.assert_not_called()
def test_retry_target_success(utcnow, sleep): predicate = retry.if_exception_type(ValueError) call_count = [0] def target(): call_count[0] += 1 if call_count[0] < 3: raise ValueError() return 42 result = retry.retry_target(target, predicate, range(10), None) assert result == 42 assert call_count[0] == 3 sleep.assert_has_calls([mock.call(0), mock.call(1)])
def test_wrap_method_with_overriding_retry_and_timeout(unusued_sleep): method = mock.Mock(spec=["__call__"], side_effect=[exceptions.NotFound(None), 42]) default_retry = retry.Retry() default_timeout = timeout.ConstantTimeout(60) wrapped_method = google.api_core.gapic_v1.method.wrap_method( method, default_retry, default_timeout ) result = wrapped_method( retry=retry.Retry(retry.if_exception_type(exceptions.NotFound)), timeout=timeout.ConstantTimeout(22), ) assert result == 42 assert method.call_count == 2 method.assert_called_with(timeout=22, metadata=mock.ANY)
def test___call___and_execute_retry(self, sleep, uniform): on_error = mock.Mock(spec=["__call__"], side_effect=[None]) retry_ = retry.Retry(predicate=retry.if_exception_type(ValueError)) target = mock.Mock(spec=["__call__"], side_effect=[ValueError(), 42]) # __name__ is needed by functools.partial. target.__name__ = "target" decorated = retry_(target, on_error=on_error) target.assert_not_called() result = decorated("meep") assert result == 42 assert target.call_count == 2 target.assert_has_calls([mock.call("meep"), mock.call("meep")]) sleep.assert_called_once_with(retry_._initial) assert on_error.call_count == 1
def test_retry_target_deadline_exceeded(utcnow, sleep): predicate = retry.if_exception_type(ValueError) exception = ValueError('meep') target = mock.Mock(side_effect=exception) # Setup the timeline so that the first call takes 5 seconds but the second # call takes 6, which puts the retry over the deadline. utcnow.side_effect = [ # The first call to utcnow establishes the start of the timeline. datetime.datetime.min, datetime.datetime.min + datetime.timedelta(seconds=5), datetime.datetime.min + datetime.timedelta(seconds=11)] with pytest.raises(exceptions.RetryError) as exc_info: retry.retry_target(target, predicate, range(10), deadline=10) assert exc_info.value.cause == exception assert exc_info.match('Deadline of 10.0s exceeded') assert exc_info.match('last exception: meep') assert target.call_count == 2
def test_retry_target_w_on_error(utcnow, sleep): predicate = retry.if_exception_type(ValueError) call_count = {"target": 0} to_raise = ValueError() def target(): call_count["target"] += 1 if call_count["target"] < 3: raise to_raise return 42 on_error = mock.Mock() result = retry.retry_target(target, predicate, range(10), None, on_error=on_error) assert result == 42 assert call_count["target"] == 3 on_error.assert_has_calls([mock.call(to_raise), mock.call(to_raise)]) sleep.assert_has_calls([mock.call(0), mock.call(1)])
def _blocking_poll(self, timeout=None): """Poll and wait for the Future to be resolved. Args: timeout (int): How long (in seconds) to wait for the operation to complete. If None, wait indefinitely. """ if self._result_set: return retry_ = retry.Retry( predicate=retry.if_exception_type(_OperationNotComplete), deadline=timeout) try: retry_(self._done_or_raise)() except exceptions.RetryError: raise concurrent.futures.TimeoutError( 'Operation did not complete within the designated ' 'timeout.')
def test_if_exception_type_multiple(): predicate = retry.if_exception_type(ValueError, TypeError) assert predicate(ValueError()) assert predicate(TypeError()) assert not predicate(RuntimeError())
from google.api_core import exceptions from google.api_core import retry from google.api_core.future import _helpers from google.api_core.future import base class _OperationNotComplete(Exception): """Private exception used for polling via retry.""" pass RETRY_PREDICATE = retry.if_exception_type( _OperationNotComplete, exceptions.TooManyRequests, exceptions.InternalServerError, exceptions.BadGateway, ) DEFAULT_RETRY = retry.Retry(predicate=RETRY_PREDICATE) class PollingFuture(base.Future): """A Future that needs to poll some service to check its status. The :meth:`done` method should be implemented by subclasses. The polling behavior will repeatedly call ``done`` until it returns True. .. note: Privacy here is intended to prevent the final class from overexposing, not to prevent subclasses from accessing methods. Args:
async def search_uris(self, request: webrisk.SearchUrisRequest = None, *, uri: str = None, threat_types: Sequence[webrisk.ThreatType] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchUrisResponse: r"""This method is used to check whether a URI is on a given threatList. Multiple threatLists may be searched in a single query. The response will list all requested threatLists the URI was found to match. If the URI is not found on any of the requested ThreatList an empty response will be returned. Args: request (:class:`google.cloud.webrisk_v1.types.SearchUrisRequest`): The request object. Request to check URI entries against threatLists. uri (:class:`str`): Required. The URI to be checked for matches. This corresponds to the ``uri`` field on the ``request`` instance; if ``request`` is provided, this should not be set. threat_types (:class:`Sequence[google.cloud.webrisk_v1.types.ThreatType]`): Required. The ThreatLists to search in. Multiple ThreatLists may be specified. This corresponds to the ``threat_types`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.webrisk_v1.types.SearchUrisResponse: """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([uri, threat_types]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = webrisk.SearchUrisRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if uri is not None: request.uri = uri if threat_types: request.threat_types.extend(threat_types) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.search_uris, default_retry=retries.Retry( initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def batch_annotate_images( self, request: image_annotator.BatchAnnotateImagesRequest = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: r"""Run image detection and annotation for a batch of images. Args: request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): The request object. Multiple image annotation requests are batched into a single service call. requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.image_annotator.BatchAnnotateImagesResponse: Response to a batch image annotation request. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([requests]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = image_annotator.BatchAnnotateImagesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if requests: request.requests.extend(requests) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.batch_annotate_images, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def async_batch_annotate_files( self, request: image_annotator.AsyncBatchAnnotateFilesRequest = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Run asynchronous image detection and annotation for a list of generic files, such as PDF files, which may contain multiple pages and multiple images per page. Progress and results can be retrieved through the ``google.longrunning.Operations`` interface. ``Operation.metadata`` contains ``OperationMetadata`` (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). Args: request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): The request object. Multiple async file annotation requests are batched into a single service call. requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): Required. Individual async file annotation requests for this batch. This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: Response to an async batch file annotation request. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([requests]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = image_annotator.AsyncBatchAnnotateFilesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if requests: request.requests.extend(requests) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.async_batch_annotate_files, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Wrap the response in an operation future. response = operation_async.from_gapic( response, self._client._transport.operations_client, image_annotator.AsyncBatchAnnotateFilesResponse, metadata_type=image_annotator.OperationMetadata, ) # Done; return the response. return response
async def annotate_video( self, request: video_intelligence.AnnotateVideoRequest = None, *, input_uri: str = None, features: Sequence[video_intelligence.Feature] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Performs asynchronous video annotation. Progress and results can be retrieved through the ``google.longrunning.Operations`` interface. ``Operation.metadata`` contains ``AnnotateVideoProgress`` (progress). ``Operation.response`` contains ``AnnotateVideoResponse`` (results). Args: request (:class:`google.cloud.videointelligence_v1p1beta1.types.AnnotateVideoRequest`): The request object. Video annotation request. input_uri (:class:`str`): Input video location. Currently, only `Google Cloud Storage <https://cloud.google.com/storage/>`__ URIs are supported, which must be specified in the following format: ``gs://bucket-id/object-id`` (other URI formats return [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see `Request URIs <https://cloud.google.com/storage/docs/request-endpoints>`__. A video URI may include wildcards in ``object-id``, and thus identify multiple videos. Supported wildcards: '*' to match 0 or more characters; '?' to match 1 character. If unset, the input video should be embedded in the request as ``input_content``. If set, ``input_content`` should be unset. This corresponds to the ``input_uri`` field on the ``request`` instance; if ``request`` is provided, this should not be set. features (:class:`Sequence[google.cloud.videointelligence_v1p1beta1.types.Feature]`): Required. Requested video annotation features. This corresponds to the ``features`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.videointelligence_v1p1beta1.types.AnnotateVideoResponse` Video annotation response. Included in the response field of the Operation returned by the GetOperation call of the google::longrunning::Operations service. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([input_uri, features]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = video_intelligence.AnnotateVideoRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if input_uri is not None: request.input_uri = input_uri if features: request.features.extend(features) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.annotate_video, default_retry=retries.Retry( initial=1.0, maximum=120.0, multiplier=2.5, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Wrap the response in an operation future. response = operation_async.from_gapic( response, self._client._transport.operations_client, video_intelligence.AnnotateVideoResponse, metadata_type=video_intelligence.AnnotateVideoProgress, ) # Done; return the response. return response
async def list_jobs( self, request: cloudscheduler.ListJobsRequest = None, *, parent: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListJobsAsyncPager: r"""Lists jobs. Args: request (:class:`~.cloudscheduler.ListJobsRequest`): The request object. Request message for listing jobs using [ListJobs][google.cloud.scheduler.v1beta1.CloudScheduler.ListJobs]. parent (:class:`str`): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.pagers.ListJobsAsyncPager: Response message for listing jobs using [ListJobs][google.cloud.scheduler.v1beta1.CloudScheduler.ListJobs]. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. if request is not None and any([parent]): raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = cloudscheduler.ListJobsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_jobs, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=600.0, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListJobsAsyncPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_index: gapic_v1.method.wrap_method( self.create_index, default_timeout=60.0, client_info=client_info, ), self.list_indexes: gapic_v1.method.wrap_method( self.list_indexes, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.InternalServerError, core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=client_info, ), self.get_index: gapic_v1.method.wrap_method( self.get_index, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.InternalServerError, core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=client_info, ), self.delete_index: gapic_v1.method.wrap_method( self.delete_index, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.InternalServerError, core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=client_info, ), self.get_field: gapic_v1.method.wrap_method( self.get_field, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.InternalServerError, core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=client_info, ), self.update_field: gapic_v1.method.wrap_method( self.update_field, default_timeout=60.0, client_info=client_info, ), self.list_fields: gapic_v1.method.wrap_method( self.list_fields, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.InternalServerError, core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=client_info, ), self.export_documents: gapic_v1.method.wrap_method( self.export_documents, default_timeout=60.0, client_info=client_info, ), self.import_documents: gapic_v1.method.wrap_method( self.import_documents, default_timeout=60.0, client_info=client_info, ), self.get_database: gapic_v1.method.wrap_method( self.get_database, default_timeout=None, client_info=client_info, ), self.list_databases: gapic_v1.method.wrap_method( self.list_databases, default_timeout=None, client_info=client_info, ), self.update_database: gapic_v1.method.wrap_method( self.update_database, default_timeout=None, client_info=client_info, ), }
async def list_policies( self, request: orgpolicy.ListPoliciesRequest = None, *, parent: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPoliciesAsyncPager: r"""Retrieves all of the ``Policies`` that exist on a particular resource. Args: request (:class:`google.cloud.orgpolicy_v2.types.ListPoliciesRequest`): The request object. The request sent to the [ListPolicies] [google.cloud.orgpolicy.v2.OrgPolicy.ListPolicies] method. parent (:class:`str`): Required. The target Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: - ``projects/{project_number}`` - ``projects/{project_id}`` - ``folders/{folder_id}`` - ``organizations/{organization_id}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.orgpolicy_v2.services.org_policy.pagers.ListPoliciesAsyncPager: The response returned from the [ListPolicies] [google.cloud.orgpolicy.v2.OrgPolicy.ListPolicies] method. It will be empty if no Policies are set on the resource. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = orgpolicy.ListPoliciesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_policies, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListPoliciesAsyncPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
def generate_access_token( self, request: common.GenerateAccessTokenRequest = None, *, name: str = None, delegates: Sequence[str] = None, scope: Sequence[str] = None, lifetime: duration.Duration = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> common.GenerateAccessTokenResponse: r"""Generates an OAuth 2.0 access token for a service account. Args: request (:class:`~.common.GenerateAccessTokenRequest`): The request object. name (:class:`str`): Required. The resource name of the service account for which the credentials are requested, in the following format: ``projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}``. The ``-`` wildcard character is required; replacing it with a project ID is invalid. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. delegates (:class:`Sequence[str]`): The sequence of service accounts in a delegation chain. Each service account must be granted the ``roles/iam.serviceAccountTokenCreator`` role on its next service account in the chain. The last service account in the chain must be granted the ``roles/iam.serviceAccountTokenCreator`` role on the service account that is specified in the ``name`` field of the request. The delegates must have the following format: ``projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}``. The ``-`` wildcard character is required; replacing it with a project ID is invalid. This corresponds to the ``delegates`` field on the ``request`` instance; if ``request`` is provided, this should not be set. scope (:class:`Sequence[str]`): Required. Code to identify the scopes to be included in the OAuth 2.0 access token. See https://developers.google.com/identity/protocols/googlescopes for more information. At least one value required. This corresponds to the ``scope`` field on the ``request`` instance; if ``request`` is provided, this should not be set. lifetime (:class:`~.duration.Duration`): The desired lifetime duration of the access token in seconds. Must be set to a value less than or equal to 3600 (1 hour). If a value is not specified, the token's lifetime will be set to a default value of one hour. This corresponds to the ``lifetime`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.common.GenerateAccessTokenResponse: """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. if request is not None and any([name, delegates, scope, lifetime]): raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) request = common.GenerateAccessTokenRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name if delegates is not None: request.delegates = delegates if scope is not None: request.scope = scope if lifetime is not None: request.lifetime = lifetime # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method.wrap_method( self._transport.generate_access_token, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response
def sign_jwt( self, request: common.SignJwtRequest = None, *, name: str = None, delegates: Sequence[str] = None, payload: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> common.SignJwtResponse: r"""Signs a JWT using a service account's system-managed private key. Args: request (:class:`~.common.SignJwtRequest`): The request object. name (:class:`str`): Required. The resource name of the service account for which the credentials are requested, in the following format: ``projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}``. The ``-`` wildcard character is required; replacing it with a project ID is invalid. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. delegates (:class:`Sequence[str]`): The sequence of service accounts in a delegation chain. Each service account must be granted the ``roles/iam.serviceAccountTokenCreator`` role on its next service account in the chain. The last service account in the chain must be granted the ``roles/iam.serviceAccountTokenCreator`` role on the service account that is specified in the ``name`` field of the request. The delegates must have the following format: ``projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}``. The ``-`` wildcard character is required; replacing it with a project ID is invalid. This corresponds to the ``delegates`` field on the ``request`` instance; if ``request`` is provided, this should not be set. payload (:class:`str`): Required. The JWT payload to sign: a JSON object that contains a JWT Claims Set. This corresponds to the ``payload`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.common.SignJwtResponse: """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. if request is not None and any([name, delegates, payload]): raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) request = common.SignJwtRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name if delegates is not None: request.delegates = delegates if payload is not None: request.payload = payload # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method.wrap_method( self._transport.sign_jwt, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response
async def create_span( self, request: trace.Span = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> trace.Span: r"""Creates a new span. Args: request (:class:`google.cloud.trace_v2.types.Span`): The request object. A span represents a single operation within a trace. Spans can be nested to form a trace tree. Often, a trace contains a root span that describes the end-to-end latency, and one or more subspans for its sub-operations. A trace can also contain multiple root spans, or none at all. Spans do not need to be contiguous—there may be gaps or overlaps between spans in a trace. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.trace_v2.types.Span: A span represents a single operation within a trace. Spans can be nested to form a trace tree. Often, a trace contains a root span that describes the end-to-end latency, and one or more subspans for its sub-operations. A trace can also contain multiple root spans, or none at all. Spans do not need to be contiguous—there may be gaps or overlaps between spans in a trace. """ # Create or coerce a protobuf request object. request = trace.Span(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_span, default_retry=retries.Retry( initial=0.1, maximum=1.0, multiplier=1.2, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=120.0, ), default_timeout=120.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response
def retry_predicate(exception: Exception) -> Callable[[Exception], bool]: """"A function that will determine whether we should retry a given Google exception.""" return retry.if_transient_error(exception) or retry.if_exception_type( exceptions.GatewayTimeout)(exception)
async def get_game_server_deployment_rollout( self, request: Union[ game_server_deployments.GetGameServerDeploymentRolloutRequest, dict] = None, *, name: str = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> game_server_deployments.GameServerDeploymentRollout: r"""Gets details a single game server deployment rollout. .. code-block:: python from google.cloud import gaming_v1beta async def sample_get_game_server_deployment_rollout(): # Create a client client = gaming_v1beta.GameServerDeploymentsServiceAsyncClient() # Initialize request argument(s) request = gaming_v1beta.GetGameServerDeploymentRolloutRequest( name="name_value", ) # Make the request response = await client.get_game_server_deployment_rollout(request=request) # Handle the response print(response) Args: request (Union[google.cloud.gaming_v1beta.types.GetGameServerDeploymentRolloutRequest, dict]): The request object. Request message for GameServerDeploymentsService.GetGameServerDeploymentRollout. name (:class:`str`): Required. The name of the game server delpoyment to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.gaming_v1beta.types.GameServerDeploymentRollout: The game server deployment rollout which represents the desired rollout state. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = game_server_deployments.GetGameServerDeploymentRolloutRequest( request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_game_server_deployment_rollout, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("name", request.name), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def list_game_server_deployments( self, request: Union[ game_server_deployments.ListGameServerDeploymentsRequest, dict] = None, *, parent: str = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListGameServerDeploymentsAsyncPager: r"""Lists game server deployments in a given project and location. .. code-block:: python from google.cloud import gaming_v1beta async def sample_list_game_server_deployments(): # Create a client client = gaming_v1beta.GameServerDeploymentsServiceAsyncClient() # Initialize request argument(s) request = gaming_v1beta.ListGameServerDeploymentsRequest( parent="parent_value", ) # Make the request page_result = client.list_game_server_deployments(request=request) # Handle the response async for response in page_result: print(response) Args: request (Union[google.cloud.gaming_v1beta.types.ListGameServerDeploymentsRequest, dict]): The request object. Request message for GameServerDeploymentsService.ListGameServerDeployments. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.gaming_v1beta.services.game_server_deployments_service.pagers.ListGameServerDeploymentsAsyncPager: Response message for GameServerDeploymentsService.ListGameServerDeployments. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = game_server_deployments.ListGameServerDeploymentsRequest( request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_game_server_deployments, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListGameServerDeploymentsAsyncPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
async def get_effective_policy( self, request: orgpolicy.GetEffectivePolicyRequest = None, *, name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> orgpolicy.Policy: r"""Gets the effective ``Policy`` on a resource. This is the result of merging ``Policies`` in the resource hierarchy and evaluating conditions. The returned ``Policy`` will not have an ``etag`` or ``condition`` set because it is a computed ``Policy`` across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded. Args: request (:class:`google.cloud.orgpolicy_v2.types.GetEffectivePolicyRequest`): The request object. The request sent to the [GetEffectivePolicy] [google.cloud.orgpolicy.v2.OrgPolicy.GetEffectivePolicy] method. name (:class:`str`): Required. The effective policy to compute. See ``Policy`` for naming rules. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.orgpolicy_v2.types.Policy: Defines a Cloud Organization Policy which is used to specify Constraints for configurations of Cloud Platform resources. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = orgpolicy.GetEffectivePolicyRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_effective_policy, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("name", request.name), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def get_finding( self, request: web_security_scanner.GetFindingRequest = None, *, name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: r"""Gets a Finding. Args: request (:class:`~.web_security_scanner.GetFindingRequest`): The request object. Request for the `GetFinding` method. name (:class:`str`): Required. The resource name of the Finding to be returned. The name follows the format of 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.finding.Finding: A Finding resource represents a vulnerability instance identified during a ScanRun. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. if request is not None and any([name]): raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) request = web_security_scanner.GetFindingRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_finding, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=600.0, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response
async def update_policy( self, request: orgpolicy.UpdatePolicyRequest = None, *, policy: orgpolicy.Policy = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> orgpolicy.Policy: r"""Updates a Policy. Returns a ``google.rpc.Status`` with ``google.rpc.Code.NOT_FOUND`` if the constraint or the policy do not exist. Returns a ``google.rpc.Status`` with ``google.rpc.Code.ABORTED`` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields. Args: request (:class:`google.cloud.orgpolicy_v2.types.UpdatePolicyRequest`): The request object. The request sent to the [UpdatePolicyRequest] [google.cloud.orgpolicy.v2.OrgPolicy.UpdatePolicy] method. policy (:class:`google.cloud.orgpolicy_v2.types.Policy`): Required. ``Policy`` to update. This corresponds to the ``policy`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.orgpolicy_v2.types.Policy: Defines a Cloud Organization Policy which is used to specify Constraints for configurations of Cloud Platform resources. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([policy]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = orgpolicy.UpdatePolicyRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if policy is not None: request.policy = policy # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_policy, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("policy.name", request.policy.name), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def annotate_text( self, request: language_service.AnnotateTextRequest = None, *, document: language_service.Document = None, features: language_service.AnnotateTextRequest.Features = None, encoding_type: language_service.EncodingType = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> language_service.AnnotateTextResponse: r"""A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call. Args: request (:class:`google.cloud.language_v1.types.AnnotateTextRequest`): The request object. The request message for the text annotation API, which can perform multiple analysis types (sentiment, entities, and syntax) in one call. document (:class:`google.cloud.language_v1.types.Document`): Input document. This corresponds to the ``document`` field on the ``request`` instance; if ``request`` is provided, this should not be set. features (:class:`google.cloud.language_v1.types.AnnotateTextRequest.Features`): The enabled features. This corresponds to the ``features`` field on the ``request`` instance; if ``request`` is provided, this should not be set. encoding_type (:class:`google.cloud.language_v1.types.EncodingType`): The encoding type used by the API to calculate offsets. This corresponds to the ``encoding_type`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.language_v1.types.AnnotateTextResponse: The text annotations response message. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = language_service.AnnotateTextRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if document is not None: request.document = document if features is not None: request.features = features if encoding_type is not None: request.encoding_type = encoding_type # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.annotate_text, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def delete_policy( self, request: orgpolicy.DeletePolicyRequest = None, *, name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a Policy. Returns a ``google.rpc.Status`` with ``google.rpc.Code.NOT_FOUND`` if the constraint or Org Policy does not exist. Args: request (:class:`google.cloud.orgpolicy_v2.types.DeletePolicyRequest`): The request object. The request sent to the [DeletePolicy] [google.cloud.orgpolicy.v2.OrgPolicy.DeletePolicy] method. name (:class:`str`): Required. Name of the policy to delete. See ``Policy`` for naming rules. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = orgpolicy.DeletePolicyRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_policy, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("name", request.name), )), ) # Send the request. await rpc( request, retry=retry, timeout=timeout, metadata=metadata, )
async def resume_job( self, request: cloudscheduler.ResumeJobRequest = None, *, name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: r"""Resume a job. This method reenables a job after it has been [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. The state of a job is stored in [Job.state][google.cloud.scheduler.v1beta1.Job.state]; after calling this method it will be set to [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED]. A job must be in [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED] to be resumed. Args: request (:class:`~.cloudscheduler.ResumeJobRequest`): The request object. Request message for [ResumeJob][google.cloud.scheduler.v1beta1.CloudScheduler.ResumeJob]. name (:class:`str`): Required. The job name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.job.Job: Configuration for a job. The maximum allowed size for a job is 100KB. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. if request is not None and any([name]): raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = cloudscheduler.ResumeJobRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.resume_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=600.0, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("name", request.name), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.list_uptime_check_configs: gapic_v1.method.wrap_method( self.list_uptime_check_configs, default_retry=retries.Retry( initial=0.1, maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=30.0, ), default_timeout=30.0, client_info=client_info, ), self.get_uptime_check_config: gapic_v1.method.wrap_method( self.get_uptime_check_config, default_retry=retries.Retry( initial=0.1, maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=30.0, ), default_timeout=30.0, client_info=client_info, ), self.create_uptime_check_config: gapic_v1.method.wrap_method( self.create_uptime_check_config, default_timeout=30.0, client_info=client_info, ), self.update_uptime_check_config: gapic_v1.method.wrap_method( self.update_uptime_check_config, default_timeout=30.0, client_info=client_info, ), self.delete_uptime_check_config: gapic_v1.method.wrap_method( self.delete_uptime_check_config, default_retry=retries.Retry( initial=0.1, maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=30.0, ), default_timeout=30.0, client_info=client_info, ), self.list_uptime_check_ips: gapic_v1.method.wrap_method( self.list_uptime_check_ips, default_retry=retries.Retry( initial=0.1, maximum=30.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=30.0, ), default_timeout=30.0, client_info=client_info, ), }
async def batch_annotate_files( self, request: image_annotator.BatchAnnotateFilesRequest = None, *, requests: Sequence[image_annotator.AnnotateFileRequest] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateFilesResponse: r"""Service that performs image detection and annotation for a batch of files. Now only "application/pdf", "image/tiff" and "image/gif" are supported. This service will extract at most 5 (customers can specify which 5 in AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each file provided and perform detection and annotation for each image extracted. Args: request (:class:`~.image_annotator.BatchAnnotateFilesRequest`): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. requests (:class:`Sequence[~.image_annotator.AnnotateFileRequest]`): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in BatchAnnotateFilesRequest. This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.image_annotator.BatchAnnotateFilesResponse: A list of file annotation responses. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([requests]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = image_annotator.BatchAnnotateFilesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if requests: request.requests.extend(requests) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.batch_annotate_files, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
# The audience field should always be set to the GCP project id. 'aud': project_id } # Read the private key file. with open(private_key_file, 'r') as f: private_key = f.read() print('Creating JWT using {} from private key file {}'.format( algorithm, private_key_file)) return jwt.encode(token, private_key, algorithm=algorithm).decode('ascii') @retry.Retry( predicate=retry.if_exception_type(AssertionError), deadline=_BACKOFF_DURATION) def publish_message( message, message_type, base_url, project_id, cloud_region, registry_id, device_id, jwt_token): headers = { 'authorization': 'Bearer {}'.format(jwt_token), 'content-type': 'application/json', 'cache-control': 'no-cache' } # Publish to the events or state topic based on the flag. url_suffix = 'publishEvent' if message_type == 'event' else 'setState' publish_url = ( '{}/projects/{}/locations/{}/registries/{}/devices/{}:{}').format(
def sample_row_keys( self, request: bigtable.SampleRowKeysRequest = None, *, table_name: str = None, app_profile_id: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[bigtable.SampleRowKeysResponse]]: r"""Returns a sample of row keys in the table. The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces. Args: request (:class:`google.cloud.bigtable_v2.types.SampleRowKeysRequest`): The request object. Request message for Bigtable.SampleRowKeys. table_name (:class:`str`): Required. The unique name of the table from which to sample row keys. Values are of the form ``projects/<project>/instances/<instance>/tables/<table>``. This corresponds to the ``table_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. app_profile_id (:class:`str`): This value specifies routing for replication. If not specified, the "default" application profile will be used. This corresponds to the ``app_profile_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: AsyncIterable[google.cloud.bigtable_v2.types.SampleRowKeysResponse]: Response message for Bigtable.SampleRowKeys. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([table_name, app_profile_id]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = bigtable.SampleRowKeysRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if table_name is not None: request.table_name = table_name if app_profile_id is not None: request.app_profile_id = app_profile_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.sample_row_keys, default_retry=retries.Retry( initial=0.01, maximum=60.0, multiplier=2, predicate=retries.if_exception_type(), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("table_name", request.table_name), )), ) # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_workflow_template: gapic_v1.method.wrap_method( self.create_workflow_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), self.get_workflow_template: gapic_v1.method.wrap_method( self.get_workflow_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), self.instantiate_workflow_template: gapic_v1.method.wrap_method( self.instantiate_workflow_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), self.instantiate_inline_workflow_template: gapic_v1.method.wrap_method( self.instantiate_inline_workflow_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), self.update_workflow_template: gapic_v1.method.wrap_method( self.update_workflow_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), self.list_workflow_templates: gapic_v1.method.wrap_method( self.list_workflow_templates, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), self.delete_workflow_template: gapic_v1.method.wrap_method( self.delete_workflow_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=client_info, ), }
async def search_hashes(self, request: webrisk.SearchHashesRequest = None, *, hash_prefix: bytes = None, threat_types: Sequence[webrisk.ThreatType] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchHashesResponse: r"""Gets the full hashes that match the requested hash prefix. This is used after a hash prefix is looked up in a threatList and there is a match. The client side threatList only holds partial hashes so the client must query this method to determine if there is a full hash match of a threat. Args: request (:class:`google.cloud.webrisk_v1.types.SearchHashesRequest`): The request object. Request to return full hashes matched by the provided hash prefixes. hash_prefix (:class:`bytes`): A hash prefix, consisting of the most significant 4-32 bytes of a SHA256 hash. For JSON requests, this field is base64-encoded. This corresponds to the ``hash_prefix`` field on the ``request`` instance; if ``request`` is provided, this should not be set. threat_types (:class:`Sequence[google.cloud.webrisk_v1.types.ThreatType]`): Required. The ThreatLists to search in. Multiple ThreatLists may be specified. This corresponds to the ``threat_types`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.webrisk_v1.types.SearchHashesResponse: """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([hash_prefix, threat_types]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = webrisk.SearchHashesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if hash_prefix is not None: request.hash_prefix = hash_prefix if threat_types: request.threat_types.extend(threat_types) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.search_hashes, default_retry=retries.Retry( initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
from google.cloud.bigtable.row_data import PartialRowsData from google.cloud.bigtable.row_data import YieldRowsData from grpc import StatusCode # Maximum number of mutations in bulk (MutateRowsRequest message): # (https://cloud.google.com/bigtable/docs/reference/data/rpc/ # google.bigtable.v2#google.bigtable.v2.MutateRowRequest) _MAX_BULK_MUTATIONS = 100000 class _BigtableRetryableError(Exception): """Retry-able error expected by the default retry strategy.""" DEFAULT_RETRY = Retry( predicate=if_exception_type(_BigtableRetryableError), initial=1.0, maximum=15.0, multiplier=2.0, deadline=120.0, # 2 minutes ) """The default retry stategy to be used on retry-able errors. Used by :meth:`~google.cloud.bigtable.table.Table.mutate_rows`. """ class TableMismatchError(ValueError): """Row from another table."""
def test_if_exception_type(): predicate = retry.if_exception_type(ValueError) assert predicate(ValueError()) assert not predicate(TypeError())
async def list_findings( self, request: web_security_scanner.ListFindingsRequest = None, *, parent: str = None, filter: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsAsyncPager: r"""List Findings under a given ScanRun. Args: request (:class:`~.web_security_scanner.ListFindingsRequest`): The request object. Request for the `ListFindings` method. parent (:class:`str`): Required. The parent resource name, which should be a scan run resource name in the format 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. filter (:class:`str`): Required. The filter expression. The expression must be in the format: . Supported field: 'finding_type'. Supported operator: '='. This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.pagers.ListFindingsAsyncPager: Response for the ``ListFindings`` method. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. if request is not None and any([parent, filter]): raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) request = web_security_scanner.ListFindingsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent if filter is not None: request.filter = filter # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_findings, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, ), ), default_timeout=600.0, client_info=_client_info, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) # Send the request. response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListFindingsAsyncPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
async def detect_intent( self, request: Union[gcd_session.DetectIntentRequest, dict] = None, *, session: str = None, query_input: gcd_session.QueryInput = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session.DetectIntentResponse: r"""Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries. If you might use `Agent Assist <https://cloud.google.com/dialogflow/docs/#aa>`__ or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent] instead of ``DetectIntent``. ``AnalyzeContent`` has additional functionality for Agent Assist and other CCAI products. Note: Always use agent versions for production traffic. See `Versions and environments <https://cloud.google.com/dialogflow/es/docs/agents-versions>`__. .. code-block:: python from google.cloud import dialogflow_v2beta1 async def sample_detect_intent(): # Create a client client = dialogflow_v2beta1.SessionsAsyncClient() # Initialize request argument(s) request = dialogflow_v2beta1.DetectIntentRequest( session="session_value", ) # Make the request response = await client.detect_intent(request=request) # Handle the response print(response) Args: request (Union[google.cloud.dialogflow_v2beta1.types.DetectIntentRequest, dict]): The request object. The request to detect user's intent. session (:class:`str`): Required. The name of the session this query is sent to. Supported formats: - \`projects//agent/sessions/, - ``projects/<Project ID>/locations/<Location ID>/agent/sessions/<Session ID>``, - ``projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>``, - ``projects/<Project ID>/locations/<Location ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>``, If ``Location ID`` is not specified we assume default 'us' location. If ``Environment ID`` is not specified, we assume default 'draft' environment (``Environment ID`` might be referred to as environment name at some places). If ``User ID`` is not specified, we are using "-". It's up to the API caller to choose an appropriate ``Session ID`` and ``User Id``. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the ``Session ID`` and ``User ID`` must not exceed 36 characters. For more information, see the `API interactions guide <https://cloud.google.com/dialogflow/docs/api-overview>`__. Note: Always use agent versions for production traffic. See `Versions and environments <https://cloud.google.com/dialogflow/es/docs/agents-versions>`__. This corresponds to the ``session`` field on the ``request`` instance; if ``request`` is provided, this should not be set. query_input (:class:`google.cloud.dialogflow_v2beta1.types.QueryInput`): Required. The input specification. It can be set to: 1. an audio config which instructs the speech recognizer how to process the speech audio, 2. a conversational query in the form of text, or 3. an event that specifies which intent to trigger. This corresponds to the ``query_input`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.dialogflow_v2beta1.types.DetectIntentResponse: The message returned from the DetectIntent method. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([session, query_input]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = gcd_session.DetectIntentRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if session is not None: request.session = session if query_input is not None: request.query_input = query_input # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.detect_intent, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.ServiceUnavailable, ), deadline=220.0, ), default_timeout=220.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("session", request.session), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def fetch_deployment_state( self, request: Union[game_server_deployments.FetchDeploymentStateRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> game_server_deployments.FetchDeploymentStateResponse: r"""Retrieves information about the current state of the game server deployment. Gathers all the Agones fleets and Agones autoscalers, including fleets running an older version of the game server deployment. .. code-block:: python from google.cloud import gaming_v1beta async def sample_fetch_deployment_state(): # Create a client client = gaming_v1beta.GameServerDeploymentsServiceAsyncClient() # Initialize request argument(s) request = gaming_v1beta.FetchDeploymentStateRequest( name="name_value", ) # Make the request response = await client.fetch_deployment_state(request=request) # Handle the response print(response) Args: request (Union[google.cloud.gaming_v1beta.types.FetchDeploymentStateRequest, dict]): The request object. Request message for GameServerDeploymentsService.FetchDeploymentState. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.gaming_v1beta.types.FetchDeploymentStateResponse: Response message for GameServerDeploymentsService.FetchDeploymentState. """ # Create or coerce a protobuf request object. request = game_server_deployments.FetchDeploymentStateRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.fetch_deployment_state, default_retry=retries.Retry( initial=1.0, maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.ServiceUnavailable, ), deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("name", request.name), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.inspect_content: gapic_v1.method.wrap_method( self.inspect_content, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.redact_image: gapic_v1.method.wrap_method( self.redact_image, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.deidentify_content: gapic_v1.method.wrap_method( self.deidentify_content, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.reidentify_content: gapic_v1.method.wrap_method( self.reidentify_content, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.list_info_types: gapic_v1.method.wrap_method( self.list_info_types, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.create_inspect_template: gapic_v1.method.wrap_method( self.create_inspect_template, default_timeout=300.0, client_info=client_info, ), self.update_inspect_template: gapic_v1.method.wrap_method( self.update_inspect_template, default_timeout=300.0, client_info=client_info, ), self.get_inspect_template: gapic_v1.method.wrap_method( self.get_inspect_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.list_inspect_templates: gapic_v1.method.wrap_method( self.list_inspect_templates, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.delete_inspect_template: gapic_v1.method.wrap_method( self.delete_inspect_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.create_deidentify_template: gapic_v1.method.wrap_method( self.create_deidentify_template, default_timeout=300.0, client_info=client_info, ), self.update_deidentify_template: gapic_v1.method.wrap_method( self.update_deidentify_template, default_timeout=300.0, client_info=client_info, ), self.get_deidentify_template: gapic_v1.method.wrap_method( self.get_deidentify_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.list_deidentify_templates: gapic_v1.method.wrap_method( self.list_deidentify_templates, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.delete_deidentify_template: gapic_v1.method.wrap_method( self.delete_deidentify_template, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.create_job_trigger: gapic_v1.method.wrap_method( self.create_job_trigger, default_timeout=300.0, client_info=client_info, ), self.update_job_trigger: gapic_v1.method.wrap_method( self.update_job_trigger, default_timeout=300.0, client_info=client_info, ), self.hybrid_inspect_job_trigger: gapic_v1.method.wrap_method( self.hybrid_inspect_job_trigger, default_timeout=300.0, client_info=client_info, ), self.get_job_trigger: gapic_v1.method.wrap_method( self.get_job_trigger, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.list_job_triggers: gapic_v1.method.wrap_method( self.list_job_triggers, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.delete_job_trigger: gapic_v1.method.wrap_method( self.delete_job_trigger, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.activate_job_trigger: gapic_v1.method.wrap_method( self.activate_job_trigger, default_timeout=300.0, client_info=client_info, ), self.create_dlp_job: gapic_v1.method.wrap_method( self.create_dlp_job, default_timeout=300.0, client_info=client_info, ), self.list_dlp_jobs: gapic_v1.method.wrap_method( self.list_dlp_jobs, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.get_dlp_job: gapic_v1.method.wrap_method( self.get_dlp_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.delete_dlp_job: gapic_v1.method.wrap_method( self.delete_dlp_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.cancel_dlp_job: gapic_v1.method.wrap_method( self.cancel_dlp_job, default_timeout=300.0, client_info=client_info, ), self.create_stored_info_type: gapic_v1.method.wrap_method( self.create_stored_info_type, default_timeout=300.0, client_info=client_info, ), self.update_stored_info_type: gapic_v1.method.wrap_method( self.update_stored_info_type, default_timeout=300.0, client_info=client_info, ), self.get_stored_info_type: gapic_v1.method.wrap_method( self.get_stored_info_type, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.list_stored_info_types: gapic_v1.method.wrap_method( self.list_stored_info_types, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.delete_stored_info_type: gapic_v1.method.wrap_method( self.delete_stored_info_type, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=300.0, ), default_timeout=300.0, client_info=client_info, ), self.hybrid_inspect_dlp_job: gapic_v1.method.wrap_method( self.hybrid_inspect_dlp_job, default_timeout=300.0, client_info=client_info, ), self.finish_dlp_job: gapic_v1.method.wrap_method( self.finish_dlp_job, default_timeout=300.0, client_info=client_info, ), }
def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.submit_job: gapic_v1.method.wrap_method( self.submit_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), self.submit_job_as_operation: gapic_v1.method.wrap_method( self.submit_job_as_operation, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), self.get_job: gapic_v1.method.wrap_method( self.get_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), self.list_jobs: gapic_v1.method.wrap_method( self.list_jobs, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), self.update_job: gapic_v1.method.wrap_method( self.update_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), self.cancel_job: gapic_v1.method.wrap_method( self.cancel_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), self.delete_job: gapic_v1.method.wrap_method( self.delete_job, default_retry=retries.Retry( initial=0.1, maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( exceptions.ServiceUnavailable, ), ), default_timeout=900.0, client_info=client_info, ), }
bigtable_table_admin_pb2 as table_admin_messages_v2_pb2) # Maximum number of mutations in bulk (MutateRowsRequest message): # (https://cloud.google.com/bigtable/docs/reference/data/rpc/ # google.bigtable.v2#google.bigtable.v2.MutateRowRequest) _MAX_BULK_MUTATIONS = 100000 VIEW_NAME_ONLY = enums.Table.View.NAME_ONLY class _BigtableRetryableError(Exception): """Retry-able error expected by the default retry strategy.""" DEFAULT_RETRY = Retry( predicate=if_exception_type(_BigtableRetryableError), initial=1.0, maximum=15.0, multiplier=2.0, deadline=120.0, # 2 minutes ) """The default retry stategy to be used on retry-able errors. Used by :meth:`~google.cloud.bigtable.table.Table.mutate_rows`. """ class TableMismatchError(ValueError): """Row from another table."""
import abc import concurrent.futures from google.api_core import exceptions from google.api_core import retry from google.api_core.future import _helpers from google.api_core.future import base class _OperationNotComplete(Exception): """Private exception used for polling via retry.""" pass RETRY_PREDICATE = retry.if_exception_type(_OperationNotComplete) DEFAULT_RETRY = retry.Retry(predicate=RETRY_PREDICATE) class PollingFuture(base.Future): """A Future that needs to poll some service to check its status. The :meth:`done` method should be implemented by subclasses. The polling behavior will repeatedly call ``done`` until it returns True. .. note: Privacy here is intended to prevent the final class from overexposing, not to prevent subclasses from accessing methods. Args: retry (google.api_core.retry.Retry): The retry configuration used when polling. This can be used to control how often :meth:`done`