Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -721,28 +721,34 @@ def get_ip_allowlist_policy(self, policy_id: str) -> CatalogIpAllowlistPolicy:
Returns:
CatalogIpAllowlistPolicy: Retrieved policy.
"""
response = self._entities_api.get_entity_ip_allowlist_policies(policy_id, _check_return_type=False)
response = self._entities_api.get_entity_ip_allowlist_policies(
policy_id, include=["users", "userGroups"], _check_return_type=False
)
return CatalogIpAllowlistPolicy.from_api(response.data)

def list_ip_allowlist_policies(self) -> list[CatalogIpAllowlistPolicy]:
"""Return all IP allowlist policies in the organization."""
get_policies = functools.partial(
self._entities_api.get_all_entities_ip_allowlist_policies, _check_return_type=False
self._entities_api.get_all_entities_ip_allowlist_policies,
include=["users", "userGroups"],
_check_return_type=False,
)
policies = load_all_entities(get_policies)
return [CatalogIpAllowlistPolicy.from_api(policy) for policy in policies.data]

def create_ip_allowlist_policy(self, policy: CatalogIpAllowlistPolicy) -> CatalogIpAllowlistPolicy:
"""Create a new IP allowlist policy."""
response = self._entities_api.create_entity_ip_allowlist_policies(
json_api_ip_allowlist_policy_in_document=policy.to_api(), _check_return_type=False
json_api_ip_allowlist_policy_in_document=policy.to_api(),
include=["users", "userGroups"],
_check_return_type=False,
)
return CatalogIpAllowlistPolicy.from_api(response.data)

def update_ip_allowlist_policy(self, policy: CatalogIpAllowlistPolicy) -> CatalogIpAllowlistPolicy:
"""Replace an existing IP allowlist policy."""
response = self._entities_api.update_entity_ip_allowlist_policies(
policy.id, policy.to_api(), _check_return_type=False
policy.id, policy.to_api(), include=["users", "userGroups"], _check_return_type=False
)
return CatalogIpAllowlistPolicy.from_api(response.data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ def test_ip_allowlist_policy_crud_methods_call_generated_client() -> None:
service.delete_ip_allowlist_policy("corp-vpn-only")

assert entities_api.get_entity_ip_allowlist_policies.call_args.args[0] == "corp-vpn-only"
# Relationship data is stripped unless explicitly requested via the JSON:API include param.
assert entities_api.get_entity_ip_allowlist_policies.call_args.kwargs["include"] == ["users", "userGroups"]
create_doc = entities_api.create_entity_ip_allowlist_policies.call_args.kwargs[
"json_api_ip_allowlist_policy_in_document"
]
assert create_doc.data.id == "corp-vpn-only"
assert entities_api.create_entity_ip_allowlist_policies.call_args.kwargs["include"] == ["users", "userGroups"]
assert entities_api.update_entity_ip_allowlist_policies.call_args.args[0] == "corp-vpn-only"
assert entities_api.update_entity_ip_allowlist_policies.call_args.kwargs["include"] == ["users", "userGroups"]
assert entities_api.delete_entity_ip_allowlist_policies.call_args.args[0] == "corp-vpn-only"


Expand All @@ -143,6 +147,7 @@ def test_list_ip_allowlist_policies_loads_all_entities() -> None:

assert [policy.id for policy in policies] == ["first", "second"]
assert entities_api.get_all_entities_ip_allowlist_policies.called
assert entities_api.get_all_entities_ip_allowlist_policies.call_args.kwargs["include"] == ["users", "userGroups"]


def test_ip_allowlist_target_actions_call_generated_client() -> None:
Expand Down
Loading