Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
feat: add api key support (#267)
Browse files Browse the repository at this point in the history
* chore: upgrade gapic-generator-java, gax-java and gapic-generator-python

PiperOrigin-RevId: 423842556

Source-Link: googleapis/googleapis@a616ca0

Source-Link: googleapis/googleapis-gen@29b938c
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMjliOTM4YzU4YzFlNTFkMDE5ZjJlZTUzOWQ1NWRjMGEzYzg2YTkwNSJ9

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] committed Jan 26, 2022
1 parent 458a23c commit 061eb45
Show file tree
Hide file tree
Showing 35 changed files with 2,482 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections import OrderedDict
import functools
import re
from typing import Dict, Sequence, Tuple, Type, Union
from typing import Dict, Optional, Sequence, Tuple, Type, Union
import pkg_resources

from google.api_core.client_options import ClientOptions
Expand Down Expand Up @@ -125,6 +125,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):

from_service_account_json = from_service_account_file

@classmethod
def get_mtls_endpoint_and_cert_source(
cls, client_options: Optional[ClientOptions] = None
):
"""Return the API endpoint and client cert source for mutual TLS.
The client cert source is determined in the following order:
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
client cert source is None.
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
default client cert source exists, use the default one; otherwise the client cert
source is None.
The API endpoint is determined in the following order:
(1) if `client_options.api_endpoint` if provided, use the provided one.
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
default mTLS endpoint; if the environment variabel is "never", use the default API
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
use the default API endpoint.
More details can be found at https://google.aip.dev/auth/4114.
Args:
client_options (google.api_core.client_options.ClientOptions): Custom options for the
client. Only the `api_endpoint` and `client_cert_source` properties may be used
in this method.
Returns:
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
client cert source to use.
Raises:
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
"""
return DocumentProcessorServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore

@property
def transport(self) -> DocumentProcessorServiceTransport:
"""Returns the transport used by the client instance.
Expand Down Expand Up @@ -197,6 +233,34 @@ async def process_document(
) -> document_processor_service.ProcessResponse:
r"""Processes a single document.
.. code-block::
from google.cloud import documentai_v1
def sample_process_document():
# Create a client
client = documentai_v1.DocumentProcessorServiceClient()
# Initialize request argument(s)
inline_document = documentai_v1.Document()
inline_document.uri = "uri_value"
project = "my-project-id"
location = "us-central1"
processor = "processor_value"
name = f"projects/{project}/locations/{location}/processors/{processor}"
request = documentai_v1.ProcessRequest(
inline_document=inline_document,
name=name,
)
# Make the request
response = client.process_document(request=request)
# Handle response
print(response)
Args:
request (Union[google.cloud.documentai_v1.types.ProcessRequest, dict]):
The request object. Request message for the process
Expand Down Expand Up @@ -279,6 +343,33 @@ async def batch_process_documents(
r"""LRO endpoint to batch process many documents. The output is
written to Cloud Storage as JSON in the [Document] format.
.. code-block::
from google.cloud import documentai_v1
def sample_batch_process_documents():
# Create a client
client = documentai_v1.DocumentProcessorServiceClient()
# Initialize request argument(s)
project = "my-project-id"
location = "us-central1"
processor = "processor_value"
name = f"projects/{project}/locations/{location}/processors/{processor}"
request = documentai_v1.BatchProcessRequest(
name=name,
)
# Make the request
operation = client.batch_process_documents(request=request)
print("Waiting for operation to complete...")
response = operation.result()
print(response)
Args:
request (Union[google.cloud.documentai_v1.types.BatchProcessRequest, dict]):
The request object. Request message for batch process
Expand Down Expand Up @@ -372,6 +463,37 @@ async def review_document(
r"""Send a document for Human Review. The input document
should be processed by the specified processor.
.. code-block::
from google.cloud import documentai_v1
def sample_review_document():
# Create a client
client = documentai_v1.DocumentProcessorServiceClient()
# Initialize request argument(s)
inline_document = documentai_v1.Document()
inline_document.uri = "uri_value"
project = "my-project-id"
location = "us-central1"
processor = "processor_value"
human_review_config = f"projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig"
request = documentai_v1.ReviewDocumentRequest(
inline_document=inline_document,
human_review_config=human_review_config,
)
# Make the request
operation = client.review_document(request=request)
print("Waiting for operation to complete...")
response = operation.result()
print(response)
Args:
request (Union[google.cloud.documentai_v1.types.ReviewDocumentRequest, dict]):
The request object. Request message for review document
Expand Down
Loading

0 comments on commit 061eb45

Please sign in to comment.