Skip to content

Commit

Permalink
fix: ZIA Pagination to support Cloud Apps parameters (#237)
Browse files Browse the repository at this point in the history
* fix: ZIA Pagination to support Cloud Apps parameters
  • Loading branch information
willguibr authored Jan 9, 2025
1 parent 94483d7 commit 6b9ffd6
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 223 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Zscaler Python SDK Changelog

## 0.10.4 (January,9 2024)

### Notes

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

### Bug Fix:

* ([#237](https://github.com/zscaler/zscaler-sdk-python/pull/237)) - Fixed pagination parameters on ZIA `cloud_apps` resource. Cloud Apps use the following parameters during pagination: `limit` and `page_number`.

## 0.10.3 (January,8 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.10.2"
version = "0.10.4"
# The full version, including alpha/beta/rc tags
release = "0.10.2"
release = "0.10.4"

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

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

## 0.10.4 (January,9 2024)

### Notes

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

### Bug Fix:

* Fixed pagination parameters on ZIA `cloud_apps` resource. Cloud Apps use the following parameters during pagination: `limit` and `page_number`. (`237 <https://github.com/zscaler/zscaler-sdk-python/pull/237>`_).

## 0.10.3 (January,8 2024)

### Notes
Expand Down
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.10.3"
version = "0.10.4"
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.10.3"
__version__ = "0.10.4"

from zscaler.zdx import ZDXClientHelper # noqa
from zscaler.zia import ZIAClientHelper # noqa
Expand Down
231 changes: 61 additions & 170 deletions zscaler/zia/__init__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zscaler/zia/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_paginated_data(
self,
path: str = None,
data_key_name: str = None,
data_per_page: int = 500,
data_per_page: int = 1000,
expected_status_code=200,
):
"""
Expand Down
11 changes: 9 additions & 2 deletions zscaler/zia/cloud_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,16 @@ def export_shadow_it_csv(self, application: str, entity: str, duration: str = "L

return self.rest.post(f"shadowIT/applications/{entity}/exportCsv", json=payload).text

def list_apps(self):
def list_apps(self, **kwargs):
"""
List all predefined and custom cloud applications by name and id.
Keyword Args:
**limit (int, optional):
Specifies the maximum number of cloud applications that must be retrieved in a page. The maximum size is 1000
**page_number (int, optional):
Specifies the page number. The numbering starts at 0.
Returns:
:obj:`BoxList` of :obj:`Box`: A list of cloud applications.
Expand All @@ -382,7 +388,8 @@ def list_apps(self):
print(app.name)
"""
return self.rest.get("cloudApplications/lite")
list, _ = self.rest.get_paginated_data(path="/cloudApplications/lite", **kwargs)
return list

def list_custom_tags(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions zscaler/zia/isolation_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

from box import BoxList

from zscaler.utils import snake_to_camel
from zscaler.zia.client import ZIAClient


class IsolationProfileAPI:
def __init__(self, client: ZIAClient):
self.rest = client

def list_isolation_profiles(self, **kwargs) -> BoxList:
def list_isolation_profiles(self) -> BoxList:
"""
Returns a list of all profiles in the Isolation Profile field for URL Filtering rules and Cloud App Control rules.
Expand Down
8 changes: 3 additions & 5 deletions zscaler/zia/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ def list_labels(self, **kwargs) -> BoxList:
Returns the list of ZIA Rule Labels.
Keyword Args:
**max_items (int, optional):
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**page_size (int, optional):
**page (int, optional):
Specifies the page offset.
**pagesize (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 1000.
Returns:
Expand Down
26 changes: 12 additions & 14 deletions zscaler/zia/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def list_locations(self, **kwargs) -> BoxList:
Filter based on whether the Enforce Authentication setting is enabled or disabled for a location.
**bw_enforced (bool, optional):
Filter based on whether Bandwith Control is being enforced for a location.
**max_items (int, optional):
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**page_size (int, optional):
**page (int, optional):
Specifies the page offset.
**pagesize (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 1000.
**search (str, optional):
The search string used to partially match against a location's name and port attributes.
Expand All @@ -60,7 +58,7 @@ def list_locations(self, **kwargs) -> BoxList:
List locations, returning 200 items per page for a maximum of 2 pages:
>>> for location in zia.locations.list_locations(page_size=200, max_pages=2):
>>> for location in zia.locations.list_locations(pagesize=200, max_pages=2):
... print(location)
"""
Expand Down Expand Up @@ -243,7 +241,7 @@ def list_sub_locations(self, location_id: str, **kwargs) -> BoxList:
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**page_size (int, optional):
**pagesize (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 1000.
**search (str, optional):
The search string used to partially match against a location's name and port attributes.
Expand Down Expand Up @@ -274,7 +272,7 @@ def list_locations_lite(self, **kwargs) -> BoxList:
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**page_size (int, optional):
**pagesize (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 1000.
**search (str, optional):
The search string used to partially match against a location's name and port attributes.
Expand All @@ -295,7 +293,7 @@ def list_locations_lite(self, **kwargs) -> BoxList:
List locations, returning 200 items per page for a maximum of 2 pages:
>>> for location in zia.locations.list_locations_lite(page_size=200, max_pages=2):
>>> for location in zia.locations.list_locations_lite(pagesize=200, max_pages=2):
... print(location)
"""
Expand Down Expand Up @@ -518,7 +516,7 @@ def get_location_group_by_id(self, group_id: int) -> Box:
"""
return self.rest.get(f"locations/groups/{group_id}")

def list_location_groups_lite(self, page: int = 1, page_size: int = 100) -> BoxList:
def list_location_groups_lite(self, **kwargs) -> BoxList:
"""
Returns a list of location groups (lite version) by their ID where only name and ID is returned in ZIA.
Expand All @@ -535,8 +533,8 @@ def list_location_groups_lite(self, page: int = 1, page_size: int = 100) -> BoxL
Get a list of all configured location groups:
>>> location = zia.locations.list_location_groups_lite()
"""
params = {"page": page, "pageSize": page_size}
return self.rest.get("locations/groups/lite", params=params)
list, _ = self.rest.get_paginated_data(path="/locations/groups/lite", **kwargs)
return list

def get_location_group_lite_by_id(self, group_id: int) -> Box:
"""
Expand Down Expand Up @@ -633,12 +631,12 @@ def list_cities_by_name(self, **kwargs) -> BoxList:
country, postal code, etc.
Args:
**kwargs: Optional keyword arguments including 'prefix', 'page', and 'page_size'.
**kwargs: Optional keyword arguments including 'prefix', 'page', and 'pagesize'.
Keyword Args:
prefix (str): The prefix string to search for cities.
page (int): The page number of the results.
page_size (int): The number of results per page.
pagesize (int): The number of results per page.
Returns:
:obj:`BoxList`: The list of cities (along with their geographical data) that match the prefix search.
Expand Down
10 changes: 4 additions & 6 deletions zscaler/zia/pac_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ def list_pac_files(self, **kwargs) -> BoxList:
Returns the list of ZIA Pac Files.
Keyword Args:
**max_items (int, optional):
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**page_size (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 1000.
**filter (int, optional):
Retrieves the list of PAC files without the PAC file content in the response
**search (str, optional):
Returns PAC files with the names that match the search criteria
Returns:
:obj:`BoxList`: The list of PAC Files configured in ZIA.
Expand Down
14 changes: 7 additions & 7 deletions zscaler/zia/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def list_gre_tunnels(self, **kwargs) -> BoxList:
... print(tunnel)
"""
return BoxList(Iterator(self.rest, "greTunnels", **kwargs))
list, _ = self.rest.get_paginated_data(path="/greTunnels", **kwargs)
return list

def get_gre_tunnel(self, tunnel_id: str) -> Box:
"""
Expand Down Expand Up @@ -230,11 +231,9 @@ def list_vips(self, **kwargs) -> BoxList:
**include (str, optional):
Include all, private, or public VIPs in the list. Available choices are `all`, `private`, `public`.
Defaults to `public`.
**max_items (int, optional):
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**page_size (int, optional):
**page (int, optional):
Specifies the page offset.
**pagesize (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 1000.
**region (str, optional):
Filter based on region.
Expand All @@ -259,7 +258,8 @@ def list_vips(self, **kwargs) -> BoxList:
... print(vip)
"""
return BoxList(Iterator(self.rest, "vips", **kwargs))
list, _ = self.rest.get_paginated_data(path="/vips", **kwargs)
return list

def add_gre_tunnel(
self,
Expand Down
8 changes: 3 additions & 5 deletions zscaler/zia/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,11 @@ def list_users(self, **kwargs) -> BoxList:
Filters by department name. This is a `starts with` match.
**group (str, optional):
Filters by group name. This is a `starts with` match.
**max_items (int, optional):
The maximum number of items to request before stopping iteration.
**max_pages (int, optional):
The maximum number of pages to request before stopping iteration.
**name (str, optional):
Filters by user name. This is a `partial` match.
**page_size (int, optional):
**page (int, optional):
Specifies the page offset.
**pagesize (int, optional):
Specifies the page size. The default size is 100, but the maximum size is 10000.
**sort_by (str):
The field name to sort by, supported values: id, name, creationTime or modifiedTime (default to name)
Expand Down
6 changes: 2 additions & 4 deletions zscaler/zia/workload_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ def list_groups(self, **kwargs) -> BoxList:
... pprint(workloads)
"""
response = self.rest.get("/workloadGroups")
if isinstance(response, Response):
return None
return response
list, _ = self.rest.get_paginated_data(path="/workloadGroups", **kwargs)
return list

# Search Workload Group By Name
def get_group_by_name(self, name):
Expand Down
10 changes: 7 additions & 3 deletions zscaler/zia/zpa_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ def list_gateways(self, **kwargs) -> BoxList:
"""
Returns a list of all ZPA Gateways.
Returns:
:obj:`BoxList`: The list of all ZPA Gateways Items
Keyword Args:
**app_segment (list, optional):
Filters the list by Application Segment
**search (str, optional):
The search string used to match against a ZPA gateway name or an associated Server Group name
Returns:
:obj:`BoxList`: The list of all ZPA Gateways Items
Expand All @@ -42,7 +45,8 @@ def list_gateways(self, **kwargs) -> BoxList:
... for item in results:
... print(item)
"""
return self.rest.get("zpaGateways")
list, _ = self.rest.get_paginated_data(path="/zpaGateways", **kwargs)
return list

def get_gateway(self, gateway_id: str) -> Box:
"""
Expand Down

0 comments on commit 6b9ffd6

Please sign in to comment.