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,422 @@
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
+ import time
19
+
20
+ from box import Box, BoxList
21
+ from requests import Response
22
+
23
+ from zscaler.utils import chunker, convert_keys, snake_to_camel
24
+ from zscaler.zia import ZIAClient
25
+
26
+
27
+ class URLCategoriesAPI:
28
+ def __init__(self, client: ZIAClient):
29
+ self.rest = client
30
+
31
+ def lookup(self, urls: list) -> BoxList:
32
+ """
33
+ Lookup the category for the provided URLs.
34
+
35
+ Args:
36
+ urls (list):
37
+ The list of URLs to perform a category lookup on.
38
+
39
+ Returns:
40
+ :obj:`BoxList`: A list of URL category reports.
41
+
42
+ Examples:
43
+ >>> zia.url_categories.lookup(['example.com', 'test.com'])
44
+
45
+ """
46
+
47
+ if len(urls) > 100:
48
+ results = BoxList()
49
+ for chunk in chunker(urls, 100):
50
+ results.extend(self._post("urlLookup", json=chunk))
51
+ time.sleep(1)
52
+ return results
53
+
54
+ else:
55
+ payload = urls
56
+ return self.rest.post("urlLookup", json=payload)
57
+
58
+ def list_categories(self, custom_only: bool = False, only_counts: bool = False) -> BoxList:
59
+ """
60
+ Returns information on URL categories.
61
+
62
+ Args:
63
+ custom_only (bool):
64
+ Returns only custom categories if True.
65
+ only_counts (bool):
66
+ Returns only URL and keyword counts if True.
67
+
68
+ Returns:
69
+ :obj:`BoxList`: A list of information for all or custom URL categories.
70
+
71
+ Examples:
72
+ List all URL categories:
73
+
74
+ >>> zia.url_categories.list_categories()
75
+
76
+ List only custom URL categories:
77
+
78
+ >>> zia.url_categories.list_categories(custom_only=True)
79
+
80
+ """
81
+ payload = {
82
+ "customOnly": custom_only,
83
+ "includeOnlyUrlKeywordCounts": only_counts,
84
+ }
85
+
86
+ return self.rest.get("urlCategories", params=payload)
87
+
88
+ def get_category_by_name(self, name):
89
+ categories = self.list_categories()
90
+ for category in categories:
91
+ if category.get("configured_name") == name:
92
+ return category
93
+ return None
94
+
95
+ def get_quota(self) -> Box:
96
+ """
97
+ Returns information on URL category quota usage.
98
+
99
+ Returns:
100
+ :obj:`Box`: The URL quota statistics.
101
+
102
+ Examples:
103
+ >>> zia.url_categories.get_quota()
104
+
105
+ """
106
+
107
+ return self.rest.get("urlCategories/urlQuota")
108
+
109
+ def get_category(self, category_id: str) -> Box:
110
+ """
111
+ Returns URL category information for the provided category.
112
+
113
+ Args:
114
+ category_id (str):
115
+ The unique identifier for the category (e.g. 'MUSIC')
116
+
117
+ Returns:
118
+ :obj:`Box`: The resource record for the category.
119
+
120
+ Examples:
121
+ >>> zia.url_categories.get_category('ALCOHOL_TOBACCO')
122
+
123
+ """
124
+ return self.rest.get(f"urlCategories/{category_id}")
125
+
126
+ def add_url_category(self, configured_name: str, super_category: str, urls: list, **kwargs) -> Box:
127
+ """
128
+ Adds a new custom URL category.
129
+
130
+ Args:
131
+ name (str):
132
+ Name of the URL category.
133
+ super_category (str):
134
+ The name of the parent category.
135
+ urls (list):
136
+ Custom URLs to add to a URL category.
137
+ **kwargs:
138
+ Optional keyword args.
139
+
140
+ Keyword Args:
141
+ db_categorized_urls (list):
142
+ URLs entered will be covered by policies that reference the parent category, in addition to this one.
143
+ description (str):
144
+ Description of the category.
145
+ custom_category (bool):
146
+ Set to true for custom URL category. Up to 48 custom URL categories can be added per organisation.
147
+ ip_ranges (list):
148
+ Custom IP addpress ranges associated to a URL category. This feature must be enabled on your tenancy.
149
+ ip_ranges_retaining_parent_category (list):
150
+ The retaining parent custom IP addess ranges associated to a URL category.
151
+ keywords (list):
152
+ Custom keywords associated to a URL category.
153
+ keywords_retaining_parent_category (list):
154
+ Retained custom keywords from the parent URL category that are associated with a URL category.
155
+
156
+ Returns:
157
+ :obj:`Box`: The newly configured custom URL category resource record.
158
+
159
+ Examples:
160
+ Add a new category for beers that don't taste good:
161
+
162
+ >>> zia.url_categories.add_url_category(name='Beer',
163
+ ... super_category='ALCOHOL_TOBACCO',
164
+ ... urls=['xxxx.com.au', 'carltondraught.com.au'],
165
+ ... description="Beers that don't taste good.")
166
+
167
+ Add a new category with IP ranges:
168
+
169
+ >>> zia.url_categories.add_url_category(name='Beer',
170
+ ... super_category='FINANCE',
171
+ ... urls=['finance.google.com'],
172
+ ... description="Google Finance.",
173
+ ... ip_ranges=['10.0.0.0/24'])
174
+
175
+ """
176
+
177
+ payload = {
178
+ "type": "URL_CATEGORY",
179
+ "superCategory": super_category,
180
+ "configuredName": configured_name,
181
+ "urls": urls,
182
+ }
183
+
184
+ # Add optional parameters to payload
185
+ for key, value in kwargs.items():
186
+ payload[snake_to_camel(key)] = value
187
+
188
+ response = self.rest.post("urlCategories", json=payload)
189
+ if isinstance(response, Response):
190
+ # Handle error response
191
+ status_code = response.status_code
192
+ if status_code != 200:
193
+ raise Exception(f"API call failed with status {status_code}: {response.json()}")
194
+ return response
195
+
196
+ def add_tld_category(self, name: str, tlds: list, **kwargs) -> Box:
197
+ """
198
+ Adds a new custom TLD category.
199
+
200
+ Args:
201
+ name (str):
202
+ The name of the TLD category.
203
+ tlds (list):
204
+ A list of TLDs in the format '.tld'.
205
+ **kwargs:
206
+ Optional keyword args.
207
+
208
+ Keyword Args:
209
+ description (str):
210
+ Description of the category.
211
+
212
+ Returns:
213
+ :obj:`Box`: The newly configured custom TLD category resource record.
214
+
215
+ Examples:
216
+ Create a category for all 'developer' sites:
217
+
218
+ >>> zia.url_categories.add_tld_category(name='Developer Sites',
219
+ ... urls=['.dev'],
220
+ ... description="Sites that are likely run by developers.")
221
+
222
+ """
223
+
224
+ payload = {
225
+ "type": "TLD_CATEGORY",
226
+ "superCategory": "USER_DEFINED", # TLDs can only be added in USER_DEFINED category
227
+ "configuredName": name,
228
+ "urls": tlds, # ZIA API reuses the 'urls' key for tlds
229
+ }
230
+
231
+ # Add optional parameters to payload
232
+ for key, value in kwargs.items():
233
+ payload[snake_to_camel(key)] = value
234
+
235
+ response = self.rest.post("urlCategories", json=payload)
236
+ if isinstance(response, Response):
237
+ # Handle error response
238
+ status_code = response.status_code
239
+ if status_code != 200:
240
+ raise Exception(f"API call failed with status {status_code}: {response.json()}")
241
+ return response
242
+
243
+ def update_url_category(self, category_id: str, **kwargs) -> Box:
244
+ """
245
+ Updates a URL category.
246
+
247
+ Args:
248
+ category_id (str):
249
+ The unique identifier of the URL category.
250
+ **kwargs:
251
+ Optional keyword args.
252
+
253
+ Keyword Args:
254
+ name (str):
255
+ The name of the URL category.
256
+ urls (list):
257
+ Custom URLs to add to a URL category.
258
+ db_categorized_urls (list):
259
+ URLs entered will be covered by policies that reference the parent category, in addition to this one.
260
+ description (str):
261
+ Description of the category.
262
+ ip_ranges (list):
263
+ Custom IP addpress ranges associated to a URL category. This feature must be enabled on your tenancy.
264
+ ip_ranges_retaining_parent_category (list):
265
+ The retaining parent custom IP addess ranges associated to a URL category.
266
+ keywords (list):
267
+ Custom keywords associated to a URL category.
268
+ keywords_retaining_parent_category (list):
269
+ Retained custom keywords from the parent URL category that are associated with a URL category.
270
+
271
+ Returns:
272
+ :obj:`Box`: The updated URL category resource record.
273
+
274
+ Examples:
275
+ Update the name of a category:
276
+
277
+ >>> zia.url_categories.update_url_category('CUSTOM_01',
278
+ ... name="Wines that don't taste good.")
279
+
280
+ Update the urls of a category:
281
+
282
+ >>> zia.url_categories.update_url_category('CUSTOM_01',
283
+ ... urls=['www.yellowtailwine.com'])
284
+
285
+ """
286
+
287
+ payload = convert_keys(self.get_category(category_id))
288
+
289
+ # Add optional parameters to payload
290
+ for key, value in kwargs.items():
291
+ payload[snake_to_camel(key)] = value
292
+
293
+ response = self.rest.put(f"urlCategories/{category_id}", json=payload)
294
+ if isinstance(response, Response) and not response.ok:
295
+ # Handle error response
296
+ raise Exception(f"API call failed with status {response.status_code}: {response.json()}")
297
+
298
+ # Return the updated object
299
+ return self.get_category(category_id)
300
+
301
+ def add_urls_to_category(self, category_id: str, urls: list) -> Box:
302
+ """
303
+ Adds URLS to a URL category.
304
+
305
+ Args:
306
+ category_id (str):
307
+ The unique identifier of the URL category.
308
+ urls (list):
309
+ Custom URLs to add to a URL category.
310
+
311
+ Returns:
312
+ :obj:`Box`: The updated URL category resource record.
313
+
314
+ Examples:
315
+ >>> zia.url_categories.add_urls_to_category('CUSTOM_01',
316
+ ... urls=['example.com'])
317
+
318
+ """
319
+
320
+ payload = convert_keys(self.get_category(category_id))
321
+ payload["urls"] = urls
322
+
323
+ response = self.rest.put(f"urlCategories/{category_id}?action=ADD_TO_LIST", json=payload)
324
+ if isinstance(response, Response) and not response.ok:
325
+ # Handle error response
326
+ raise Exception(f"API call failed with status {response.status_code}: {response.json()}")
327
+
328
+ def delete_urls_from_category(self, category_id: str, urls: list) -> Box:
329
+ """
330
+ Deletes URLS from a URL category.
331
+
332
+ Args:
333
+ category_id (str):
334
+ The unique identifier of the URL category.
335
+ urls (list):
336
+ Custom URLs to delete from a URL category.
337
+
338
+ Returns:
339
+ :obj:`Box`: The updated URL category resource record.
340
+
341
+ Examples:
342
+ >>> zia.url_categories.delete_urls_from_category('CUSTOM_01',
343
+ ... urls=['example.com'])
344
+
345
+ """
346
+ current_config = self.get_category(category_id)
347
+ payload = {
348
+ "configuredName": current_config["configured_name"],
349
+ "urls": urls,
350
+ } # Required for successful call
351
+
352
+ return self.rest.put(f"urlCategories/{category_id}?action=REMOVE_FROM_LIST", json=payload)
353
+
354
+ def delete_from_category(self, category_id: str, **kwargs):
355
+ """
356
+ Deletes the specified items from a URL category.
357
+
358
+ Args:
359
+ category_id (str):
360
+ The unique id for the URL category.
361
+ **kwargs:
362
+ Optional parameters.
363
+
364
+ Keyword Args:
365
+ keywords (list):
366
+ A list of keywords that will be deleted.
367
+ keywords_retaining_parent_category (list):
368
+ A list of keywords retaining their parent category that will be deleted.
369
+ urls (list):
370
+ A list of URLs that will be deleted.
371
+ db_categorized_urls (list):
372
+ A list of URLs retaining their parent category that will be deleted
373
+
374
+ Returns:
375
+ :obj:`Box`: The updated URL category resource record.
376
+
377
+ Examples:
378
+ Delete URLs retaining parent category from a custom category:
379
+
380
+ >>> zia.url_categories.delete_from_category(
381
+ ... category_id="CUSTOM_01",
382
+ ... db_categorized_urls=['twitter.com'])
383
+
384
+ Delete URLs and URLs retaining parent category from a custom category:
385
+
386
+ >>> zia.url_categories.delete_from_category(
387
+ ... category_id="CUSTOM_01",
388
+ ... urls=['news.com', 'cnn.com'],
389
+ ... db_categorized_urls=['google.com, bing.com'])
390
+
391
+ """
392
+ current_config = self.get_category(category_id)
393
+
394
+ payload = {
395
+ "configured_name": current_config["configured_name"], # Required for successful call
396
+ }
397
+
398
+ # Add optional parameters to payload
399
+ for key, value in kwargs.items():
400
+ payload[key] = value
401
+
402
+ # Convert snake to camelcase
403
+ payload = convert_keys(payload)
404
+
405
+ return self.rest.put(f"urlCategories/{category_id}?action=REMOVE_FROM_LIST", json=payload)
406
+
407
+ def delete_category(self, category_id: str) -> int:
408
+ """
409
+ Deletes the specified URL category.
410
+
411
+ Args:
412
+ category_id (str):
413
+ The unique identifier for the category.
414
+
415
+ Returns:
416
+ :obj:`int`: The status code for the operation.
417
+
418
+ Examples:
419
+ >>> zia.url_categories.delete_category('CUSTOM_01')
420
+
421
+ """
422
+ return self.rest.delete(f"urlCategories/{category_id}").status_code