diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py index 6022a3b6c19f..55a9432a6aba 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py @@ -61,6 +61,10 @@ class PipelineServiceAsyncClient: DEFAULT_ENDPOINT = PipelineServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = PipelineServiceClient.DEFAULT_MTLS_ENDPOINT + cloud_function_path = staticmethod(PipelineServiceClient.cloud_function_path) + parse_cloud_function_path = staticmethod( + PipelineServiceClient.parse_cloud_function_path + ) location_path = staticmethod(PipelineServiceClient.location_path) parse_location_path = staticmethod(PipelineServiceClient.parse_location_path) common_billing_account_path = staticmethod( diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py index 877fa77b0fcb..ac1f760b8ce1 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py @@ -180,6 +180,28 @@ def transport(self) -> PipelineServiceTransport: """ return self._transport + @staticmethod + def cloud_function_path( + project: str, + location: str, + function: str, + ) -> str: + """Returns a fully-qualified cloud_function string.""" + return "projects/{project}/locations/{location}/functions/{function}".format( + project=project, + location=location, + function=function, + ) + + @staticmethod + def parse_cloud_function_path(path: str) -> Dict[str, str]: + """Parses a cloud_function path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/functions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def location_path( project: str, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/filters.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/filters.py index a483093c4e55..2922f160cfc8 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/filters.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/filters.py @@ -367,11 +367,14 @@ class FileType(proto.Enum): Returns only folders. DOCUMENT (3): Returns only non-folder documents. + ROOT_FOLDER (4): + Returns only root folders """ FILE_TYPE_UNSPECIFIED = 0 ALL = 1 FOLDER = 2 DOCUMENT = 3 + ROOT_FOLDER = 4 file_type: FileType = proto.Field( proto.ENUM, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/pipelines.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/pipelines.py index 7c65f4eb33ae..ff98cfd91797 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/pipelines.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/types/pipelines.py @@ -272,6 +272,35 @@ class IngestPipelineConfig(proto.Message): Optional. The name of the folder to which all ingested documents will be linked during ingestion process. Format is ``projects/{project}/locations/{location}/documents/{folder_id}`` + cloud_function (str): + The Cloud Function resource name. The Cloud Function needs + to live inside consumer project and is accessible to + Document AI Warehouse P4SA. Only Cloud Functions V2 is + supported. Cloud function execution should complete within 5 + minutes or this file ingestion may fail due to timeout. + Format: + ``https://{region}-{project_id}.cloudfunctions.net/{cloud_function}`` + The following keys are available the request json payload. + + - display_name + - properties + - plain_text + - reference_id + - document_schema_name + - raw_document_path + - raw_document_file_type + + The following keys from the cloud function json response + payload will be ingested to the Document AI Warehouse as + part of Document proto content and/or related information. + The original values will be overridden if any key is present + in the response. + + - display_name + - properties + - plain_text + - document_acl_policy + - folder """ document_acl_policy: policy_pb2.Policy = proto.Field( @@ -287,6 +316,10 @@ class IngestPipelineConfig(proto.Message): proto.STRING, number=3, ) + cloud_function: str = proto.Field( + proto.STRING, + number=4, + ) class GcsIngestPipeline(proto.Message): diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py index 6357806aa392..9e7df33c573c 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py @@ -1812,9 +1812,35 @@ def test_pipeline_service_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_location_path(): +def test_cloud_function_path(): project = "squid" location = "clam" + function = "whelk" + expected = "projects/{project}/locations/{location}/functions/{function}".format( + project=project, + location=location, + function=function, + ) + actual = PipelineServiceClient.cloud_function_path(project, location, function) + assert expected == actual + + +def test_parse_cloud_function_path(): + expected = { + "project": "octopus", + "location": "oyster", + "function": "nudibranch", + } + path = PipelineServiceClient.cloud_function_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_cloud_function_path(path) + assert expected == actual + + +def test_location_path(): + project = "cuttlefish" + location = "mussel" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -1825,8 +1851,8 @@ def test_location_path(): def test_parse_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "winkle", + "location": "nautilus", } path = PipelineServiceClient.location_path(**expected) @@ -1836,7 +1862,7 @@ def test_parse_location_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "scallop" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1846,7 +1872,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "abalone", } path = PipelineServiceClient.common_billing_account_path(**expected) @@ -1856,7 +1882,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "squid" expected = "folders/{folder}".format( folder=folder, ) @@ -1866,7 +1892,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "clam", } path = PipelineServiceClient.common_folder_path(**expected) @@ -1876,7 +1902,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "whelk" expected = "organizations/{organization}".format( organization=organization, ) @@ -1886,7 +1912,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "octopus", } path = PipelineServiceClient.common_organization_path(**expected) @@ -1896,7 +1922,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "oyster" expected = "projects/{project}".format( project=project, ) @@ -1906,7 +1932,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "nudibranch", } path = PipelineServiceClient.common_project_path(**expected) @@ -1916,8 +1942,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "cuttlefish" + location = "mussel" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -1928,8 +1954,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "winkle", + "location": "nautilus", } path = PipelineServiceClient.common_location_path(**expected)