zscaler-sdk-python 1.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. zscaler/__init__.py +34 -0
  2. zscaler/cache/__init__.py +0 -0
  3. zscaler/cache/cache.py +105 -0
  4. zscaler/cache/no_op_cache.py +68 -0
  5. zscaler/cache/zscaler_cache.py +161 -0
  6. zscaler/constants.py +26 -0
  7. zscaler/errors/__init__.py +0 -0
  8. zscaler/errors/error.py +10 -0
  9. zscaler/errors/http_error.py +20 -0
  10. zscaler/errors/zscaler_api_error.py +24 -0
  11. zscaler/exceptions/__init__.py +1 -0
  12. zscaler/exceptions/exceptions.py +101 -0
  13. zscaler/logger.py +57 -0
  14. zscaler/ratelimiter/__init__.py +0 -0
  15. zscaler/ratelimiter/ratelimiter.py +39 -0
  16. zscaler/user_agent.py +23 -0
  17. zscaler/utils.py +577 -0
  18. zscaler/zia/__init__.py +657 -0
  19. zscaler/zia/activate.py +52 -0
  20. zscaler/zia/admin_and_role_management.py +344 -0
  21. zscaler/zia/apptotal.py +71 -0
  22. zscaler/zia/audit_logs.py +95 -0
  23. zscaler/zia/authentication_settings.py +98 -0
  24. zscaler/zia/client.py +88 -0
  25. zscaler/zia/cloud_apps.py +406 -0
  26. zscaler/zia/device_management.py +90 -0
  27. zscaler/zia/dlp.py +784 -0
  28. zscaler/zia/errors.py +37 -0
  29. zscaler/zia/firewall.py +1104 -0
  30. zscaler/zia/forwarding_control.py +271 -0
  31. zscaler/zia/isolation_profile.py +83 -0
  32. zscaler/zia/labels.py +180 -0
  33. zscaler/zia/locations.py +661 -0
  34. zscaler/zia/sandbox.py +180 -0
  35. zscaler/zia/security.py +236 -0
  36. zscaler/zia/ssl_inspection.py +175 -0
  37. zscaler/zia/traffic.py +853 -0
  38. zscaler/zia/url_categories.py +442 -0
  39. zscaler/zia/url_filtering.py +310 -0
  40. zscaler/zia/users.py +386 -0
  41. zscaler/zia/web_dlp.py +295 -0
  42. zscaler/zia/workload_groups.py +58 -0
  43. zscaler/zia/zpa_gateway.py +187 -0
  44. zscaler/zpa/__init__.py +683 -0
  45. zscaler/zpa/app_segments.py +331 -0
  46. zscaler/zpa/app_segments_inspection.py +311 -0
  47. zscaler/zpa/app_segments_pra.py +310 -0
  48. zscaler/zpa/certificates.py +234 -0
  49. zscaler/zpa/client.py +113 -0
  50. zscaler/zpa/cloud_connector_groups.py +75 -0
  51. zscaler/zpa/connectors.py +518 -0
  52. zscaler/zpa/emergency_access.py +178 -0
  53. zscaler/zpa/errors.py +37 -0
  54. zscaler/zpa/idp.py +83 -0
  55. zscaler/zpa/inspection.py +1012 -0
  56. zscaler/zpa/isolation_profile.py +85 -0
  57. zscaler/zpa/lss.py +568 -0
  58. zscaler/zpa/machine_groups.py +79 -0
  59. zscaler/zpa/policies.py +848 -0
  60. zscaler/zpa/posture_profiles.py +122 -0
  61. zscaler/zpa/privileged_remote_access.py +862 -0
  62. zscaler/zpa/provisioning.py +271 -0
  63. zscaler/zpa/saml_attributes.py +100 -0
  64. zscaler/zpa/scim_attributes.py +117 -0
  65. zscaler/zpa/scim_groups.py +146 -0
  66. zscaler/zpa/segment_groups.py +191 -0
  67. zscaler/zpa/server_groups.py +217 -0
  68. zscaler/zpa/servers.py +202 -0
  69. zscaler/zpa/service_edges.py +404 -0
  70. zscaler/zpa/trusted_networks.py +127 -0
  71. zscaler_sdk_python-1.0.0.dist-info/LICENSE.md +21 -0
  72. zscaler_sdk_python-1.0.0.dist-info/METADATA +59 -0
  73. zscaler_sdk_python-1.0.0.dist-info/RECORD +75 -0
  74. zscaler_sdk_python-1.0.0.dist-info/WHEEL +6 -0
  75. zscaler_sdk_python-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,178 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright (c) 2023, Zscaler Inc.
4
+ #
5
+ # Permission to use, copy, modify, and/or distribute this software for any
6
+ # purpose with or without fee is hereby granted, provided that the above
7
+ # copyright notice and this permission notice appear in all copies.
8
+ #
9
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
17
+
18
+ from box import Box
19
+ from requests import Response
20
+
21
+ from zscaler.utils import snake_to_camel
22
+ from zscaler.zpa.client import ZPAClient
23
+
24
+
25
+ class EmergencyAccessAPI:
26
+ def __init__(self, client: ZPAClient):
27
+ self.rest = client
28
+
29
+ def get_user(self, user_id: str) -> Box:
30
+ """
31
+ Returns information on the specified emergency access user.
32
+
33
+ Args:
34
+ portal_id (str):
35
+ The unique identifier for the emergency access user.
36
+
37
+ Returns:
38
+ :obj:`Box`: The resource record for the emergency access user.
39
+
40
+ Examples:
41
+ >>> pprint(zpa.emergency_access.get_user('99999'))
42
+
43
+ """
44
+ return self.rest.get(f"emergencyAccess/user/{user_id}")
45
+
46
+ def add_user(
47
+ self,
48
+ email_id: str,
49
+ first_name: str,
50
+ last_name: str,
51
+ user_id: str,
52
+ activate_now: bool = True,
53
+ **kwargs,
54
+ ) -> Box:
55
+ """
56
+ Add an emergency access user.
57
+
58
+ Args:
59
+ email_id (str): The email address of the emergency access user, as provided by the admin.
60
+ first_name (str): The first name of the emergency access user.
61
+ last_name (str): The last name of the emergency access user, as provided by the admin.
62
+ user_id (str): The unique identifier of the emergency access user.
63
+ activate_now (bool, optional): Indicates if the emergency access user is activated upon creation. Defaults to True.
64
+
65
+ **kwargs: Optional keyword args for additional attributes.
66
+
67
+ Returns:
68
+ :obj:`Box`: The resource record for the newly created user or an error message.
69
+
70
+ Examples:
71
+ >>> zpa.emergency_access.add_user(
72
+ ... email_id='user1Access@acme.com',
73
+ ... first_name='User1',
74
+ ... last_name='Access',
75
+ ... user_id='user1',
76
+ ... activate_now=True,
77
+ )
78
+ """
79
+ payload = {
80
+ "emailId": email_id,
81
+ "userId": user_id,
82
+ "firstName": first_name,
83
+ "lastName": last_name,
84
+ }
85
+
86
+ # Include any additional attributes passed via kwargs
87
+ for key, value in kwargs.items():
88
+ payload[snake_to_camel(key)] = value
89
+
90
+ # Append 'activateNow=true' to the URL query parameters if activate_now is True
91
+ query_params = {"activateNow": "true"} if activate_now else {}
92
+
93
+ response = self.rest.post(
94
+ "emergencyAccess/user", params=query_params, json=payload
95
+ )
96
+ if isinstance(response, Response):
97
+ # this is only true when the creation failed (status code is not 2xx)
98
+ status_code = response.status_code
99
+ # Handle error response
100
+ raise Exception(
101
+ f"API call failed with status {status_code}: {response.json()}"
102
+ )
103
+ return response
104
+
105
+ def update_user(self, user_id: str, **kwargs) -> Box:
106
+ """
107
+ Updates the specified emergency access user.
108
+
109
+ Args:
110
+ user_id (str): The unique identifier of the emergency access user.
111
+
112
+ Keyword Args:
113
+ email_id (str): The email address of the emergency access user, as provided by the admin.
114
+ first_name (str): The first name of the emergency access user.
115
+ last_name (str): The last name of the emergency access user, as provided by the admin.
116
+ user_id (str): The unique identifier of the emergency access user.
117
+
118
+ Returns:
119
+ Box: A Box object containing the details of the emergency access user.
120
+
121
+ Examples:
122
+ >>> zpa.emergency_access.update_user(
123
+ ... user_id='99999',
124
+ ... first_name='User1',
125
+ ... last_name='Access')
126
+ """
127
+ # Set payload to value of existing record
128
+ payload = {snake_to_camel(k): v for k, v in self.get_user(user_id).items()}
129
+
130
+ # Add optional parameters to payload
131
+ for key, value in kwargs.items():
132
+ payload[snake_to_camel(key)] = value
133
+
134
+ resp = self.rest.put(f"emergencyAccess/user/{user_id}", json=payload)
135
+ if not isinstance(resp, Response):
136
+ return self.get_user(user_id)
137
+
138
+ def activate_user(self, user_id: str, send_email: bool = False) -> Box:
139
+ """
140
+ Activates the emergency access user.
141
+
142
+ Args:
143
+ user_id (str): The unique identifier of the emergency access user to be activated.
144
+
145
+ Returns:
146
+
147
+ Examples:
148
+ >>> zpa.emergency_access.activate_user('99999', send_email=True)
149
+
150
+ """
151
+ query_params = {"sendEmail": "true"} if send_email else {}
152
+
153
+ response = self.rest.put(
154
+ f"emergencyAccess/user/{user_id}/activate", params=query_params
155
+ )
156
+ if response.status_code == 200:
157
+ return self.get_user(user_id)
158
+ else:
159
+ raise Exception(
160
+ f"API call failed with status {response.status_code}: {response.text}"
161
+ )
162
+
163
+ def deactivate_user(self, user_id: str) -> Box:
164
+ """
165
+ Deactivates the emergency access user.
166
+
167
+ Args:
168
+ user_id (str): The unique identifier of the emergency access user to be deactivated.
169
+
170
+ Returns:
171
+
172
+ Examples:
173
+ >>> zpa.emergency_access.deactivate_user('99999')
174
+
175
+ """
176
+ resp = self.rest.put(f"emergencyAccess/user/{user_id}/deactivate").status_code
177
+ if not isinstance(resp, Response):
178
+ return self.get_user(user_id)
zscaler/zpa/errors.py ADDED
@@ -0,0 +1,37 @@
1
+ # class Error:
2
+ # """
3
+ # Base Error Class
4
+ # """
5
+
6
+ # def __init__(self):
7
+ # self.message = ""
8
+
9
+ # def __repr__(self):
10
+ # return str({"message": self.message})
11
+
12
+
13
+ # class HTTPError(Error):
14
+ # def __init__(self, url, response, response_body):
15
+ # self.status = response.status_code
16
+ # self.url = url
17
+ # self.message = f"HTTP {self.status} {response_body}"
18
+
19
+
20
+ # class ZpaAPIError(Error):
21
+ # def __init__(self, url, response, response_body):
22
+ # self.status = response.status_code
23
+ # self.url = url
24
+ # self.response_body = response_body
25
+ # self.message = f"ZPA HTTP {self.status} " f"{self.response_body}\n"
26
+
27
+
28
+ # class ZpaBaseException(Exception):
29
+ # pass
30
+
31
+
32
+ # class HTTPException(ZpaBaseException):
33
+ # pass
34
+
35
+
36
+ # class ZpaAPIException(ZpaBaseException):
37
+ # pass
zscaler/zpa/idp.py ADDED
@@ -0,0 +1,83 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright (c) 2023, Zscaler Inc.
4
+ #
5
+ # Permission to use, copy, modify, and/or distribute this software for any
6
+ # purpose with or without fee is hereby granted, provided that the above
7
+ # copyright notice and this permission notice appear in all copies.
8
+ #
9
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
17
+
18
+ from box import Box, BoxList
19
+ from requests import Response
20
+
21
+ from zscaler.zpa.client import ZPAClient
22
+
23
+
24
+ class IDPControllerAPI:
25
+ def __init__(self, client: ZPAClient):
26
+ self.rest = client
27
+
28
+ def list_idps(self, **kwargs) -> BoxList:
29
+ """
30
+ Returns a list of all configured IdPs.
31
+
32
+ Keyword Args:
33
+ **max_items (int):
34
+ The maximum number of items to request before stopping iteration.
35
+ **max_pages (int):
36
+ The maximum number of pages to request before stopping iteration.
37
+ **pagesize (int):
38
+ Specifies the page size. The default size is 20, but the maximum size is 500.
39
+ **scim_enabled (bool):
40
+ Returns all SCIM IdPs if ``True``. Returns all non-SCIM IdPs if ``False``.
41
+ **search (str, optional):
42
+ The search string used to match against features and fields.
43
+
44
+ Returns:
45
+ :obj:`BoxList`: A list of all configured IdPs.
46
+
47
+ Examples:
48
+ >>> for idp in zpa.idp.list_idps():
49
+ ... pprint(idp)
50
+
51
+ """
52
+ list, _ = self.rest.get_paginated_data(path="/idp", **kwargs, api_version="v2")
53
+ return list
54
+
55
+ def get_idp_by_name(self, name):
56
+ idps = self.list_idps()
57
+ for idp in idps:
58
+ if idp.get("name") == name:
59
+ return idp
60
+ return None
61
+
62
+ def get_idp(self, idp_id: str) -> Box:
63
+ """
64
+ Returns information on the specified IdP.
65
+
66
+ Args:
67
+ idp_id (str):
68
+ The unique identifier for the IdP.
69
+
70
+ Returns:
71
+ :obj:`Box`: The resource record for the IdP.
72
+
73
+ Examples:
74
+ >>> pprint(zpa.idp.get_idp('99999'))
75
+
76
+ """
77
+
78
+ response = self.rest.get("/idp/%s" % (idp_id))
79
+ if isinstance(response, Response):
80
+ status_code = response.status_code
81
+ if status_code != 200:
82
+ return None
83
+ return response