def _instance_api_response_for_update(self): import datetime from google.api_core import operation from google.longrunning import operations_pb2 from google.protobuf.any_pb2 import Any from google.cloud._helpers import _datetime_to_pb_timestamp from google.cloud.bigtable_admin_v2.gapic import bigtable_instance_admin_client from google.cloud.bigtable_admin_v2.proto import ( bigtable_instance_admin_pb2 as messages_v2_pb2, ) from google.cloud.bigtable_admin_v2.types import instance_pb2 NOW = datetime.datetime.utcnow() NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.UpdateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( messages_v2_pb2.UpdateInstanceMetadata.DESCRIPTOR.full_name ) response_pb = operations_pb2.Operation( name=self.OP_NAME, metadata=Any(type_url=type_url, value=metadata.SerializeToString()), ) response = operation.from_gapic( response_pb, mock.Mock(), instance_pb2.Instance, metadata_type=messages_v2_pb2.UpdateInstanceMetadata, ) instance_path_template = "projects/{project}/instances/{instance}" instance_api = mock.create_autospec( bigtable_instance_admin_client.BigtableInstanceAdminClient ) instance_api.partial_update_instance.return_value = response instance_api.instance_path = instance_path_template.format return instance_api, response
def test_from_gapic(): operation_proto = make_operation_proto(done=True) operations_client = mock.create_autospec( operations_v1.OperationsClient, instance=True) future = operation.from_gapic( operation_proto, operations_client, struct_pb2.Struct, metadata_type=struct_pb2.Struct) assert future._result_type == struct_pb2.Struct assert future._metadata_type == struct_pb2.Struct assert future.operation.name == TEST_OPERATION_NAME assert future.done
def update_game_server_deployment( self, request: game_server_deployments. UpdateGameServerDeploymentRequest = None, *, game_server_deployment: game_server_deployments. GameServerDeployment = None, update_mask: field_mask.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Patches a Game Server Deployment. Args: request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.UpdateGameServerDeployment. Only allows updates for labels. game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): Required. The Game Server Deployment to be updated. Only fields specified in update_mask are updated. This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (:class:`~.field_mask.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask This corresponds to the ``update_mask`` 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:``~.game_server_deployments.GameServerDeployment``: A Game Server Deployment resource. """ # 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([game_server_deployment, update_mask]): raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = game_server_deployments.UpdateGameServerDeploymentRequest( request) # If we have keyword arguments corresponding to fields on the # request, apply these. if game_server_deployment is not None: request.game_server_deployment = game_server_deployment if update_mask is not None: request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method.wrap_method( self._transport.update_game_server_deployment, default_timeout=None, client_info=_client_info, ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, game_server_deployments.GameServerDeployment, metadata_type=common.OperationMetadata, ) # Done; return the response. return response
def update_environment( self, request: gcdc_environment.UpdateEnvironmentRequest = None, *, environment: gcdc_environment.Environment = None, update_mask: field_mask.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the specified [Environment][google.cloud.dialogflow.cx.v3.Environment]. Args: request (google.cloud.dialogflowcx_v3.types.UpdateEnvironmentRequest): The request object. The request message for [Environments.UpdateEnvironment][google.cloud.dialogflow.cx.v3.Environments.UpdateEnvironment]. environment (google.cloud.dialogflowcx_v3.types.Environment): Required. The environment to update. This corresponds to the ``environment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The mask to control which fields get updated. This corresponds to the ``update_mask`` 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.dialogflowcx_v3.types.Environment` Represents an environment for an agent. You can create multiple versions of your agent and publish them to separate environments. When you edit an agent, you are editing the draft agent. At any point, you can save the draft agent as an agent version, which is an immutable snapshot of your agent. When you save the draft agent, it is published to the default environment. When you create agent versions, you can publish them to custom environments. You can create a variety of custom environments for testing, development, production, etc. """ # 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([environment, update_mask]) 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." ) # Minor optimization to avoid making a copy if the user passes # in a gcdc_environment.UpdateEnvironmentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, gcdc_environment.UpdateEnvironmentRequest): request = gcdc_environment.UpdateEnvironmentRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if environment is not None: request.environment = environment if update_mask is not None: request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_environment] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( (("environment.name", request.environment.name),) ), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, gcdc_environment.Environment, metadata_type=struct.Struct, ) # Done; return the response. return response
def delete_game_server_deployment( self, request: game_server_deployments. DeleteGameServerDeploymentRequest = None, *, name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes a single Game Server Deployment. Args: request (:class:`~.game_server_deployments.DeleteGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.DeleteGameServerDeployment. name (:class:`str`): Required. The name of the Game Server Deployment to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. 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: ~.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:``~.game_server_deployments.GameServerDeployment``: A Game Server Deployment resource. """ # 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 = game_server_deployments.DeleteGameServerDeploymentRequest( 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.wrap_method( self._transport.delete_game_server_deployment, default_timeout=None, client_info=_client_info, ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, game_server_deployments.GameServerDeployment, metadata_type=common.OperationMetadata, ) # Done; return the response. return response
def create_workload( self, request: assuredworkloads_v1beta1.CreateWorkloadRequest = None, *, parent: str = None, workload: assuredworkloads_v1beta1.Workload = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates Assured Workload. Args: request (google.cloud.assuredworkloads_v1beta1.types.CreateWorkloadRequest): The request object. Request for creating a workload. parent (str): Required. The resource name of the new Workload's parent. Must be of the form ``organizations/{org_id}/locations/{location_id}``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. workload (google.cloud.assuredworkloads_v1beta1.types.Workload): Required. Assured Workload to create This corresponds to the ``workload`` 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.assuredworkloads_v1beta1.types.Workload` An Workload object for managing highly regulated workloads of cloud customers. """ # 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, workload]) 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.") # Minor optimization to avoid making a copy if the user passes # in a assuredworkloads_v1beta1.CreateWorkloadRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, assuredworkloads_v1beta1.CreateWorkloadRequest): request = assuredworkloads_v1beta1.CreateWorkloadRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent if workload is not None: request.workload = workload # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_workload] # 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 = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, assuredworkloads_v1beta1.Workload, metadata_type=assuredworkloads_v1beta1. CreateWorkloadOperationMetadata, ) # Done; return the response. return response
def promote_campaign_draft( self, request: Union[campaign_draft_service.PromoteCampaignDraftRequest, dict] = None, *, campaign_draft: str = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Promotes the changes in a draft back to the base campaign. This method returns a Long Running Operation (LRO) indicating if the Promote is done. Use [Operations.GetOperation] to poll the LRO until it is done. Only a done status is returned in the response. See the status in the Campaign Draft resource to determine if the promotion was successful. If the LRO failed, use [CampaignDraftService.ListCampaignDraftAsyncErrors][google.ads.googleads.v10.services.CampaignDraftService.ListCampaignDraftAsyncErrors] to view the list of error reasons. List of thrown errors: `AuthenticationError <>`__ `AuthorizationError <>`__ `CampaignDraftError <>`__ `HeaderError <>`__ `InternalError <>`__ `QuotaError <>`__ `RequestError <>`__ Args: request (Union[google.ads.googleads.v10.services.types.PromoteCampaignDraftRequest, dict]): The request object. Request message for [CampaignDraftService.PromoteCampaignDraft][google.ads.googleads.v10.services.CampaignDraftService.PromoteCampaignDraft]. campaign_draft (str): Required. The resource name of the campaign draft to promote. This corresponds to the ``campaign_draft`` 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } The JSON representation for Empty is empty JSON object {}. """ # 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([campaign_draft]) 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.") # Minor optimization to avoid making a copy if the user passes # in a campaign_draft_service.PromoteCampaignDraftRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, campaign_draft_service.PromoteCampaignDraftRequest): request = campaign_draft_service.PromoteCampaignDraftRequest( request) # If we have keyword arguments corresponding to fields on the # request, apply these. if campaign_draft is not None: request.campaign_draft = campaign_draft # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ self._transport.promote_campaign_draft] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("campaign_draft", request.campaign_draft), )), ) # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, empty_pb2.Empty, metadata_type=empty_pb2.Empty, ) # Done; return the response. return response
def restore_agent( self, request: agent.RestoreAgentRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Restores the specified agent from a ZIP file. Replaces the current agent version with a new one. All the intents and entity types in the older version are deleted. After the restore, the restored draft agent will be trained automatically (unless disabled in agent settings). However, once the restore is done, training may not be completed yet. Please call [TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent] and wait for the operation it returns in order to train explicitly. An operation which tracks when restoring is complete. It only tracks when the draft agent is updated not when it is done training. Note: You should always train an agent prior to sending it queries. See the `training documentation <https://cloud.google.com/dialogflow/es/docs/training>`__. Args: request (google.cloud.dialogflow_v2.types.RestoreAgentRequest): The request object. The request message for [Agents.RestoreAgent][google.cloud.dialogflow.v2.Agents.RestoreAgent]. 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } The JSON representation for Empty is empty JSON object {}. """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a agent.RestoreAgentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, agent.RestoreAgentRequest): request = agent.RestoreAgentRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.restore_agent] # 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 = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, empty_pb2.Empty, metadata_type=struct_pb2.Struct, ) # Done; return the response. return response
def batch_process_documents( self, request: document_understanding. BatchProcessDocumentsRequest = None, *, requests: Sequence[ document_understanding.ProcessDocumentRequest] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. Args: request (google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest): The request object. Request to batch process documents as an asynchronous operation. The output is written to Cloud Storage as JSON in the [Document] format. requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]): Required. Individual requests for each document. 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: google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in the LRO Operation after the operation is complete. """ # 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.") # Minor optimization to avoid making a copy if the user passes # in a document_understanding.BatchProcessDocumentsRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, document_understanding.BatchProcessDocumentsRequest): request = document_understanding.BatchProcessDocumentsRequest( request) # If we have keyword arguments corresponding to fields on the # request, apply these. if requests is not None: request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ self._transport.batch_process_documents] # 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 = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, document_understanding.BatchProcessDocumentsResponse, metadata_type=document_understanding.OperationMetadata, ) # Done; return the response. return response
def export_agent( self, request: agent.ExportAgentRequest = None, *, parent: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Exports the specified agent to a ZIP file. Args: request (google.cloud.dialogflow_v2.types.ExportAgentRequest): The request object. The request message for [Agents.ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent]. parent (str): Required. The project that the agent to export is associated with. Format: ``projects/<Project 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.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.dialogflow_v2.types.ExportAgentResponse` The response message for [Agents.ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent]. """ # 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." ) # Minor optimization to avoid making a copy if the user passes # in a agent.ExportAgentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, agent.ExportAgentRequest): request = agent.ExportAgentRequest(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 = self._transport._wrapped_methods[self._transport.export_agent] # 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 = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, agent.ExportAgentResponse, metadata_type=struct_pb2.Struct, ) # Done; return the response. return response
def reload_document( self, request: document.ReloadDocumentRequest = None, *, name: str = None, content_uri: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Reloads the specified document from its specified source, content_uri or content. The previously loaded content of the document will be deleted. Note: Even when the content of the document has not changed, there still may be side effects because of internal implementation changes. Note: The ``projects.agent.knowledgeBases.documents`` resource is deprecated; only use ``projects.knowledgeBases.documents``. Operation <response: [Document][google.cloud.dialogflow.v2.Document], metadata: [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata]> Args: request (google.cloud.dialogflow_v2.types.ReloadDocumentRequest): The request object. Request message for [Documents.ReloadDocument][google.cloud.dialogflow.v2.Documents.ReloadDocument]. name (str): Required. The name of the document to reload. Format: ``projects/<Project ID>/locations/<Location ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. content_uri (str): Optional. The path of gcs source file for reloading document content. For now, only gcs uri is supported. For documents stored in Google Cloud Storage, these URIs must have the form ``gs://<bucket-name>/<object-name>``. This corresponds to the ``content_uri`` 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.dialogflow_v2.types.Document` A knowledge document to be used by a [KnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBase]. For more information, see the [knowledge base guide](\ https://cloud.google.com/dialogflow/docs/how/knowledge-bases). Note: The projects.agent.knowledgeBases.documents resource is deprecated; only use projects.knowledgeBases.documents. """ # 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, content_uri]) 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." ) # Minor optimization to avoid making a copy if the user passes # in a document.ReloadDocumentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, document.ReloadDocumentRequest): request = document.ReloadDocumentRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name if content_uri is not None: request.content_uri = content_uri # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.reload_document] # 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,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, document.Document, metadata_type=document.KnowledgeOperationMetadata, ) # Done; return the response. return response
def update_document( self, request: gcd_document.UpdateDocumentRequest = None, *, document: gcd_document.Document = None, update_mask: field_mask.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the specified document. Operation <response: [Document][google.cloud.dialogflow.v2.Document], metadata: [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata]> Args: request (google.cloud.dialogflow_v2.types.UpdateDocumentRequest): The request object. Request message for [Documents.UpdateDocument][google.cloud.dialogflow.v2.Documents.UpdateDocument]. document (google.cloud.dialogflow_v2.types.Document): Required. The document to update. This corresponds to the ``document`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Not specified means ``update all``. Currently, only ``display_name`` can be updated, an InvalidArgument will be returned for attempting to update other fields. This corresponds to the ``update_mask`` 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.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.dialogflow_v2.types.Document` A knowledge document to be used by a [KnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBase]. For more information, see the [knowledge base guide](\ https://cloud.google.com/dialogflow/docs/how/knowledge-bases). Note: The projects.agent.knowledgeBases.documents resource is deprecated; only use projects.knowledgeBases.documents. """ # 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, update_mask]) 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." ) # Minor optimization to avoid making a copy if the user passes # in a gcd_document.UpdateDocumentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, gcd_document.UpdateDocumentRequest): request = gcd_document.UpdateDocumentRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if document is not None: request.document = document if update_mask is not None: request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_document] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( (("document.name", request.document.name),) ), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, gcd_document.Document, metadata_type=gcd_document.KnowledgeOperationMetadata, ) # Done; return the response. return response
def delete_document( self, request: document.DeleteDocumentRequest = None, *, name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes the specified document. Operation <response: [google.protobuf.Empty][google.protobuf.Empty], metadata: [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata]> Args: request (google.cloud.dialogflow_v2.types.DeleteDocumentRequest): The request object. Request message for [Documents.DeleteDocument][google.cloud.dialogflow.v2.Documents.DeleteDocument]. name (str): Required. The name of the document to delete. Format: ``projects/<Project ID>/locations/<Location ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document 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: google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } The JSON representation for Empty is empty JSON object {}. """ # 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." ) # Minor optimization to avoid making a copy if the user passes # in a document.DeleteDocumentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, document.DeleteDocumentRequest): request = document.DeleteDocumentRequest(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 = self._transport._wrapped_methods[self._transport.delete_document] # 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,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, empty.Empty, metadata_type=document.KnowledgeOperationMetadata, ) # Done; return the response. return response
def run_offline_user_data_job( self, request: offline_user_data_job_service. RunOfflineUserDataJobRequest = None, *, resource_name: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Runs the offline user data job. When finished, the long running operation will contain the processing result or failure information, if any. List of thrown errors: `AuthenticationError <>`__ `AuthorizationError <>`__ `DatabaseError <>`__ `HeaderError <>`__ `InternalError <>`__ `OfflineUserDataJobError <>`__ `QuotaError <>`__ `RequestError <>`__ Args: request (:class:`google.ads.googleads.v8.services.types.RunOfflineUserDataJobRequest`): The request object. Request message for [OfflineUserDataJobService.RunOfflineUserDataJob][google.ads.googleads.v8.services.OfflineUserDataJobService.RunOfflineUserDataJob]. resource_name (:class:`str`): Required. The resource name of the OfflineUserDataJob to run. This corresponds to the ``resource_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.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } The JSON representation for Empty is empty JSON object {}. """ # 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([resource_name]): raise ValueError('If the `request` argument is set, then none of ' 'the individual field arguments should be set.') # Minor optimization to avoid making a copy if the user passes # in a offline_user_data_job_service.RunOfflineUserDataJobRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance( request, offline_user_data_job_service.RunOfflineUserDataJobRequest): request = offline_user_data_job_service.RunOfflineUserDataJobRequest( request) # If we have keyword arguments corresponding to fields on the # request, apply these. if resource_name is not None: request.resource_name = resource_name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ self._transport.run_offline_user_data_job] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (('resource_name', request.resource_name), )), ) # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, empty_pb2.Empty, metadata_type=empty_pb2.Empty, ) # Done; return the response. return response