zscaler-sdk-python 0.1.3__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 +35 -0
  2. zscaler/cache/__init__.py +0 -0
  3. zscaler/cache/cache.py +105 -0
  4. zscaler/cache/no_op_cache.py +66 -0
  5. zscaler/cache/zscaler_cache.py +159 -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 +21 -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 +37 -0
  16. zscaler/user_agent.py +21 -0
  17. zscaler/utils.py +546 -0
  18. zscaler/zia/__init__.py +629 -0
  19. zscaler/zia/activate.py +51 -0
  20. zscaler/zia/admin_and_role_management.py +336 -0
  21. zscaler/zia/apptotal.py +71 -0
  22. zscaler/zia/audit_logs.py +93 -0
  23. zscaler/zia/authentication_settings.py +94 -0
  24. zscaler/zia/client.py +88 -0
  25. zscaler/zia/cloud_apps.py +402 -0
  26. zscaler/zia/device_management.py +90 -0
  27. zscaler/zia/dlp.py +772 -0
  28. zscaler/zia/errors.py +37 -0
  29. zscaler/zia/firewall.py +1064 -0
  30. zscaler/zia/forwarding_control.py +267 -0
  31. zscaler/zia/isolation_profile.py +83 -0
  32. zscaler/zia/labels.py +178 -0
  33. zscaler/zia/locations.py +645 -0
  34. zscaler/zia/sandbox.py +201 -0
  35. zscaler/zia/security.py +232 -0
  36. zscaler/zia/ssl_inspection.py +169 -0
  37. zscaler/zia/traffic.py +819 -0
  38. zscaler/zia/url_categories.py +422 -0
  39. zscaler/zia/url_filtering.py +306 -0
  40. zscaler/zia/users.py +378 -0
  41. zscaler/zia/web_dlp.py +291 -0
  42. zscaler/zia/workload_groups.py +58 -0
  43. zscaler/zia/zpa_gateway.py +179 -0
  44. zscaler/zpa/README.md +40 -0
  45. zscaler/zpa/__init__.py +655 -0
  46. zscaler/zpa/app_segments.py +317 -0
  47. zscaler/zpa/app_segments_inspection.py +295 -0
  48. zscaler/zpa/app_segments_pra.py +296 -0
  49. zscaler/zpa/certificates.py +230 -0
  50. zscaler/zpa/client.py +113 -0
  51. zscaler/zpa/cloud_connector_groups.py +75 -0
  52. zscaler/zpa/connectors.py +500 -0
  53. zscaler/zpa/emergency_access.py +170 -0
  54. zscaler/zpa/errors.py +37 -0
  55. zscaler/zpa/idp.py +83 -0
  56. zscaler/zpa/inspection.py +968 -0
  57. zscaler/zpa/isolation_profile.py +85 -0
  58. zscaler/zpa/lss.py +544 -0
  59. zscaler/zpa/machine_groups.py +79 -0
  60. zscaler/zpa/policies.py +824 -0
  61. zscaler/zpa/posture_profiles.py +120 -0
  62. zscaler/zpa/privileged_remote_access.py +827 -0
  63. zscaler/zpa/provisioning.py +262 -0
  64. zscaler/zpa/saml_attributes.py +96 -0
  65. zscaler/zpa/scim_attributes.py +115 -0
  66. zscaler/zpa/scim_groups.py +133 -0
  67. zscaler/zpa/segment_groups.py +183 -0
  68. zscaler/zpa/server_groups.py +211 -0
  69. zscaler/zpa/servers.py +198 -0
  70. zscaler/zpa/service_edges.py +388 -0
  71. zscaler/zpa/trusted_networks.py +125 -0
  72. zscaler_sdk_python-0.1.3.dist-info/LICENSE.md +21 -0
  73. zscaler_sdk_python-0.1.3.dist-info/METADATA +362 -0
  74. zscaler_sdk_python-0.1.3.dist-info/RECORD +75 -0
  75. zscaler_sdk_python-0.1.3.dist-info/WHEEL +4 -0
@@ -0,0 +1,336 @@
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
+ from box import Box, BoxList
18
+ from requests import Response
19
+
20
+ from zscaler.utils import Iterator, snake_to_camel
21
+ from zscaler.zia import ZIAClient
22
+
23
+
24
+ class AdminAndRoleManagementAPI:
25
+ def __init__(self, client: ZIAClient):
26
+ self.rest = client
27
+
28
+ def list_users(self, **kwargs) -> BoxList:
29
+ """
30
+ Returns a list of admin users.
31
+
32
+ Keyword Args:
33
+ include_auditor_users (bool, optional):
34
+ Include or exclude auditor user information in the list.
35
+ include_admin_users (bool, optional):
36
+ Include or exclude admin user information in the list. (default: True)
37
+ search (str, optional):
38
+ The search string used to partially match against an admin/auditor user's Login ID or Name.
39
+ page (int, optional):
40
+ Specifies the page offset.
41
+ page_size (int, optional):
42
+ Specifies the page size. The default size is 100, but the maximum size is 1000.
43
+
44
+ Returns:
45
+ list: The admin_users resource records.
46
+
47
+ Examples:
48
+ >>> users = zia.admin_and_role_management.list_users('admin@example.com')
49
+
50
+ """
51
+ return BoxList(Iterator(self.rest, "adminUsers", **kwargs))
52
+
53
+ def get_user(self, user_id: str) -> Box:
54
+ """
55
+ Returns information on the specified admin user id.
56
+
57
+ Args:
58
+ user_id (str): The unique id of the admin user.
59
+
60
+ Returns:
61
+ :obj:`Box`: The admin user resource record.
62
+
63
+ Examples:
64
+ >>> print(zia.admin_and_role_management.get_user('987321202'))
65
+
66
+ """
67
+ response = self.rest.get("/adminUsers/%s" % (user_id))
68
+ if isinstance(response, Response):
69
+ status_code = response.status_code
70
+ if status_code != 200:
71
+ return None
72
+ return response
73
+
74
+ def add_user(self, name: str, login_name: str, email: str, password: str, **kwargs) -> Box:
75
+ """
76
+ Adds a new admin user to ZIA.
77
+
78
+ Args:
79
+ name (str): The user's full name.
80
+ login_name (str):
81
+ The name that the admin user will use to login to ZIA in email format, i.e. `user@domain.tld.`
82
+ email (str): The email address for the admin user.
83
+ password (str): The password for the admin user.
84
+ **kwargs: Optional keyword args.
85
+
86
+ Keyword Args:
87
+ admin_scope (str): The scope of the admin's permissions, accepted values are:
88
+ ``organization``, ``department``, ``location``, ``location_group``
89
+ comments (str): Additional information about the admin user.
90
+ disabled (bool): Set to ``True`` if you want the account disabled upon creation.
91
+ is_password_login_allowed (bool): Set to ``True`` to allow password login.
92
+ is_security_report_comm_enabled (bool):
93
+ Set to ``True`` to allow ZIA Security Update emails to be sent to the admin user.
94
+ is_service_update_comm_enabled (bool):
95
+ Set to ``True`` to allow ZIA Service Update emails to be sent to the admin user.
96
+ is_product_update_comm_enabled (bool):
97
+ Set to ``True`` to allow ZIA Product Update emails to be sent to the admin user.
98
+ is_password_expired (bool):
99
+ Set to ``True`` to expire the admin user's password upon creation.
100
+ is_exec_mobile_app_enabled (bool):
101
+ Set to ``True`` to enable to executive insights mobile application for the admin user.
102
+ role_id (str): The unique id for the admin role being assigned to the admin user.
103
+ scope_ids (list):
104
+ A list of entity ids for the admin user's scope. e.g. if the admin user has admin_scope set to
105
+ ``department`` then you will need to provide a list of department ids.
106
+ **NOTE**: This param doesn't need to
107
+ be provided if the admin user's scope is set to ``organization``.
108
+
109
+ Returns:
110
+ :obj:`Box`: The newly created admin user resource record.
111
+
112
+ Examples:
113
+
114
+ Add an admin user with the minimum required params:
115
+ >>> admin_user = zia.admin_and_role_management.add_user(
116
+ ... name="Jim Bob",
117
+ ... login_name="jim@example.com",
118
+ ... password="*********",
119
+ ... email="jim@example.com")
120
+
121
+ Add an admin user with a department admin scope:
122
+ >>> admin_user = zia.admin_and_role_management.add_user(
123
+ ... name="Jane Bob",
124
+ ... login_name="jane@example.com",
125
+ ... password="*********",
126
+ ... email="jane@example.com,
127
+ ... admin_scope="department",
128
+ ... scope_ids = ['376542', '245688'])
129
+
130
+ Add an auditor user:
131
+ >>> auditor_user = zia.admin_and_role_management.add_user(
132
+ ... name="Head Bob",
133
+ ... login_name="head@example.com",
134
+ ... password="*********",
135
+ ... email="head@example.com,
136
+ ... is_auditor=True)
137
+
138
+ """
139
+ payload = {
140
+ "userName": name,
141
+ "loginName": login_name,
142
+ "email": email,
143
+ "password": password,
144
+ }
145
+
146
+ # Get the admin scope if provided
147
+ admin_scope = kwargs.pop("admin_scope", None)
148
+
149
+ # The default admin scope is organization so we don't really need to
150
+ # send it to ZIA as part of this API call. Otherwise if the user has
151
+ # supplied something different then we want to explicitly set that for
152
+ # the adminScopeType.
153
+ if admin_scope and admin_scope != "organization":
154
+ payload["adminScopeType"] = admin_scope.upper()
155
+ payload["adminScopeScopeEntities"] = []
156
+
157
+ # Add optional parameters to payload
158
+ for key, value in kwargs.items():
159
+ # If the user has supplied ids for the admin scope then we'll add
160
+ # them to the payload here. If the user doesn't supply them then
161
+ # ZIA will return an error.
162
+ if key == "scope_ids":
163
+ for scope_id in value:
164
+ payload["adminScopeScopeEntities"].append({"id": scope_id})
165
+ elif key == "role_id":
166
+ payload["role"] = {"id": value}
167
+ else:
168
+ payload[snake_to_camel(key)] = value
169
+
170
+ response = self.rest.post("adminUsers", json=payload)
171
+ if isinstance(response, Response):
172
+ # Handle error response
173
+ status_code = response.status_code
174
+ if status_code != 200:
175
+ raise Exception(f"API call failed with status {status_code}: {response.json()}")
176
+ return response
177
+
178
+ def update_user(self, user_id: str, **kwargs) -> dict:
179
+ """
180
+ Update an admin user.
181
+
182
+ Args:
183
+ user_id (str): The unique id of the admin user to be updated.
184
+ **kwargs: Optional keyword args.
185
+
186
+ Keyword Args:
187
+ admin_scope (str): The scope of the admin's permissions, accepted values are:
188
+ ``organization``, ``department``, ``location``, ``location_group``
189
+ comments (str): Additional information about the admin user.
190
+ disabled (bool): Set to ``True`` if you want the account disabled upon creation.
191
+ email (str): The email address for the admin user.
192
+ is_password_login_allowed (bool): Set to ``True`` to allow password login.
193
+ is_security_report_comm_enabled (bool):
194
+ Set to ``True`` to allow ZIA Security Update emails to be sent to the admin user.
195
+ is_service_update_comm_enabled (bool):
196
+ Set to ``True`` to allow ZIA Service Update emails to be sent to the admin user.
197
+ is_product_update_comm_enabled (bool):
198
+ Set to ``True`` to allow ZIA Product Update emails to be sent to the admin user.
199
+ is_password_expired (bool):
200
+ Set to ``True`` to expire the admin user's password upon creation.
201
+ is_exec_mobile_app_enabled (bool):
202
+ Set to ``True`` to enable to executive insights mobile application for the admin user.
203
+ name (str): The user's full name.
204
+ password (str): The password for the admin user.
205
+ role_id (str): The unique id for the admin role being assigned to the admin user.
206
+ scope_ids (list):
207
+ A list of entity ids for the admin user's scope. e.g. if the admin user has ``admin_scope`` set to
208
+ ``department`` then you will need to provide a list of department ids.
209
+ **NOTE:** This param doesn't need to
210
+ be provided if the admin user's scope is set to `organization`.
211
+
212
+ Returns:
213
+ :obj:`dict`: The updated admin user resource record.
214
+
215
+ Examples:
216
+
217
+ Update the email address for an admin user:
218
+ >>> user = zia.admin_and_role_management.update_user('99695301',
219
+ ... email='jimbob@example.com')
220
+
221
+ Update the admin scope for an admin user to department:
222
+ >>> user = zia.admin_and_role_management.update_user('99695301',
223
+ ... admin_scope='department',
224
+ ... scope_ids=['3846532', '3846541'])
225
+
226
+ """
227
+
228
+ # Get the resource record for the provided user id
229
+ payload = {snake_to_camel(k): v for k, v in self.get_user(user_id).items()}
230
+
231
+ # Get the admin scope if provided
232
+ admin_scope = kwargs.pop("admin_scope", None)
233
+
234
+ # The default admin scope is organization so we don't really need to
235
+ # send it to ZIA as part of this API call. Otherwise if the user has
236
+ # supplied something different then we want to explicitly set that for
237
+ # the adminScopeType.
238
+ if admin_scope and admin_scope != "organization":
239
+ payload["adminScopeType"] = admin_scope.upper()
240
+ payload["adminScopeScopeEntities"] = []
241
+
242
+ # Add optional parameters to payload
243
+ for key, value in kwargs.items():
244
+ # If the user has supplied ids for the admin scope then we'll add
245
+ # them to the payload here. If the user doesn't supply them then
246
+ # ZIA will return an error.
247
+ if key == "scope_ids":
248
+ for scope_id in value:
249
+ payload["adminScopeScopeEntities"].append({"id": scope_id})
250
+ elif key == "name":
251
+ # We renamed the username param to make it more meaningful for zscaler-sdk-python users
252
+ payload["userName"] = value
253
+ else:
254
+ payload[snake_to_camel(key)] = value
255
+
256
+ # Update payload
257
+ for key, value in kwargs.items():
258
+ payload[snake_to_camel(key)] = value
259
+
260
+ response = self.rest.put("/adminUsers/%s" % (user_id), json=payload)
261
+ if isinstance(response, Response) and not response.ok:
262
+ # Handle error response
263
+ raise Exception(f"API call failed with status {response.status_code}: {response.json()}")
264
+
265
+ # Return the updated object
266
+ return self.get_user(user_id)
267
+
268
+ def delete_user(self, user_id: str) -> int:
269
+ """
270
+ Deletes the specified admin user by id.
271
+
272
+ Args:
273
+ user_id (str): The unique id of the admin user.
274
+
275
+ Returns:
276
+ :obj:`int`: The response code for the request.
277
+
278
+ Examples:
279
+ >>> zia.admin_role_management.delete_admin_user('99272455')
280
+
281
+ """
282
+ response = self.rest.delete("/adminUsers/%s" % (user_id))
283
+ return response.status_code
284
+
285
+ def list_roles(self, **kwargs) -> BoxList:
286
+ """
287
+ Return a list of the configured admin roles in ZIA.
288
+
289
+ Args:
290
+ **kwargs: Optional keyword args.
291
+
292
+ Keyword Args:
293
+ include_auditor_role (bool): Set to ``True`` to include auditor role information in the response.
294
+ include_partner_role (bool): Set to ``True`` to include partner admin role information in the response.
295
+
296
+ Returns:
297
+ :obj:`BoxList`: A list of admin role resource records.
298
+
299
+ Examples:
300
+ Get a list of all configured admin roles:
301
+ >>> roles = zia.admin_and_management_roles.list_roles()
302
+
303
+ """
304
+ payload = {snake_to_camel(key): value for key, value in kwargs.items()}
305
+ return self.rest.get("adminRoles/lite", params=payload)
306
+
307
+ def get_role(self, role_id: str) -> Box:
308
+ """
309
+ Returns information on the specified admin user id.
310
+
311
+ Args:
312
+ user_id (str): The unique id of the admin user.
313
+
314
+ Returns:
315
+ :obj:`Box`: The admin user resource record.
316
+
317
+ Examples:
318
+ >>> print(zia.admin_and_role_management.get_user('987321202'))
319
+
320
+ """
321
+ admin_role = next(user for user in self.list_roles() if user.id == int(role_id))
322
+ return admin_role
323
+
324
+ def get_roles_by_name(self, name):
325
+ roles = self.list_roles()
326
+ for role in roles:
327
+ if role.get("name") == name:
328
+ return role
329
+ return None
330
+
331
+ def get_roles_by_id(self, role_id):
332
+ roles = self.list_roles()
333
+ for role in roles:
334
+ if role.get("id") == role_id:
335
+ return role
336
+ return None
@@ -0,0 +1,71 @@
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
+ from box import Box
18
+
19
+ from zscaler.zia import ZIAClient
20
+
21
+
22
+ class AppTotalAPI:
23
+ def __init__(self, client: ZIAClient):
24
+ self.rest = client
25
+
26
+ def get_app(self, app_id: str, verbose: bool = False) -> Box:
27
+ """
28
+ Searches the AppTotal App Catalog by app ID. If the app exists in the catalog, the app's information is
29
+ returned. If not, the app is submitted for analysis. After analysis is complete, a subsequent GET request is
30
+ required to fetch the app's information.
31
+
32
+ Args:
33
+ app_id (str): The app ID to search for.
34
+ verbose (bool, optional): Defaults to False.
35
+
36
+ Returns:
37
+ :obj:`Box`: The response object.
38
+
39
+ Examples:
40
+ Return verbose information on an app with ID 12345::
41
+
42
+ zia.apptotal.get_app(app_id="12345", verbose=True)
43
+
44
+ """
45
+ params = {
46
+ "app_id": app_id,
47
+ "verbose": verbose,
48
+ }
49
+ return self.rest.get("apps/app", params=params)
50
+
51
+ def scan_app(self, app_id: str) -> Box:
52
+ """
53
+ Submits an app for analysis in the AppTotal Sandbox. After analysis is complete, a subsequent GET request is
54
+ required to fetch the app's information.
55
+
56
+ Args:
57
+ app_id (str): The app ID to scan.
58
+
59
+ Returns:
60
+ :obj:`Box`: The response object.
61
+
62
+ Examples:
63
+ Scan an app with ID 12345::
64
+
65
+ zia.apptotal.scan_app(app_id="12345")
66
+
67
+ """
68
+ payload = {
69
+ "appId": app_id,
70
+ }
71
+ return self.rest.post("apps/app", json=payload)
@@ -0,0 +1,93 @@
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
+
20
+ from zscaler.zia import ZIAClient
21
+
22
+
23
+ class AuditLogsAPI:
24
+ def __init__(self, client: ZIAClient):
25
+ self.rest = client
26
+
27
+ def status(self) -> Box:
28
+ """
29
+ Get the status of a request for an audit log report.
30
+
31
+ Returns:
32
+ :obj:`Box`: Audit log report request status.
33
+
34
+ Examples:
35
+ >>> print(zia.audit_logs.status())
36
+
37
+ """
38
+ return self.rest.get("auditlogEntryReport")
39
+
40
+ def create(self, start_time: str, end_time: str) -> int:
41
+ """
42
+ Creates an audit log report for the specified time period and saves it as a CSV file. The report
43
+ includes audit information for every call made to the cloud service API during the specified time period.
44
+ Creating a new audit log report will overwrite a previously-generated report.
45
+
46
+ Args:
47
+ start_time (str):
48
+ The timestamp, in epoch, of the admin's last login.
49
+ end_time (str):
50
+ The timestamp, in epoch, of the admin's last logout.
51
+
52
+ Returns:
53
+ :obj:`int`: The status code for the operation.
54
+
55
+ Examples:
56
+ >>> zia.audit_logs.create(start_time='1627221600000',
57
+ ... end_time='1627271676622')
58
+
59
+ """
60
+ payload = {
61
+ "startTime": start_time,
62
+ "endTime": end_time,
63
+ }
64
+ return self.rest.post("auditlogEntryReport", json=payload, box=False).status_code
65
+
66
+ def cancel(self) -> int:
67
+ """
68
+ Cancels the request to create an audit log report.
69
+
70
+ Returns:
71
+ :obj:`int`: The operation response code.
72
+
73
+ Examples:
74
+ >>> zia.audit_logs.cancel()
75
+
76
+ """
77
+ return self.rest.delete("auditlogEntryReport", box=False).status_code
78
+
79
+ def get_report(self) -> str:
80
+ """
81
+ Returns the most recently created audit log report.
82
+
83
+ Returns:
84
+ :obj:`str`: String representation of CSV file.
85
+
86
+ Examples:
87
+ Write report to CSV file:
88
+
89
+ >>> with open("audit_log.csv", "w+") as fh:
90
+ ... fh.write(zia.audit_logs.get_report())
91
+
92
+ """
93
+ return self.rest.get("auditlogEntryReport/download").text
@@ -0,0 +1,94 @@
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 BoxList
19
+
20
+ from zscaler.zia import ZIAClient
21
+
22
+
23
+ class AuthenticationSettingsAPI:
24
+ def __init__(self, client: ZIAClient):
25
+ self.rest = client
26
+
27
+ def get_exempted_urls(self) -> BoxList:
28
+ """
29
+ Returns a list of exempted URLs.
30
+
31
+ Returns:
32
+ :obj:`BoxList`: A list of exempted URLs
33
+
34
+ Examples:
35
+ >>> for url in zia.authentication_settings.get_exempted_urls():
36
+ ... pprint(url)
37
+ """
38
+ response = self.rest.get("authSettings/exemptedUrls")
39
+
40
+ # Ensure the correct attribute key is used in the response check.
41
+ if "urls" in response:
42
+ return response.urls
43
+ else:
44
+ return BoxList()
45
+
46
+ def add_urls_to_exempt_list(self, url_list: list) -> BoxList:
47
+ """
48
+ Adds the provided URLs to the exempt list.
49
+
50
+ Args:
51
+ url_list (:obj:`list` of :obj:`str`):
52
+ The list of URLs to be added.
53
+
54
+ Returns:
55
+ :obj:`BoxList`: The complete and updated exempt list.
56
+
57
+ """
58
+
59
+ payload = {"urls": url_list}
60
+
61
+ resp = self.rest.post("authSettings/exemptedUrls?action=ADD_TO_LIST", json=payload)
62
+
63
+ # Check if the response object has a 'status_code' attribute before accessing it
64
+ if hasattr(resp, "status_code"):
65
+ if resp.status_code == 204:
66
+ return self.get_exempted_urls()
67
+ else:
68
+ # Handle case where resp is a Box object
69
+ if "urls" in resp:
70
+ return resp.urls
71
+ else:
72
+ return BoxList() # Return empty list if no URLs are present
73
+
74
+ def delete_urls_from_exempt_list(self, url_list: list) -> BoxList:
75
+ """
76
+ Deletes the provided URLs from the exemption list.
77
+
78
+ Args:
79
+ url_list (:obj:`list` of :obj:`str`):
80
+ The list of URLs to be removed.
81
+
82
+ Returns:
83
+ :obj:`BoxList`: The updated exemption list.
84
+
85
+ Examples:
86
+ >>> zia.authentication_settings.delete_urls_from_exempt_list(['example.com'])
87
+
88
+ """
89
+ payload = {"urls": url_list}
90
+ resp = self.rest.post("authSettings/exemptedUrls?action=REMOVE_FROM_LIST", json=payload)
91
+
92
+ # Return the updated exemption list if the removal was successful.
93
+ if resp == 200:
94
+ return self.get_exempted_urls()
zscaler/zia/client.py ADDED
@@ -0,0 +1,88 @@
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
+ class ZIAClient:
19
+ def __init__():
20
+ pass
21
+
22
+ def get(self, path: str, json=None, params=None, fail_safe: bool = False):
23
+ """
24
+ Send a GET request to the ZIA API.
25
+ Parameters:
26
+ - path (str): API endpoint path.
27
+ - json (str): the request body.
28
+ - params (dict): the query params
29
+ """
30
+ pass
31
+ pass
32
+
33
+ def get_paginated_data(
34
+ self,
35
+ path: str = None,
36
+ data_key_name: str = None,
37
+ data_per_page: int = 500,
38
+ expected_status_code=200,
39
+ ):
40
+ """
41
+ Send a GET request to the ZIA API to fetch all pages of a resources.
42
+ Parameters:
43
+ - path (str): API endpoint path.
44
+ - data_key_name (str): list field key.
45
+ - data_per_page: the page size
46
+ - params (dict): the query params
47
+ """
48
+ pass
49
+
50
+ def put(self, path: str, json=None, params=None):
51
+ """
52
+ Send a PUT request to the ZIA API.
53
+ Parameters:
54
+ - path (str): API endpoint path.
55
+ - json (str): the request body.
56
+ - params (dict): the query params
57
+ """
58
+ pass
59
+
60
+ def patch(self, path: str, json=None, params=None):
61
+ """
62
+ Send a PATCH request to the ZIA API.
63
+ Parameters:
64
+ - path (str): API endpoint path.
65
+ - json (str): the request body.
66
+ - params (dict): the query params
67
+ """
68
+ pass
69
+
70
+ def post(self, path: str, json=None, params=None):
71
+ """
72
+ Send a POST request to the ZIA API.
73
+ Parameters:
74
+ - path (str): API endpoint path.
75
+ - json (str): the request body.
76
+ - params (dict): the query params
77
+ """
78
+ pass
79
+
80
+ def delete(self, path: str, json=None, params=None):
81
+ """
82
+ Send a DELETE request to the ZIA API.
83
+ Parameters:
84
+ - path (str): API endpoint path.
85
+ - json (str): the request body.
86
+ - params (dict): the query params
87
+ """
88
+ pass