From fbb47e6487fe454ca84d2415cf756a87bf66739f Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 3 Sep 2021 22:06:13 +0000 Subject: [PATCH] feat: add inventory_path (#283) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 394704298 Source-Link: https://github.com/googleapis/googleapis/commit/31d2d3432d9a0b910d7858eab7720b63445f23b2 Source-Link: https://github.com/googleapis/googleapis-gen/commit/aa3ce0901f686a71b68e427c6bb7a611b151b540 --- .../services/asset_service/async_client.py | 2 + .../asset_v1/services/asset_service/client.py | 16 ++++++ .../unit/gapic/asset_v1/test_asset_service.py | 56 +++++++++++++------ 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/google/cloud/asset_v1/services/asset_service/async_client.py b/google/cloud/asset_v1/services/asset_service/async_client.py index c05e2b8f..cac62725 100644 --- a/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1/services/asset_service/async_client.py @@ -53,6 +53,8 @@ class AssetServiceAsyncClient: feed_path = staticmethod(AssetServiceClient.feed_path) parse_feed_path = staticmethod(AssetServiceClient.parse_feed_path) + inventory_path = staticmethod(AssetServiceClient.inventory_path) + parse_inventory_path = staticmethod(AssetServiceClient.parse_inventory_path) service_perimeter_path = staticmethod(AssetServiceClient.service_perimeter_path) parse_service_perimeter_path = staticmethod( AssetServiceClient.parse_service_perimeter_path diff --git a/google/cloud/asset_v1/services/asset_service/client.py b/google/cloud/asset_v1/services/asset_service/client.py index 49638798..9e411187 100644 --- a/google/cloud/asset_v1/services/asset_service/client.py +++ b/google/cloud/asset_v1/services/asset_service/client.py @@ -200,6 +200,22 @@ def parse_feed_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/feeds/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def inventory_path(project: str, location: str, instance: str,) -> str: + """Returns a fully-qualified inventory string.""" + return "projects/{project}/locations/{location}/instances/{instance}/inventory".format( + project=project, location=location, instance=instance, + ) + + @staticmethod + def parse_inventory_path(path: str) -> Dict[str, str]: + """Parses a inventory path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/instances/(?P.+?)/inventory$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def service_perimeter_path(access_policy: str, service_perimeter: str,) -> str: """Returns a fully-qualified service_perimeter string.""" diff --git a/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/unit/gapic/asset_v1/test_asset_service.py index 8eb6e5fe..2037c805 100644 --- a/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1/test_asset_service.py @@ -3835,9 +3835,33 @@ def test_parse_feed_path(): assert expected == actual +def test_inventory_path(): + project = "scallop" + location = "abalone" + instance = "squid" + expected = "projects/{project}/locations/{location}/instances/{instance}/inventory".format( + project=project, location=location, instance=instance, + ) + actual = AssetServiceClient.inventory_path(project, location, instance) + assert expected == actual + + +def test_parse_inventory_path(): + expected = { + "project": "clam", + "location": "whelk", + "instance": "octopus", + } + path = AssetServiceClient.inventory_path(**expected) + + # Check that the path construction is reversible. + actual = AssetServiceClient.parse_inventory_path(path) + assert expected == actual + + def test_service_perimeter_path(): - access_policy = "scallop" - service_perimeter = "abalone" + access_policy = "oyster" + service_perimeter = "nudibranch" expected = "accessPolicies/{access_policy}/servicePerimeters/{service_perimeter}".format( access_policy=access_policy, service_perimeter=service_perimeter, ) @@ -3847,8 +3871,8 @@ def test_service_perimeter_path(): def test_parse_service_perimeter_path(): expected = { - "access_policy": "squid", - "service_perimeter": "clam", + "access_policy": "cuttlefish", + "service_perimeter": "mussel", } path = AssetServiceClient.service_perimeter_path(**expected) @@ -3858,7 +3882,7 @@ def test_parse_service_perimeter_path(): def test_common_billing_account_path(): - billing_account = "whelk" + billing_account = "winkle" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3868,7 +3892,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "octopus", + "billing_account": "nautilus", } path = AssetServiceClient.common_billing_account_path(**expected) @@ -3878,7 +3902,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "oyster" + folder = "scallop" expected = "folders/{folder}".format(folder=folder,) actual = AssetServiceClient.common_folder_path(folder) assert expected == actual @@ -3886,7 +3910,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "nudibranch", + "folder": "abalone", } path = AssetServiceClient.common_folder_path(**expected) @@ -3896,7 +3920,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "cuttlefish" + organization = "squid" expected = "organizations/{organization}".format(organization=organization,) actual = AssetServiceClient.common_organization_path(organization) assert expected == actual @@ -3904,7 +3928,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "mussel", + "organization": "clam", } path = AssetServiceClient.common_organization_path(**expected) @@ -3914,7 +3938,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "winkle" + project = "whelk" expected = "projects/{project}".format(project=project,) actual = AssetServiceClient.common_project_path(project) assert expected == actual @@ -3922,7 +3946,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "nautilus", + "project": "octopus", } path = AssetServiceClient.common_project_path(**expected) @@ -3932,8 +3956,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "scallop" - location = "abalone" + project = "oyster" + location = "nudibranch" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3943,8 +3967,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "squid", - "location": "clam", + "project": "cuttlefish", + "location": "mussel", } path = AssetServiceClient.common_location_path(**expected)