Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

feat: add inventory_path #283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions google/cloud/asset_v1/services/asset_service/async_client.py
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions google/cloud/asset_v1/services/asset_service/client.py
Expand Up @@ -200,6 +200,22 @@ def parse_feed_path(path: str) -> Dict[str, str]:
m = re.match(r"^projects/(?P<project>.+?)/feeds/(?P<feed>.+?)$", 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<project>.+?)/locations/(?P<location>.+?)/instances/(?P<instance>.+?)/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."""
Expand Down
56 changes: 40 additions & 16 deletions tests/unit/gapic/asset_v1/test_asset_service.py
Expand Up @@ -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,
)
Expand All @@ -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)

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

Expand All @@ -3878,15 +3902,15 @@ 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


def test_parse_common_folder_path():
expected = {
"folder": "nudibranch",
"folder": "abalone",
}
path = AssetServiceClient.common_folder_path(**expected)

Expand All @@ -3896,15 +3920,15 @@ 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


def test_parse_common_organization_path():
expected = {
"organization": "mussel",
"organization": "clam",
}
path = AssetServiceClient.common_organization_path(**expected)

Expand All @@ -3914,15 +3938,15 @@ 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


def test_parse_common_project_path():
expected = {
"project": "nautilus",
"project": "octopus",
}
path = AssetServiceClient.common_project_path(**expected)

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

Expand Down