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

Commit 061eb45

Browse files
feat: add api key support (#267)
* chore: upgrade gapic-generator-java, gax-java and gapic-generator-python PiperOrigin-RevId: 423842556 Source-Link: googleapis/googleapis@a616ca0 Source-Link: https://github.com/googleapis/googleapis-gen/commit/29b938c58c1e51d019f2ee539d55dc0a3c86a905 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>
1 parent 458a23c commit 061eb45

File tree

35 files changed

+2482
-180
lines changed

35 files changed

+2482
-180
lines changed

google/cloud/documentai_v1/services/document_processor_service/async_client.py

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from collections import OrderedDict
1717
import functools
1818
import re
19-
from typing import Dict, Sequence, Tuple, Type, Union
19+
from typing import Dict, Optional, Sequence, Tuple, Type, Union
2020
import pkg_resources
2121

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

126126
from_service_account_json = from_service_account_file
127127

128+
@classmethod
129+
def get_mtls_endpoint_and_cert_source(
130+
cls, client_options: Optional[ClientOptions] = None
131+
):
132+
"""Return the API endpoint and client cert source for mutual TLS.
133+
134+
The client cert source is determined in the following order:
135+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
136+
client cert source is None.
137+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
138+
default client cert source exists, use the default one; otherwise the client cert
139+
source is None.
140+
141+
The API endpoint is determined in the following order:
142+
(1) if `client_options.api_endpoint` if provided, use the provided one.
143+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
144+
default mTLS endpoint; if the environment variabel is "never", use the default API
145+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
146+
use the default API endpoint.
147+
148+
More details can be found at https://google.aip.dev/auth/4114.
149+
150+
Args:
151+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
152+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
153+
in this method.
154+
155+
Returns:
156+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
157+
client cert source to use.
158+
159+
Raises:
160+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
161+
"""
162+
return DocumentProcessorServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
163+
128164
@property
129165
def transport(self) -> DocumentProcessorServiceTransport:
130166
"""Returns the transport used by the client instance.
@@ -197,6 +233,34 @@ async def process_document(
197233
) -> document_processor_service.ProcessResponse:
198234
r"""Processes a single document.
199235
236+
.. code-block::
237+
238+
from google.cloud import documentai_v1
239+
240+
def sample_process_document():
241+
# Create a client
242+
client = documentai_v1.DocumentProcessorServiceClient()
243+
244+
# Initialize request argument(s)
245+
inline_document = documentai_v1.Document()
246+
inline_document.uri = "uri_value"
247+
248+
project = "my-project-id"
249+
location = "us-central1"
250+
processor = "processor_value"
251+
name = f"projects/{project}/locations/{location}/processors/{processor}"
252+
253+
request = documentai_v1.ProcessRequest(
254+
inline_document=inline_document,
255+
name=name,
256+
)
257+
258+
# Make the request
259+
response = client.process_document(request=request)
260+
261+
# Handle response
262+
print(response)
263+
200264
Args:
201265
request (Union[google.cloud.documentai_v1.types.ProcessRequest, dict]):
202266
The request object. Request message for the process
@@ -279,6 +343,33 @@ async def batch_process_documents(
279343
r"""LRO endpoint to batch process many documents. The output is
280344
written to Cloud Storage as JSON in the [Document] format.
281345
346+
347+
.. code-block::
348+
349+
from google.cloud import documentai_v1
350+
351+
def sample_batch_process_documents():
352+
# Create a client
353+
client = documentai_v1.DocumentProcessorServiceClient()
354+
355+
# Initialize request argument(s)
356+
project = "my-project-id"
357+
location = "us-central1"
358+
processor = "processor_value"
359+
name = f"projects/{project}/locations/{location}/processors/{processor}"
360+
361+
request = documentai_v1.BatchProcessRequest(
362+
name=name,
363+
)
364+
365+
# Make the request
366+
operation = client.batch_process_documents(request=request)
367+
368+
print("Waiting for operation to complete...")
369+
370+
response = operation.result()
371+
print(response)
372+
282373
Args:
283374
request (Union[google.cloud.documentai_v1.types.BatchProcessRequest, dict]):
284375
The request object. Request message for batch process
@@ -372,6 +463,37 @@ async def review_document(
372463
r"""Send a document for Human Review. The input document
373464
should be processed by the specified processor.
374465
466+
467+
.. code-block::
468+
469+
from google.cloud import documentai_v1
470+
471+
def sample_review_document():
472+
# Create a client
473+
client = documentai_v1.DocumentProcessorServiceClient()
474+
475+
# Initialize request argument(s)
476+
inline_document = documentai_v1.Document()
477+
inline_document.uri = "uri_value"
478+
479+
project = "my-project-id"
480+
location = "us-central1"
481+
processor = "processor_value"
482+
human_review_config = f"projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig"
483+
484+
request = documentai_v1.ReviewDocumentRequest(
485+
inline_document=inline_document,
486+
human_review_config=human_review_config,
487+
)
488+
489+
# Make the request
490+
operation = client.review_document(request=request)
491+
492+
print("Waiting for operation to complete...")
493+
494+
response = operation.result()
495+
print(response)
496+
375497
Args:
376498
request (Union[google.cloud.documentai_v1.types.ReviewDocumentRequest, dict]):
377499
The request object. Request message for review document

0 commit comments

Comments
 (0)