Skip to content

Commit

Permalink
Merge branch 'release/0.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchos committed Nov 12, 2021
2 parents 9c310ef + 01067c6 commit c39d03a
Show file tree
Hide file tree
Showing 47 changed files with 1,260 additions and 112 deletions.
4 changes: 2 additions & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sphinx==4.2.0
restfly==1.4.3
sphinx==4.3.0
restfly==1.4.4
python-box==5.4.1
furo==2021.10.9
pre-commit==2.15.0
Expand Down
5 changes: 2 additions & 3 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#
import os
import sys
from pyzscaler import __version__

sys.path.insert(0, os.path.abspath(".."))

Expand All @@ -26,9 +25,9 @@
html_title = ""

# The short X.Y version
version = '.'.join(__version__.split('.')[:2])
version = '0.12'
# The full version, including alpha/beta/rc tags
release = __version__
release = '0.12.0'

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

Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyzscaler"
version = "0.11.0"
version = "0.12.0"
description = "A python SDK for the Zscaler API."
authors = ["Mitch Kelly <me@mkelly.dev>"]
license = "MIT"
Expand Down Expand Up @@ -29,14 +29,14 @@ include = [

[tool.poetry.dependencies]
python = "^3.6.1"
restfly = "1.4.3"
restfly = "1.4.4"
python-box = "5.4.1"

[tool.poetry.dev-dependencies]
python = "^3.6.1"
restfly = "1.4.3"
restfly = "1.4.4"
python-box = "5.4.1"
Sphinx = "4.2.0"
Sphinx = "4.3.0"
furo = "2021.10.9"
pytest = "6.2.5"
requests = "2.26.0"
Expand Down
2 changes: 1 addition & 1 deletion pyzscaler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Dax Mickelson",
"Jacob Gårder",
]
__version__ = "0.11.0"
__version__ = "0.12.0"

from pyzscaler.zia import ZIA # noqa
from pyzscaler.zpa import ZPA # noqa
19 changes: 15 additions & 4 deletions pyzscaler/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time

from box import BoxList
from restfly import APIIterator


Expand Down Expand Up @@ -51,13 +50,25 @@ def __init__(self, api, path: str = "", **kw):
self.max_pages = kw.pop("max_pages", 0)
self.payload = {}
if kw:

self.payload = {snake_to_camel(key): value for key, value in kw.items()}

def _get_page(self) -> None:
"""Iterator function to get the page."""
self.page = self._api.get(
resp = self._api.get(
self.path,
params={**self.payload, "page": self.num_pages + 1},
box=BoxList,
)
try:
# If we are using ZPA then the API will return records under the
# 'list' key.
self.page = resp.get("list") or []
except AttributeError:
# If the list key doesn't exist then we're likely using ZIA so just
# return the full response.
self.page = resp
finally:
# If we use the default retry-after logic in Restfly then we are
# going to keep seeing 429 messages in stdout. ZIA and ZPA have a
# standard 1 sec rate limit on the API endpoints with pagination so
# we are going to include it here.
time.sleep(1)
1 change: 1 addition & 0 deletions pyzscaler/zia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, **kw):
self._password = kw.get("password", os.getenv(f"{self._env_base}_PASSWORD"))
self._env_cloud = kw.get("cloud", os.getenv(f"{self._env_base}_CLOUD"))
self._url = f"https://zsapi.{self._env_cloud}.net/api/v1"
self.conv_box = True
super(ZIA, self).__init__(**kw)

def _build_session(self, **kwargs) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyzscaler/zia/admin_and_role_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def list_roles(self, **kwargs) -> BoxList:
"""
payload = {snake_to_camel(key): value for key, value in kwargs.items()}

return self._get("adminRoles/lite", params=payload, box=BoxList)
return self._get("adminRoles/lite", params=payload)

def get_user(self, user_id: str) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyzscaler/zia/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def get_report(self):
... fh.write(zia.audit_logs.get_report())
"""
return self._get("auditlogEntryReport/download", box=False).text
return self._get("auditlogEntryReport/download").text
3 changes: 1 addition & 2 deletions pyzscaler/zia/dlp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from box import BoxList
from restfly.endpoint import APIEndpoint

from pyzscaler.utils import snake_to_camel
Expand Down Expand Up @@ -223,7 +222,7 @@ def list_dicts(self, query: str = None):
"""
payload = {"search": query}
return self._get("dlpDictionaries", params=payload, box=BoxList)
return self._get("dlpDictionaries", params=payload)

def get_dict(self, dict_id: str):
"""
Expand Down
41 changes: 19 additions & 22 deletions pyzscaler/zia/firewall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from box import BoxList
from restfly.endpoint import APIEndpoint

from pyzscaler.utils import snake_to_camel
Expand Down Expand Up @@ -34,7 +33,7 @@ def list_rules(self):
... pprint(rule)
"""
return self._get("firewallFilteringRules", box=BoxList)
return self._get("firewallFilteringRules")

def add_rule(self, name: str, action: str, **kwargs):
"""
Expand Down Expand Up @@ -228,7 +227,7 @@ def list_ip_destination_groups(self, exclude_type: str = None):

payload = {"excludeType": exclude_type}

return self._get("ipDestinationGroups", params=payload, box=BoxList)
return self._get("ipDestinationGroups", params=payload)

def get_ip_destination_group(self, group_id: str):
"""
Expand Down Expand Up @@ -376,7 +375,7 @@ def list_ip_source_groups(self, search: str = None):

payload = {"search": search}

return self._get("ipSourceGroups", params=payload, box=BoxList)
return self._get("ipSourceGroups", params=payload)

def get_ip_source_group(self, group_id: str):
"""
Expand Down Expand Up @@ -493,7 +492,7 @@ def list_network_app_groups(self, search: str = None):
"""
payload = {"search": search}
return self._get("networkApplicationGroups", params=payload, box=BoxList)
return self._get("networkApplicationGroups", params=payload)

def get_network_app_group(self, group_id: str):
"""
Expand Down Expand Up @@ -528,7 +527,7 @@ def list_network_apps(self, search: str = None):
"""
payload = {"search": search}
return self._get("networkApplications", params=payload, box=BoxList)
return self._get("networkApplications", params=payload)

def get_network_app(self, app_id: str):
"""
Expand Down Expand Up @@ -564,7 +563,7 @@ def list_network_svc_groups(self, search: str = None):

payload = {"search": search}

return self._get("networkServiceGroups", params=payload, box=BoxList)
return self._get("networkServiceGroups", params=payload)

def get_network_svc_group(self, group_id: str):
"""
Expand Down Expand Up @@ -596,7 +595,7 @@ def delete_network_svc_group(self, group_id: str):
>>> zia.firewall.delete_network_svc_group('762398')
"""
return self._delete(f"networkServiceGroups/{group_id}")
return self._delete(f"networkServiceGroups/{group_id}", box=False).status_code

def add_network_svc_group(self, name: str, service_ids: list, description: str = None):
"""
Expand Down Expand Up @@ -646,7 +645,7 @@ def list_network_services(self, search: str = None, protocol: str = None):
"""
payload = {"search": search, "protocol": protocol}
return self._get("networkServices", params=payload, box=BoxList)
return self._get("networkServices", params=payload)

def get_network_service(self, service_id: str):
"""
Expand Down Expand Up @@ -732,10 +731,10 @@ def add_network_service(self, name: str, ports: list = None, **kwargs):
# Convert tuple list to dict and add to payload
if ports is not None:
for items in ports:
port_obj = {"start": items[2]}
if len(ports) == 4:
port_obj["end"] = items[3]
payload.setdefault(f"{items[0]}{items[1].title()}Ports", []).append(port_obj)
port_range = [{"start": items[2]}]
if len(items) == 4:
port_range.append({"end": items[3]})
payload.setdefault(f"{items[0]}{items[1].title()}Ports", []).extend(port_range)

# Add optional parameters to payload
for key, value in kwargs.items():
Expand Down Expand Up @@ -786,19 +785,17 @@ def update_network_service(self, service_id: str, ports: list = None, **kwargs):
"""
existing_service = self.get_network_service(service_id)
payload = {snake_to_camel(k): v for k, v in self.get_network_service(service_id).items()}

# Convert tuple list to dict and add to payload
if ports is not None:
payload = {}
# Clear existing ports and set new values
for items in ports:
port_obj = {"start": items[2]}
if len(ports) == 4:
port_obj["end"] = items[3]
payload.setdefault(f"{items[0]}{items[1].title()}Ports", []).append(port_obj)
else:
# Use existing values and convert back to camelCase
payload = {snake_to_camel(k): v for k, v in existing_service.items()}
port_key = f"{items[0]}{items[1].title()}Ports"
payload[port_key] = []
payload[port_key].append({"start": items[2]})
if len(items) == 4:
payload[port_key].append({"end": items[3]})

# Add optional parameters to payload
for key, value in kwargs.items():
Expand Down
2 changes: 1 addition & 1 deletion pyzscaler/zia/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_location(self, location_id: str = None, location_name: str = None):
>>> location = zia.locations.get_location_name(name='stockholm_office')
"""
if location_id and location_name:
raise ValueError("TOO MANY ARGUMENTS: Expected either a location_id or a location_name. Both were provided.")
raise ValueError("TOO MANY ARGUMENTS: Expected either location_id or location_name. Both were provided.")
elif location_name:
location = (record for record in self.list_locations(search=location_name) if record.name == location_name)
return next(location, None)
Expand Down
3 changes: 1 addition & 2 deletions pyzscaler/zia/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from box import BoxList
from restfly.endpoint import APIEndpoint


Expand All @@ -14,7 +13,7 @@ def get_quota(self):
>>> pprint(zia.sandbox.get_quota())
"""
return self._get("sandbox/report/quota", box=BoxList)[0]
return self._get("sandbox/report/quota")[0]

def get_report(self, md5_hash: str, report_details: str = "summary"):
"""
Expand Down
14 changes: 3 additions & 11 deletions pyzscaler/zia/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def erase_whitelist(self):
"""
payload = {"whitelistUrls": []}

return self._put("security", json=payload, box=False).status_code
return self._put("security", json=payload).status_code

def replace_whitelist(self, url_list: list):
"""
Expand Down Expand Up @@ -141,11 +141,7 @@ def add_urls_to_blacklist(self, url_list: list):

payload = {"blacklistUrls": url_list}

return self._post(
"security/advanced/blacklistUrls?action=ADD_TO_LIST",
json=payload,
box=False,
).status_code
return self._post("security/advanced/blacklistUrls?action=ADD_TO_LIST", json=payload).blacklist_urls

def replace_blacklist(self, url_list: list):
"""
Expand Down Expand Up @@ -201,8 +197,4 @@ def delete_urls_from_blacklist(self, url_list: list):

payload = {"blacklistUrls": url_list}

return self._post(
"security/advanced/blacklistUrls?action=REMOVE_FROM_LIST",
json=payload,
box=False,
).status_code
return self._post("security/advanced/blacklistUrls?action=REMOVE_FROM_LIST", json=payload, box=False).status_code
2 changes: 1 addition & 1 deletion pyzscaler/zia/ssl_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_csr(self):
>>> csr = zia.ssl.get_csr()
"""
return self._get("sslSettings/downloadcsr", box=False).text
return self._get("sslSettings/downloadcsr").text

def get_intermediate_ca(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions pyzscaler/zia/traffic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from box import BoxList
from restfly.endpoint import APIEndpoint

from pyzscaler.utils import Iterator, snake_to_camel
Expand Down Expand Up @@ -77,7 +76,7 @@ def list_gre_ranges(self, **kwargs):
"""
payload = {snake_to_camel(key): value for key, value in kwargs.items()}

return self._get("greTunnels/availableInternalIpRanges", params=payload, box=BoxList)
return self._get("greTunnels/availableInternalIpRanges", params=payload)

def add_gre_tunnel(
self,
Expand Down Expand Up @@ -439,7 +438,7 @@ def list_vips_recommended(self, **kwargs):
"""
payload = {snake_to_camel(key): value for key, value in kwargs.items()}

return self._get("vips/recommendedList", params=payload, box=BoxList)
return self._get("vips/recommendedList", params=payload)

def get_closest_diverse_vip_ids(self, ip_address: str):
"""
Expand Down
5 changes: 2 additions & 3 deletions pyzscaler/zia/url_categories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from box import BoxList
from restfly.endpoint import APIEndpoint

from pyzscaler.utils import snake_to_camel
Expand All @@ -22,7 +21,7 @@ def lookup(self, urls: list):
"""
payload = urls

return self._post("urlLookup", json=payload, box=BoxList)
return self._post("urlLookup", json=payload)

def list_categories(self, custom_only: bool = False):
"""
Expand All @@ -46,7 +45,7 @@ def list_categories(self, custom_only: bool = False):
"""

return self._get(f"urlCategories?customOnly={custom_only}", box=BoxList)
return self._get(f"urlCategories?customOnly={custom_only}")

def get_quota(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions pyzscaler/zia/url_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from box import BoxList
from restfly.endpoint import APIEndpoint

from pyzscaler.utils import snake_to_camel
Expand Down Expand Up @@ -29,7 +28,7 @@ def list_rules(self):
... pprint(rule)
"""
return self._get("urlFilteringRules", box=BoxList)
return self._get("urlFilteringRules")

def get_rule(self, rule_id: str):
"""
Expand Down
1 change: 1 addition & 0 deletions pyzscaler/zpa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, **kw):
self._client_id = kw.get("client_id", os.getenv(f"{self._env_base}_CLIENT_ID"))
self._client_secret = kw.get("client_secret", os.getenv(f"{self._env_base}_CLIENT_SECRET"))
self._customer_id = kw.get("customer_id", os.getenv(f"{self._env_base}_CUSTOMER_ID"))
self.conv_box = True
super(ZPA, self).__init__(**kw)

def _build_session(self, **kwargs) -> None:
Expand Down
Loading

0 comments on commit c39d03a

Please sign in to comment.