Skip to content

Commit

Permalink
feat: add ROOT_FOLDER field to Document Warehouse API v1 (#11660)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

BEGIN_COMMIT_OVERRIDE
feat: add `cloud_function`fields to support new ingestion option in
Document Warehouse API v1
feat: add `ROOT_FOLDER` field to Document Warehouse API v1
END_COMMIT_OVERRIDE


PiperOrigin-RevId: 566393178

Source-Link:
googleapis/googleapis@c7c2ce2

Source-Link:
googleapis/googleapis-gen@b24ddfe
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWNvbnRlbnR3YXJlaG91c2UvLk93bEJvdC55YW1sIiwiaCI6ImIyNGRkZmVjODM1MmUwNWMxNzAyMTU5ZTE4OTQxOTRmNmQ1ZWY4NDUifQ==

---------

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] authored Sep 19, 2023
1 parent 77c7f3c commit 61a2c29
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<project>.+?)/locations/(?P<location>.+?)/functions/(?P<function>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def location_path(
project: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand All @@ -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,
)
Expand All @@ -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)

Expand All @@ -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,
)
Expand All @@ -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)

Expand All @@ -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,
)
Expand All @@ -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)

Expand All @@ -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,
)
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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)

Expand Down

0 comments on commit 61a2c29

Please sign in to comment.