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,271 @@
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 (
21
+ convert_keys,
22
+ recursive_snake_to_camel,
23
+ snake_to_camel,
24
+ transform_common_id_fields,
25
+ )
26
+ from zscaler.zia import ZIAClient
27
+
28
+
29
+ class ForwardingControlAPI:
30
+ # Forwarding Control filter rule keys that only require an ID to be provided.
31
+ reformat_params = [
32
+ ("app_service_groups", "appServiceGroups"),
33
+ ("departments", "departments"),
34
+ ("devices", "devices"),
35
+ ("device_groups", "deviceGroups"),
36
+ ("dest_ip_groups", "destIpGroups"),
37
+ ("dest_ipv6_groups", "destIpv6Groups"),
38
+ ("ec_groups", "ecGroups"),
39
+ ("groups", "groups"),
40
+ ("labels", "labels"),
41
+ ("locations", "locations"),
42
+ ("location_groups", "locationGroups"),
43
+ ("nw_application_groups", "nwApplicationGroups"),
44
+ ("nw_services", "nwServices"),
45
+ ("nw_service_groups", "nwServiceGroups"),
46
+ ("proxy_gateway", "proxyGateway"),
47
+ ("src_ip_groups", "srcIpGroups"),
48
+ ("src_ipv6_groups", "srcIpv6Groups"),
49
+ ("users", "users"),
50
+ ("zpa_gateway", "zpaGateway"),
51
+ ("zpa_app_segments", "zpaAppSegments"),
52
+ ("zpa_application_segments", "zpaApplicationSegments"),
53
+ ("zpa_application_segment_groups", "zpaApplicationSegmentGroups"),
54
+ ]
55
+
56
+ def __init__(self, client: ZIAClient):
57
+ self.rest = client
58
+
59
+ def list_rules(self) -> BoxList:
60
+ """
61
+ Returns a list of all forwarding control rules.
62
+
63
+ Returns:
64
+ :obj:`BoxList`: The list of forwarding control rules
65
+
66
+ Examples:
67
+ >>> for rule in zia.forwarding_control.list_rules():
68
+ ... pprint(rule)
69
+
70
+ """
71
+ response = self.rest.get("/forwardingRules")
72
+ if isinstance(response, Response):
73
+ return None
74
+ return response
75
+
76
+ def get_rule(self, rule_id: str) -> Box:
77
+ """
78
+ Returns information for the specified forwarding control filter rule.
79
+
80
+ Args:
81
+ rule_id (str): The unique identifier for the forwarding control filter rule.
82
+
83
+ Returns:
84
+ :obj:`Box`: The resource record for the forwarding control filter rule.
85
+
86
+ Examples:
87
+ >>> pprint(zia.forwarding_control.get_rule('431233'))
88
+
89
+ """
90
+ return self.rest.get(f"forwardingRules/{rule_id}")
91
+
92
+ def add_rule(self, name: str, forward_method: str, **kwargs) -> Box:
93
+ """
94
+ Adds a new forwarding control filter rule.
95
+
96
+ Args:
97
+ name (str): Name of the rule, max 31 chars.
98
+ forward_method (str): Traffic forwarding method. Options: 'INVALID', 'DIRECT',
99
+ 'PROXYCHAIN', 'ZIA', 'ZPA', 'ECZPA', 'ECSELF', 'DROP'.
100
+
101
+ Keyword Args:
102
+ order (str): Rule order, defaults to bottom.
103
+ rank (str): Admin rank of the rule.
104
+ state (str): Rule state ('ENABLED' or 'DISABLED').
105
+ description (str): Rule description.
106
+ src_ips (list): Source IPs for the rule, accepts IP addresses or CIDR.
107
+ dest_addresses (list): Destination IPs for the rule, accepts IP addresses or CIDR.
108
+ dest_ip_categories (list): IP address categories for the rule.
109
+ dest_countries (list): Destination countries for the rule.
110
+ enable_full_logging (bool): If True, enables full logging.
111
+ nw_applications (list): Network service applications for the rule.
112
+ app_services (list): IDs for application services for the rule.
113
+ app_service_groups (list): IDs for application service groups.
114
+ departments (list): IDs for departments the rule applies to.
115
+ dest_ip_groups (list): IDs for destination IP groups the rule applies to.
116
+ devices (list): IDs for Zscaler Client Connector managed devices.
117
+ device_groups (list): IDs for device groups managed by Zscaler Client Connector.
118
+ groups (list): IDs for groups the rule applies to.
119
+ labels (list): IDs for labels the rule applies to.
120
+ locations (list): IDs for locations the rule applies to.
121
+ location_groups (list): IDs for location groups the rule applies to.
122
+ nw_application_groups (list): IDs for network application groups.
123
+ nw_services (list): IDs for network services the rule applies to.
124
+ nw_service_groups (list): IDs for network service groups the rule applies to.
125
+ time_windows (list): IDs for time windows the rule applies to.
126
+ users (list): IDs for users the rule applies to.
127
+
128
+ Returns:
129
+ :obj:`Box`: New forwarding control filter rule resource.
130
+
131
+ Examples:
132
+ Forward all traffic to Google DNS:
133
+
134
+ >>> zia.forwarding_control.add_rule(rank='7',
135
+ ... dest_addresses=['8.8.8.8', '8.8.4.4'],
136
+ ... name='FORWARD_ANY_TO_GOOG-DNS',
137
+ ... forward_method='DIRECT',
138
+ ... description='TT#1965432122')
139
+
140
+ Block all traffic to Quad9 DNS for Finance Group:
141
+
142
+ >>> zia.forwarding_control.add_rule(rank='7',
143
+ ... dest_addresses=['9.9.9.9'],
144
+ ... name='BLOCK_FIN_TO_Q9-DNS',
145
+ ... forward_method='DIRECT',
146
+ ... groups=['95016183'],
147
+ ... description='TT#1965432122')
148
+ """
149
+ # Convert enabled to API format if present
150
+ if "enabled" in kwargs:
151
+ kwargs["state"] = "ENABLED" if kwargs.pop("enabled") else "DISABLED"
152
+
153
+ payload = {
154
+ "name": name,
155
+ "forwardMethod": forward_method,
156
+ "order": kwargs.pop("order", len(self.list_rules())),
157
+ }
158
+
159
+ # Transform ID fields in kwargs
160
+ transform_common_id_fields(self.reformat_params, kwargs, payload)
161
+ for key, value in kwargs.items():
162
+ if value is not None:
163
+ payload[snake_to_camel(key)] = value
164
+
165
+ # Convert the entire payload's keys to camelCase before sending
166
+ camel_payload = recursive_snake_to_camel(payload)
167
+ for key, value in kwargs.items():
168
+ if value is not None:
169
+ camel_payload[snake_to_camel(key)] = value
170
+
171
+ # Send POST request to create the rule
172
+ response = self.rest.post("forwardingRules", json=payload)
173
+ if isinstance(response, Response):
174
+ # Handle error response
175
+ status_code = response.status_code
176
+ if status_code != 200:
177
+ raise Exception(
178
+ f"API call failed with status {status_code}: {response.json()}"
179
+ )
180
+ return response
181
+
182
+ def update_rule(self, rule_id: str, **kwargs) -> Box:
183
+ """
184
+ Updates an existing forwarding control filter rule.
185
+
186
+ Args:
187
+ rule_id (str): The unique ID for the rule that is being updated.
188
+ **kwargs: Optional keyword args.
189
+
190
+ Keyword Args:
191
+ order (str): The order of the rule, defaults to adding rule to bottom of list.
192
+ rank (str): The admin rank of the rule.
193
+ state (str): The rule state. Accepted values are 'ENABLED' or 'DISABLED'.
194
+ description (str): Additional information about the rule
195
+ src_ips (list): The source IPs that this rule applies to. Individual IP addresses or CIDR ranges accepted.
196
+ dest_addresses (list): The destination IP addresses that this rule applies to. Individual IP addresses or
197
+ CIDR ranges accepted.
198
+ dest_ip_categories (list): The IP address categories that this rule applies to.
199
+ dest_countries (list): The destination countries that this rule applies to.
200
+ enable_full_logging (bool): Enables full logging if True.
201
+ nw_applications (list): The network service applications that this rule applies to.
202
+ app_services (list): The IDs for the application services that this rule applies to.
203
+ app_service_groups (list): The IDs for the application service groups that this rule applies to.
204
+ departments (list): The IDs for the departments that this rule applies to.
205
+ dest_ip_groups (list): The IDs for the destination IP groups that this rule applies to.
206
+ groups (list): The IDs for the groups that this rule applies to.
207
+ labels (list): The IDs for the labels that this rule applies to.
208
+ locations (list): The IDs for the locations that this rule applies to.
209
+ location_groups (list): The IDs for the location groups that this rule applies to.
210
+ nw_application_groups (list): The IDs for the network application groups that this rule applies to.
211
+ nw_services (list): The IDs for the network services that this rule applies to.
212
+ nw_service_groups (list): The IDs for the network service groups that this rule applies to.
213
+ time_windows (list): The IDs for the time windows that this rule applies to.
214
+ users (list): The IDs for the users that this rule applies to.
215
+
216
+ Returns:
217
+ :obj:`Box`: The updated forwarding control filter rule resource record.
218
+
219
+ Examples:
220
+ Update the destination IP addresses for a rule:
221
+
222
+ >>> zia.forwarding_control.update_rule('976598',
223
+ ... dest_addresses=['1.1.1.1'],
224
+ ... description="TT#1965232865")
225
+
226
+ Update a rule description:
227
+
228
+ >>> zia.forwarding_control.update_rule('976597',
229
+ ... description="TT#1965232866")
230
+
231
+ """
232
+
233
+ # Set payload to value of existing record and convert nested dict keys.
234
+ payload = convert_keys(self.get_rule(rule_id))
235
+
236
+ # Convert enabled to API format if present in kwargs
237
+ if "enabled" in kwargs:
238
+ kwargs["state"] = "ENABLED" if kwargs.pop("enabled") else "DISABLED"
239
+
240
+ # Transform ID fields in kwargs
241
+ transform_common_id_fields(self.reformat_params, kwargs, payload)
242
+
243
+ # Add remaining optional parameters to payload
244
+ for key, value in kwargs.items():
245
+ payload[snake_to_camel(key)] = value
246
+
247
+ response = self.rest.put(f"forwardingRules/{rule_id}", json=payload)
248
+ if isinstance(response, Response) and not response.ok:
249
+ # Handle error response
250
+ raise Exception(
251
+ f"API call failed with status {response.status_code}: {response.json()}"
252
+ )
253
+
254
+ # Return the updated object
255
+ return self.get_rule(rule_id)
256
+
257
+ def delete_rule(self, rule_id: str) -> int:
258
+ """
259
+ Deletes the specified forwarding control filter rule.
260
+
261
+ Args:
262
+ rule_id (str): The unique identifier for the forwarding control filter rule.
263
+
264
+ Returns:
265
+ :obj:`int`: The status code for the operation.
266
+
267
+ Examples:
268
+ >>> zia.forwarding_control.delete_rule('278454')
269
+
270
+ """
271
+ return self.rest.delete(f"forwardingRules/{rule_id}").status_code
@@ -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 BoxList
19
+
20
+ from zscaler.utils import snake_to_camel
21
+ from zscaler.zia.client import ZIAClient
22
+
23
+
24
+ class IsolationProfileAPI:
25
+ def __init__(self, client: ZIAClient):
26
+ self.rest = client
27
+
28
+ def list_isolation_profiles(self, **kwargs) -> BoxList:
29
+ """
30
+ Returns a list of all profiles in the Isolation Profile field for URL Filtering rules and Cloud App Control rules.
31
+
32
+ Args:
33
+ **kwargs: Optional keyword arguments to refine the search query.
34
+
35
+ Returns:
36
+ :obj:`BoxList`: A list of isolation profile resource records.
37
+
38
+ Examples:
39
+ >>> isolation_profiles = zia.isolation_profiles.list_isolation_profiles()
40
+
41
+ """
42
+ payload = {snake_to_camel(key): value for key, value in kwargs.items()}
43
+ return self.rest.get("browserIsolation/profiles", json=payload)
44
+
45
+ def get_profiles_by_name(self, name: str):
46
+ """
47
+ Retrieves a specific isolation profile by its name.
48
+
49
+ Args:
50
+ name (str): The name of the isolation profile to retrieve.
51
+
52
+ Returns:
53
+ :obj:`Box`: The isolation profile if found, otherwise None.
54
+
55
+ Examples:
56
+ >>> profile = zia.isolation_profiles.get_profiles_by_name('Default Isolation')
57
+ ... print(profile)
58
+ """
59
+ profiles = self.list_isolation_profiles()
60
+ for profile in profiles:
61
+ if profile.get("name") == name:
62
+ return profile
63
+ return None
64
+
65
+ def get_profiles_by_id(self, profile_id: str):
66
+ """
67
+ Retrieves a specific isolation profile by its unique identifier.
68
+
69
+ Args:
70
+ profile_id (str): The ID of the isolation profile to retrieve.
71
+
72
+ Returns:
73
+ :obj:`Box`: The isolation profile if found, otherwise None.
74
+
75
+ Examples:
76
+ >>> profile = zia.isolation_profiles.get_profiles_by_id('12345')
77
+ ... print(profile)
78
+ """
79
+ profiles = self.list_isolation_profiles()
80
+ for profile in profiles:
81
+ if profile.get("id") == profile_id:
82
+ return profile
83
+ return None
zscaler/zia/labels.py ADDED
@@ -0,0 +1,180 @@
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.utils import Iterator, convert_keys, snake_to_camel
22
+ from zscaler.zia import ZIAClient
23
+
24
+
25
+ class RuleLabelsAPI:
26
+ def __init__(self, client: ZIAClient):
27
+ self.rest = client
28
+
29
+ def list_labels(self, **kwargs) -> BoxList:
30
+ """
31
+ Returns the list of ZIA Rule Labels.
32
+
33
+ Keyword Args:
34
+ **max_items (int, optional):
35
+ The maximum number of items to request before stopping iteration.
36
+ **max_pages (int, optional):
37
+ The maximum number of pages to request before stopping iteration.
38
+ **page_size (int, optional):
39
+ Specifies the page size. The default size is 100, but the maximum size is 1000.
40
+
41
+ Returns:
42
+ :obj:`BoxList`: The list of Rule Labels configured in ZIA.
43
+
44
+ Examples:
45
+ List Rule Labels using default settings:
46
+
47
+ >>> for label in zia.labels.list_labels():
48
+ ... print(label)
49
+
50
+ List labels, limiting to a maximum of 10 items:
51
+
52
+ >>> for label in zia.labels.list_labels(max_items=10):
53
+ ... print(label)
54
+
55
+ List labels, returning 200 items per page for a maximum of 2 pages:
56
+
57
+ >>> for label in zia.labels.list_labels(page_size=200, max_pages=2):
58
+ ... print(label)
59
+
60
+ """
61
+ return BoxList(Iterator(self.rest, "ruleLabels", **kwargs))
62
+
63
+ def get_label(self, label_id: str) -> Box:
64
+ """
65
+ Returns the label details for a given Rule Label.
66
+
67
+ Args:
68
+ label_id (str): The unique identifier for the Rule Label.
69
+
70
+ Returns:
71
+ :obj:`Box`: The Rule Label resource record.
72
+
73
+ Examples:
74
+ >>> label = zia.labels.get_label('99999')
75
+
76
+ """
77
+ response = self.rest.get("/ruleLabels/%s" % (label_id))
78
+ if isinstance(response, Response):
79
+ status_code = response.status_code
80
+ if status_code != 200:
81
+ return None
82
+ return response
83
+
84
+ def add_label(self, name: str, **kwargs) -> Box:
85
+ """
86
+ Creates a new ZIA Rule Label.
87
+
88
+ Args:
89
+ name (str):
90
+ The name of the Rule Label.
91
+
92
+ Keyword Args:
93
+ description (str):
94
+ Additional information about the Rule Label.
95
+
96
+ Returns:
97
+ :obj:`Box`: The newly added Rule Label resource record.
98
+
99
+ Examples:
100
+ Add a label with default parameters:
101
+
102
+ >>> label = zia.labels.add_label("My New Label")
103
+
104
+ Add a label with description:
105
+
106
+ >>> label = zia.labels.add_label("My Second Label":
107
+ ... description="My second label description")
108
+
109
+ """
110
+ payload = {"name": name}
111
+
112
+ # Add optional parameters to payload
113
+ for key, value in kwargs.items():
114
+ payload[snake_to_camel(key)] = value
115
+
116
+ response = self.rest.post("ruleLabels", json=payload)
117
+ if isinstance(response, Response):
118
+ # this is only true when the creation failed (status code is not 2xx)
119
+ status_code = response.status_code
120
+ # Handle error response
121
+ raise Exception(
122
+ f"API call failed with status {status_code}: {response.json()}"
123
+ )
124
+ return response
125
+
126
+ def update_label(self, label_id: str, **kwargs):
127
+ """
128
+ Updates information for the specified ZIA Rule Label.
129
+
130
+ Args:
131
+ label_id (str): The unique id for the Rule Label that will be updated.
132
+
133
+ Keyword Args:
134
+ name (str): The name of the Rule Label.
135
+ description (str): Additional information for the Rule Label.
136
+
137
+ Returns:
138
+ :obj:`Box`: The updated Rule Label resource record.
139
+
140
+ Examples:
141
+ Update the name of a Rule Label:
142
+
143
+ >>> label = zia.labels.update_label(99999,
144
+ ... name="Updated Label Name")
145
+
146
+ Update the name and description of a Rule Label:
147
+
148
+ >>> label = zia.labels.update_label(99999,
149
+ ... name="Updated Label Name",
150
+ ... description="Updated Label Description")
151
+
152
+ """
153
+ # Get the label data from ZIA
154
+ payload = convert_keys(self.get_label(label_id))
155
+
156
+ # Add optional parameters to payload
157
+ for key, value in kwargs.items():
158
+ payload[snake_to_camel(key)] = value
159
+
160
+ resp = self.rest.put(f"ruleLabels/{label_id}", json=payload)
161
+
162
+ # Return the object if it was updated successfully
163
+ if not isinstance(resp, Response):
164
+ return self.get_label(label_id)
165
+
166
+ def delete_label(self, label_id):
167
+ """
168
+ Deletes the specified Rule Label.
169
+
170
+ Args:
171
+ label_id (str): The unique identifier of the Rule Label that will be deleted.
172
+
173
+ Returns:
174
+ :obj:`int`: The response code for the request.
175
+
176
+ Examples
177
+ >>> user = zia.labels.delete_label('99999')
178
+
179
+ """
180
+ return self.rest.delete(f"ruleLabels/{label_id}").status_code