forked from mitchos/pyZscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/zdx' into develop
- Loading branch information
Showing
21 changed files
with
1,974 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
admin | ||
------ | ||
|
||
The following methods allow for interaction with the ZDX | ||
Admin API endpoints. | ||
|
||
Methods are accessible via ``zdx.admin`` | ||
|
||
.. _zdx-admin: | ||
|
||
.. automodule:: pyzscaler.zdx.admin | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apps | ||
------ | ||
|
||
The following methods allow for interaction with the ZDX | ||
Application API endpoints. | ||
|
||
Methods are accessible via ``zdx.apps`` | ||
|
||
.. _zdx-apps: | ||
|
||
.. automodule:: pyzscaler.zdx.apps | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
devices | ||
------- | ||
|
||
The following methods allow for interaction with the ZDX | ||
Devices API endpoints. | ||
|
||
Methods are accessible via ``zdx.devices`` | ||
|
||
.. _zdx-devices: | ||
|
||
.. automodule:: pyzscaler.zdx.devices | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ZDX | ||
========== | ||
This package covers the ZDX interface. | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
:hidden: | ||
|
||
* | ||
|
||
.. automodule:: pyzscaler.zdx | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
session | ||
------- | ||
|
||
The following methods allow for interaction with the ZDX | ||
Session API endpoints. | ||
|
||
Methods are accessible via ``zdx.session`` | ||
|
||
.. _zdx-session: | ||
|
||
.. automodule:: pyzscaler.zdx.session | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import os | ||
|
||
from box import Box | ||
from restfly.session import APISession | ||
|
||
from pyzscaler import __version__ | ||
from .admin import AdminAPI | ||
from .apps import AppsAPI | ||
from .devices import DevicesAPI | ||
from .session import SessionAPI | ||
from .users import UsersAPI | ||
|
||
|
||
class ZDX(APISession): | ||
""" | ||
A Controller to access Endpoints in the Zscaler Digital Experience (ZDX) API. | ||
The ZDX object stores the session token and simplifies access to CRUD options within the ZDX Portal. | ||
Attributes: | ||
client_id (str): The ZDX Client ID generated from the ZDX Portal. | ||
client_secret (str): The ZDX Client Secret generated from the ZDX Portal. | ||
cloud (str): The Zscaler cloud for your tenancy, accepted values are below. Defaults to ``zdxcloud``. | ||
* ``zdxcloud`` | ||
* ``zdxbeta`` | ||
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://. | ||
""" | ||
|
||
_vendor = "Zscaler" | ||
_product = "pyZscaler" | ||
_backoff = 3 | ||
_build = __version__ | ||
_box = True | ||
_box_attrs = {"camel_killer_box": True} | ||
_env_base = "ZDX" | ||
_env_cloud = "zdxcloud" | ||
_url = "https://api.zdxcloud.net/v1" | ||
|
||
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._env_cloud)) | ||
self._url = kw.get("override_url", os.getenv(f"{self._env_base}_OVERRIDE_URL")) or f"https://api.{self._cloud}.net/v1" | ||
self.conv_box = True | ||
super(ZDX, self).__init__(**kw) | ||
|
||
def _build_session(self, **kwargs) -> Box: | ||
"""Creates a ZCC API session.""" | ||
super(ZDX, self)._build_session(**kwargs) | ||
self._auth_token = self.session.create_token(client_id=self._client_id, client_secret=self._client_secret).token | ||
return self._session.headers.update({"Authorization": f"Bearer {self._auth_token}"}) | ||
|
||
@property | ||
def session(self): | ||
"""The interface object for the :ref:`ZDX Session interface <zdx-session>`.""" | ||
return SessionAPI(self) | ||
|
||
@property | ||
def admin(self): | ||
"""The interface object for the :ref:`ZDX Admin interface <zdx-admin>`.""" | ||
return AdminAPI(self) | ||
|
||
@property | ||
def apps(self): | ||
"""The interface object for the :ref:`ZDX Apps interface <zdx-apps>`.""" | ||
return AppsAPI(self) | ||
|
||
@property | ||
def devices(self): | ||
"""The interface object for the :ref:`ZDX Devices interface <zdx-devices>`.""" | ||
return DevicesAPI(self) | ||
|
||
@property | ||
def users(self): | ||
"""The interface object for the :ref:`ZDX Users interface <zdx-users>`.""" | ||
return UsersAPI(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from box import BoxList | ||
from restfly.endpoint import APIEndpoint | ||
|
||
from pyzscaler.utils import zdx_params | ||
|
||
|
||
class AdminAPI(APIEndpoint): | ||
@zdx_params | ||
def list_departments(self, **kwargs) -> BoxList: | ||
""" | ||
Returns a list of departments that are configured within ZDX. | ||
Keyword Args: | ||
since (int): The number of hours to look back for devices. | ||
search (str): The search string to filter by name or department ID. | ||
Returns: | ||
:obj:`BoxList`: The list of departments in ZDX. | ||
Examples: | ||
List all departments in ZDX for the past 2 hours | ||
>>> for department in zdx.admin.list_departments(): | ||
... print(department) | ||
""" | ||
|
||
return self._get("administration/departments", params=kwargs) | ||
|
||
@zdx_params | ||
def list_locations(self, **kwargs) -> BoxList: | ||
""" | ||
Returns a list of locations that are configured within ZDX. | ||
Keyword Args: | ||
since (int): The number of hours to look back for devices. | ||
search (str): The search string to filter by name or location ID. | ||
Returns: | ||
:obj:`BoxList`: The list of locations in ZDX. | ||
Examples: | ||
List all locations in ZDX for the past 2 hours | ||
>>> for location in zdx.admin.list_locations(): | ||
... print(location) | ||
""" | ||
return self._get("administration/locations", params=kwargs) | ||
|
||
@zdx_params | ||
def list_geolocations(self, **kwargs) -> BoxList: | ||
""" | ||
Returns a list of all active geolocations configured within the ZDX tenant. | ||
Keyword Args: | ||
since (int): The number of hours to look back for devices. | ||
location_id (str): The unique ID for the location. | ||
parent_geo_id (str): The unique ID for the parent geolocation. | ||
search (str): The search string to filter by name. | ||
Returns: | ||
:obj:`BoxList`: The list of geolocations in ZDX. | ||
Examples: | ||
List all geolocations in ZDX for the past 2 hours | ||
>>> for geolocation in zdx.admin.list_geolocations(): | ||
... print(geolocation) | ||
""" | ||
return self._get("active_geo", params=kwargs) |
Oops, something went wrong.