Skip to content

Commit

Permalink
fix: Fixed ZPA App Connector Bulk functions and ZIA location Manageme…
Browse files Browse the repository at this point in the history
…nt (#182)

* fix: Fixed ZPA Connectors and ServiceEdge Bulk Functions and ZIA Locations

* fix: Fixed location management functions
  • Loading branch information
willguibr authored Oct 9, 2024
1 parent 432e1a1 commit d66ebb5
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 511 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Zscaler Python SDK Changelog

## 0.9.5 (October, 9 2024)

### Notes

- Python Versions: **v3.8, v3.9, v3.10, v3.11**

### Bug Fixes

* Fixed ZPA App Connector and Service Edge Bulk Delete functions due to return error ([#182](https://github.com/zscaler/zscaler-sdk-python/pull/182))
* Deprecated the ZIA function `get_location_group_by_name`. Users must use Use `list_location_groups(name=group_name)` instead going forward. ([#182](https://github.com/zscaler/zscaler-sdk-python/pull/182))

## 0.9.4 (October, 3 2024)

### Notes
Expand Down
4 changes: 2 additions & 2 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
html_title = ""

# The short X.Y version
version = "0.9.4"
version = "0.9.5"
# The full version, including alpha/beta/rc tags
release = "0.9.4"
release = "0.9.5"

# -- General configuration ---------------------------------------------------

Expand Down
13 changes: 13 additions & 0 deletions docsrc/zs/guides/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ Release Notes
Zscaler Python SDK Changelog
----------------------------

0.9.5 (October, 9 2024)
------------------------

Notes
^^^^^

- Python Versions: **v3.8, v3.9, v3.10, v3.11**

### Bug Fixes

* Fixed ZPA App Connector and Service Edge Bulk Delete functions due to return error (`182 <https://github.com/zscaler/zscaler-sdk-python/pull/182>`_)
* Deprecated the ZIA function `get_location_group_by_name`. Users must use Use `list_location_groups(name=group_name)` instead going forward. (`182 <https://github.com/zscaler/zscaler-sdk-python/pull/182>`_)

0.9.4 (October, 3 2024)
------------------------

Expand Down
1,036 changes: 576 additions & 460 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zscaler-sdk-python"
version = "0.9.4"
version = "0.9.5"
description = "Official Python SDK for the Zscaler Products (Beta)"
authors = ["Zscaler, Inc. <devrel@zscaler.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion zscaler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
__contributors__ = [
"William Guilherme",
]
__version__ = "0.9.4"
__version__ = "0.9.5"

from zscaler.zdx import ZDXClientHelper # noqa
from zscaler.zia import ZIAClientHelper # noqa
Expand Down
61 changes: 17 additions & 44 deletions zscaler/zia/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,19 @@ def bulk_delete_locations(self, location_ids: list, **kwargs) -> int:
raise Exception(f"API call failed with status {status_code}: {response.json()}")
return response

def list_location_groups(self) -> BoxList:
def list_location_groups(self, **kwargs) -> BoxList:
"""
Return a list of location groups in ZIA.
Args:
**kwargs: Optional keyword args.
Keyword Args:
groupType (str): The location group's type (i.e., Static or Dynamic).
name (str): The location group's name.
comments (str): Additional comments or information about the location group.
groupType (str): The location group's type (i.e., STATIC_GROUP or DYNAMIC_GROUP).
location_id (int): The unique identifier for a location within a location group.
last_mod_user (str): The admin who modified the location group last.
Returns:
:obj:`BoxList`: A list of location group resource records.
Expand All @@ -499,7 +503,14 @@ def list_location_groups(self) -> BoxList:
Get a list of all configured location groups:
>>> location = zia.locations.list_location_groups()
"""
return self.rest.get("locations/groups")
return BoxList(
Iterator(
self.rest,
f"locations/groups",
max_pages=1,
**kwargs,
)
)

def get_location_group_by_id(self, group_id: int) -> Box:
"""
Expand All @@ -517,25 +528,6 @@ def get_location_group_by_id(self, group_id: int) -> Box:
"""
return self.rest.get(f"locations/groups/{group_id}")

def get_location_group_by_name(self, group_name: str, page: int = 1, page_size: int = 100) -> Box:
"""
Return a specific location group by its name in ZIA.
Args:
group_name (str): The name of the location group.
page (int, optional): Page number to retrieve. Defaults to 1.
page_size (int, optional): Number of records per page. Defaults to 100.
Returns:
:obj:`Box`: A location group resource record.
Examples:
Get a specific location group by its name:
>>> location = zia.locations.get_location_group_by_name("Unassigned Locations")
"""
params = {"page": page, "pageSize": page_size, "search": group_name}
return self.rest.get("locations/groups", params=params)

def list_location_groups_lite(self, page: int = 1, page_size: int = 100) -> BoxList:
"""
Returns a list of location groups (lite version) by their ID where only name and ID is returned in ZIA.
Expand All @@ -544,7 +536,7 @@ def list_location_groups_lite(self, page: int = 1, page_size: int = 100) -> BoxL
**kwargs: Optional keyword args.
Keyword Args:
groupType (str): The location group's type (i.e., Static or Dynamic).
groupType (str): The location group's type (i.e., STATIC_GROUP or DYNAMIC_GROUP).
Returns:
:obj:`BoxList`: A list of location group resource records.
Expand Down Expand Up @@ -572,25 +564,6 @@ def get_location_group_lite_by_id(self, group_id: int) -> Box:
"""
return self.rest.get(f"locations/groups/lite/{group_id}")

def get_location_group_lite_by_name(self, group_name: str, page: int = 1, page_size: int = 100) -> BoxList:
"""
Return specific location groups (lite version) by their name where only name and ID is returned in ZIA.
Args:
group_name (str): The name of the location group.
page (int, optional): Page number to retrieve. Defaults to 1.
page_size (int, optional): Number of records per page. Defaults to 100.
Returns:
:obj:`BoxList`: A list of location group resource records with only ID and name.
Examples:
Get specific location groups (lite version) by name:
>>> locations = zia.locations.get_location_group_lite_by_name("Unassigned Locations")
"""
params = {"page": page, "pageSize": page_size, "search": group_name}
return self.rest.get("locations/groups/lite", params=params)

def list_location_groups_count(self, **kwargs) -> BoxList:
"""
Returns a list of location groups for your organization.
Expand All @@ -599,7 +572,7 @@ def list_location_groups_count(self, **kwargs) -> BoxList:
**kwargs: Optional keyword args.
Keyword Args:
group_type (str): The location group's type (i.e., Static or Dynamic).
group_type (str): The location group's type (i.e., STATIC_GROUP or DYNAMIC_GROUP).
last_mod_user (str): The admin who modified the location group last.
version (int): The version parameter is for Zscaler internal use only. Used by the service for backup operations.
name (str): The location group's name.
Expand All @@ -611,7 +584,7 @@ def list_location_groups_count(self, **kwargs) -> BoxList:
Examples:
Gets the list of location groups for your organization:
>>> location = zia.locations.list_location_groups_count(group_type='Static', name='Corporate')
>>> location = zia.locations.list_location_groups_count(group_type='STATIC_GROUP', name='Corporate')
"""
params = {}
optional_params = ["group_type", "last_mod_user", "version", "name", "comments", "location_id"]
Expand Down
13 changes: 11 additions & 2 deletions zscaler/zpa/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def delete_connector(self, connector_id: str, **kwargs) -> int:
params["microtenantId"] = kwargs.pop("microtenant_id")
return self.rest.delete(f"connector/{connector_id}", params=params).status_code

def bulk_delete_connectors(self, connector_ids: list, **kwargs) -> int:
def bulk_delete_connectors(self, connector_ids: list, **kwargs) -> Box:
"""
Deletes all specified App Connectors from ZPA.
Expand All @@ -177,7 +177,16 @@ def bulk_delete_connectors(self, connector_ids: list, **kwargs) -> int:
params = {}
if "microtenant_id" in kwargs:
params["microtenantId"] = kwargs.pop("microtenant_id")
return self.rest.post("connector/bulkDelete", json=payload)

response = self.rest.post("connector/bulkDelete", json=payload, params=params)

if isinstance(response, Response):
# Check for HTTP status and handle errors
if response.status_code != 200:
raise Exception(f"API call failed with status {response.status_code}: {response.json()}")

# If successful, return the response
return response

def list_connector_groups(self, **kwargs) -> BoxList:
"""
Expand Down
2 changes: 1 addition & 1 deletion zscaler/zpa/service_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def delete_service_edge(self, service_edge_id: str, **kwargs) -> int:
params["microtenantId"] = kwargs.pop("microtenant_id")
return self.rest.delete(f"serviceEdge/{service_edge_id}", params=params).status_code

def bulk_delete_service_edges(self, service_edge_ids: list, **kwargs) -> int:
def bulk_delete_service_edges(self, service_edge_ids: list, **kwargs) -> Box:
"""
Bulk deletes the specified Service Edges from ZPA.
Expand Down

0 comments on commit d66ebb5

Please sign in to comment.