Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchos committed Jul 13, 2022
2 parents 5adb1b5 + be712ba commit a8eec60
Show file tree
Hide file tree
Showing 10 changed files with 1,624 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
html_title = ""

# The short X.Y version
version = '1.2'
version = '1.3'
# The full version, including alpha/beta/rc tags
release = '1.2.1'
release = '1.3.0'

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

Expand Down
12 changes: 12 additions & 0 deletions docsrc/zs/zpa/inspection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inspection
---------------

The following methods allow for interaction with the ZPA
Inspection Controller API endpoints.

Methods are accessible via ``zpa.inspection``

.. _zpa-inspection:

.. automodule:: pyzscaler.zpa.inspection
:members:
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 = "pyzscaler"
version = "1.2.1"
version = "1.3.0"
description = "A python SDK for the Zscaler API."
authors = ["Mitch Kelly <me@mkelly.dev>"]
license = "MIT"
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__ = "1.2.1"
__version__ = "1.3.0"

from pyzscaler.zcc import ZCC # noqa
from pyzscaler.zia import ZIA # noqa
Expand Down
5 changes: 3 additions & 2 deletions pyzscaler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

def snake_to_camel(name: str):
"""Converts Python Snake Case to Zscaler's lower camelCase."""
if "_" not in name:
return name
# Edge-cases where camelCase is breaking
edge_cases = {
"routable_ip": "routableIP",
Expand All @@ -14,8 +16,7 @@ def snake_to_camel(name: str):
"surrogate_ip": "surrogateIP",
"surrogate_ip_enforced_for_known_browsers": "surrogateIPEnforcedForKnownBrowsers",
}
ret = edge_cases.get(name, name[0].lower() + name.title()[1:].replace("_", ""))
return ret
return edge_cases.get(name, name[0].lower() + name.title()[1:].replace("_", ""))


def chunker(lst, n):
Expand Down
19 changes: 19 additions & 0 deletions pyzscaler/zcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ class ZCC(APISession):
Attributes:
client_id (str): The ZCC Client ID generated from the ZCC Portal.
client_secret (str): The ZCC Client Secret generated from the ZCC Portal.
cloud (str): The Zscaler cloud for your tenancy, accepted values are:
* ``zscaler``
* ``zscalerone``
* ``zscalertwo``
* ``zscalerthree``
* ``zscloud``
* ``zscalerbeta``
company_id (str):
The ZCC Company ID. There seems to be no easy way to obtain this at present. See the note
at the top of this page for information on how to retrieve the Company ID.
override_url (str):
If supplied, this attribute can be used to override the production URL that is derived
from supplying the `cloud` attribute. Use this attribute if you have a non-standard tenant URL
(e.g. internal test instance etc). When using this attribute, there is no need to supply the `cloud`
attribute. The override URL will be prepended to the API endpoint suffixes. The protocol must be included
i.e. http:// or https://.
"""

Expand All @@ -38,6 +52,11 @@ class ZCC(APISession):
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._cloud = kw.get("cloud", os.getenv(f"{self._env_base}_CLOUD"))
self._url = (
kw.get("override_url", os.getenv(f"{self._env_base}_OVERRIDE_URL"))
or f"https://api-mobile.{self._env_cloud}.net/papi"
)
self.company_id = kw.get("company_id", os.getenv(f"{self._env_base}_COMPANY_ID"))
self.conv_box = True
super(ZCC, self).__init__(**kw)
Expand Down
19 changes: 18 additions & 1 deletion pyzscaler/zia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ class ZIA(APISession):
api_key (str): The ZIA API key generated from the ZIA console.
username (str): The ZIA administrator username.
password (str): The ZIA administrator password.
cloud (str): The Zscaler cloud for your tenancy, accepted values are:
* ``zscaler``
* ``zscalerone``
* ``zscalertwo``
* ``zscalerthree``
* ``zscloud``
* ``zscalerbeta``
override_url (str):
If supplied, this attribute can be used to override the production URL that is derived
from supplying the `cloud` attribute. Use this attribute if you have a non-standard tenant URL
(e.g. internal test instance etc). When using this attribute, there is no need to supply the `cloud`
attribute. The override URL will be prepended to the API endpoint suffixes. The protocol must be included
i.e. http:// or https://.
"""

Expand All @@ -51,7 +65,10 @@ def __init__(self, **kw):
self._username = kw.get("username", os.getenv(f"{self._env_base}_USERNAME"))
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._url = (
kw.get("override_url", os.getenv(f"{self._env_base}_OVERRIDE_URL"))
or f"https://zsapi.{self._env_cloud}.net/api/v1"
)
self.conv_box = True
super(ZIA, self).__init__(**kw)

Expand Down
49 changes: 42 additions & 7 deletions pyzscaler/zpa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyzscaler.zpa.connector_groups import ConnectorGroupsAPI
from pyzscaler.zpa.connectors import ConnectorsAPI
from pyzscaler.zpa.idp import IDPControllerAPI
from pyzscaler.zpa.inspection import InspectionControllerAPI
from pyzscaler.zpa.lss import LSSConfigControllerAPI
from pyzscaler.zpa.machine_groups import MachineGroupsAPI
from pyzscaler.zpa.policies import PolicySetsAPI
Expand All @@ -31,9 +32,21 @@ class ZPA(APISession):
The ZPA object stores the session token and simplifies access to API interfaces within ZPA.
Attributes:
_client_id (str): The ZPA API client ID generated from the ZPA console.
_client_secret (str): The ZPA API client secret generated from the ZPA console.
_customer_id (str): The ZPA tenant ID found in the Administration > Company menu in the ZPA console.
client_id (str): The ZPA API client ID generated from the ZPA console.
client_secret (str): The ZPA API client secret generated from the ZPA console.
customer_id (str): The ZPA tenant ID found in the Administration > Company menu in the ZPA console.
cloud (str): The Zscaler cloud for your tenancy, accepted values are:
* ``production``
* ``beta``
Defaults to ``production``.
override_url (str):
If supplied, this attribute can be used to override the production URL that is derived
from supplying the `cloud` attribute. Use this attribute if you have a non-standard tenant URL
(e.g. internal test instance etc). When using this attribute, there is no need to supply the `cloud`
attribute. The override URL will be prepended to the API endpoint suffixes. The protocol must be included
i.e. http:// or https://.
"""

Expand All @@ -49,17 +62,31 @@ 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"))
# The v2 URL supports additional API endpoints
self.v2_url = f"https://config.private.zscaler.com/mgmtconfig/v2/admin/customers/{self._customer_id}"
self.user_config_url = f"https://config.private.zscaler.com/userconfig/v1/customers/{self._customer_id}"
self._cloud = kw.get("cloud", os.getenv(f"{self._env_base}_CLOUD"))
self._override_url = kw.get("override_url", os.getenv(f"{self._env_base}_OVERRIDE_URL"))
self.conv_box = True
super(ZPA, self).__init__(**kw)

def _build_session(self, **kwargs) -> None:
"""Creates a ZPA API authenticated session."""
super(ZPA, self)._build_session(**kwargs)

self._url = f"https://config.private.zscaler.com/mgmtconfig/v1/admin/customers/{self._customer_id}"
# Configure URL base for this API session
if self._override_url:
self._url_base = self._override_url
elif not self._cloud or self._cloud == "production":
self._url_base = "https://config.private.zscaler.com"
elif self._cloud == "beta":
self._url_base = "https://config.zpabeta.net"
else:
raise ValueError("Missing Attribute: You must specify either cloud or override_url")

# Configure URLs for this API session
self._url = f"{self._url_base}/mgmtconfig/v1/admin/customers/{self._customer_id}"
self.user_config_url = f"{self._url_base}/userconfig/v1/customers/{self._customer_id}"
# The v2 URL supports additional API endpoints
self.v2_url = f"{self._url_base}/mgmtconfig/v2/admin/customers/{self._customer_id}"

self._auth_token = self.session.create_token(client_id=self._client_id, client_secret=self._client_secret)
return self._session.headers.update({"Authorization": f"Bearer {self._auth_token}"})

Expand Down Expand Up @@ -111,6 +138,14 @@ def idp(self):
"""
return IDPControllerAPI(self)

@property
def inspection(self):
"""
The interface object for the :ref:`ZPA Inspection interface <zpa-inspection>`.
"""
return InspectionControllerAPI(self)

@property
def lss(self):
"""
Expand Down
Loading

0 comments on commit a8eec60

Please sign in to comment.