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.
- zscaler/__init__.py +34 -0
- zscaler/cache/__init__.py +0 -0
- zscaler/cache/cache.py +105 -0
- zscaler/cache/no_op_cache.py +68 -0
- zscaler/cache/zscaler_cache.py +161 -0
- zscaler/constants.py +26 -0
- zscaler/errors/__init__.py +0 -0
- zscaler/errors/error.py +10 -0
- zscaler/errors/http_error.py +20 -0
- zscaler/errors/zscaler_api_error.py +24 -0
- zscaler/exceptions/__init__.py +1 -0
- zscaler/exceptions/exceptions.py +101 -0
- zscaler/logger.py +57 -0
- zscaler/ratelimiter/__init__.py +0 -0
- zscaler/ratelimiter/ratelimiter.py +39 -0
- zscaler/user_agent.py +23 -0
- zscaler/utils.py +577 -0
- zscaler/zia/__init__.py +657 -0
- zscaler/zia/activate.py +52 -0
- zscaler/zia/admin_and_role_management.py +344 -0
- zscaler/zia/apptotal.py +71 -0
- zscaler/zia/audit_logs.py +95 -0
- zscaler/zia/authentication_settings.py +98 -0
- zscaler/zia/client.py +88 -0
- zscaler/zia/cloud_apps.py +406 -0
- zscaler/zia/device_management.py +90 -0
- zscaler/zia/dlp.py +784 -0
- zscaler/zia/errors.py +37 -0
- zscaler/zia/firewall.py +1104 -0
- zscaler/zia/forwarding_control.py +271 -0
- zscaler/zia/isolation_profile.py +83 -0
- zscaler/zia/labels.py +180 -0
- zscaler/zia/locations.py +661 -0
- zscaler/zia/sandbox.py +180 -0
- zscaler/zia/security.py +236 -0
- zscaler/zia/ssl_inspection.py +175 -0
- zscaler/zia/traffic.py +853 -0
- zscaler/zia/url_categories.py +442 -0
- zscaler/zia/url_filtering.py +310 -0
- zscaler/zia/users.py +386 -0
- zscaler/zia/web_dlp.py +295 -0
- zscaler/zia/workload_groups.py +58 -0
- zscaler/zia/zpa_gateway.py +187 -0
- zscaler/zpa/__init__.py +683 -0
- zscaler/zpa/app_segments.py +331 -0
- zscaler/zpa/app_segments_inspection.py +311 -0
- zscaler/zpa/app_segments_pra.py +310 -0
- zscaler/zpa/certificates.py +234 -0
- zscaler/zpa/client.py +113 -0
- zscaler/zpa/cloud_connector_groups.py +75 -0
- zscaler/zpa/connectors.py +518 -0
- zscaler/zpa/emergency_access.py +178 -0
- zscaler/zpa/errors.py +37 -0
- zscaler/zpa/idp.py +83 -0
- zscaler/zpa/inspection.py +1012 -0
- zscaler/zpa/isolation_profile.py +85 -0
- zscaler/zpa/lss.py +568 -0
- zscaler/zpa/machine_groups.py +79 -0
- zscaler/zpa/policies.py +848 -0
- zscaler/zpa/posture_profiles.py +122 -0
- zscaler/zpa/privileged_remote_access.py +862 -0
- zscaler/zpa/provisioning.py +271 -0
- zscaler/zpa/saml_attributes.py +100 -0
- zscaler/zpa/scim_attributes.py +117 -0
- zscaler/zpa/scim_groups.py +146 -0
- zscaler/zpa/segment_groups.py +191 -0
- zscaler/zpa/server_groups.py +217 -0
- zscaler/zpa/servers.py +202 -0
- zscaler/zpa/service_edges.py +404 -0
- zscaler/zpa/trusted_networks.py +127 -0
- zscaler_sdk_python-1.0.0.dist-info/LICENSE.md +21 -0
- zscaler_sdk_python-1.0.0.dist-info/METADATA +59 -0
- zscaler_sdk_python-1.0.0.dist-info/RECORD +75 -0
- zscaler_sdk_python-1.0.0.dist-info/WHEEL +6 -0
- zscaler_sdk_python-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,191 @@
|
|
|
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 snake_to_camel
|
|
22
|
+
|
|
23
|
+
from . import ZPAClient
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SegmentGroupsAPI:
|
|
27
|
+
def __init__(self, client: ZPAClient):
|
|
28
|
+
self.rest = client
|
|
29
|
+
|
|
30
|
+
def list_groups(self, **kwargs) -> BoxList:
|
|
31
|
+
"""
|
|
32
|
+
Returns a list of all configured segment groups.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
:obj:`BoxList`: A list of all configured segment groups.
|
|
36
|
+
|
|
37
|
+
Examples:
|
|
38
|
+
>>> for segment_group in zpa.segment_groups.list_groups():
|
|
39
|
+
... pprint(segment_group)
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
list, _ = self.rest.get_paginated_data(
|
|
43
|
+
path="/segmentGroup", **kwargs, api_version="v1"
|
|
44
|
+
)
|
|
45
|
+
return list
|
|
46
|
+
|
|
47
|
+
def get_group(self, group_id: str) -> Box:
|
|
48
|
+
"""
|
|
49
|
+
Returns information on the specified segment group.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
group_id (str):
|
|
53
|
+
The unique identifier for the segment group.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
:obj:`Box`: The resource record for the segment group.
|
|
57
|
+
|
|
58
|
+
Examples:
|
|
59
|
+
>>> pprint(zpa.segment_groups.get_group('99999'))
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
return self.rest.get(f"segmentGroup/{group_id}")
|
|
63
|
+
|
|
64
|
+
def get_segment_group_by_name(self, name):
|
|
65
|
+
apps = self.list_groups()
|
|
66
|
+
for app in apps:
|
|
67
|
+
if app.get("name") == name:
|
|
68
|
+
return app
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
def add_group(self, name: str, enabled: bool = True, **kwargs) -> Box:
|
|
72
|
+
"""
|
|
73
|
+
Adds a new segment group.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
name (str):
|
|
77
|
+
The name of the new segment group.
|
|
78
|
+
enabled (bool):
|
|
79
|
+
Enable the segment group. Defaults to True.
|
|
80
|
+
**kwargs:
|
|
81
|
+
|
|
82
|
+
Keyword Args:
|
|
83
|
+
application_ids (:obj:`list` of :obj:`dict`):
|
|
84
|
+
Unique application IDs to associate with the segment group.
|
|
85
|
+
config_space (str):
|
|
86
|
+
The config space for the segment group. Can either be DEFAULT or SIEM.
|
|
87
|
+
description (str):
|
|
88
|
+
A description for the segment group.
|
|
89
|
+
policy_migrated (bool):
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
:obj:`Box`: The resource record for the newly created segment group.
|
|
93
|
+
|
|
94
|
+
Examples:
|
|
95
|
+
Creating a segment group with the minimum required parameters:
|
|
96
|
+
|
|
97
|
+
>>> zpa.segment_groups.add_group('new_segment_group',
|
|
98
|
+
... True)
|
|
99
|
+
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
payload = {
|
|
103
|
+
"name": name,
|
|
104
|
+
"enabled": enabled,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if kwargs.get("application_ids"):
|
|
108
|
+
payload["applications"] = [
|
|
109
|
+
{"id": app_id} for app_id in kwargs.pop("application_ids")
|
|
110
|
+
]
|
|
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("segmentGroup", 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_group(self, group_id: str, **kwargs) -> Box:
|
|
127
|
+
"""
|
|
128
|
+
Updates an existing segment group.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
group_id (str):
|
|
132
|
+
The unique identifier for the segment group to be updated.
|
|
133
|
+
**kwargs: Optional keyword args.
|
|
134
|
+
|
|
135
|
+
Keyword Args:
|
|
136
|
+
name (str):
|
|
137
|
+
The name of the new segment group.
|
|
138
|
+
enabled (bool):
|
|
139
|
+
Enable the segment group.
|
|
140
|
+
application_ids (:obj:`list` of :obj:`dict`):
|
|
141
|
+
Unique application IDs to associate with the segment group.
|
|
142
|
+
config_space (str):
|
|
143
|
+
The config space for the segment group. Can either be DEFAULT or SIEM.
|
|
144
|
+
description (str):
|
|
145
|
+
A description for the segment group.
|
|
146
|
+
policy_migrated (bool):
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
:obj:`Box`: The resource record for the updated segment group.
|
|
150
|
+
|
|
151
|
+
Examples:
|
|
152
|
+
Updating the name of a segment group:
|
|
153
|
+
|
|
154
|
+
>>> zpa.segment_groups.update_group('99999',
|
|
155
|
+
... name='updated_name')
|
|
156
|
+
|
|
157
|
+
"""
|
|
158
|
+
# Set payload to value of existing record
|
|
159
|
+
payload = {snake_to_camel(k): v for k, v in self.get_group(group_id).items()}
|
|
160
|
+
|
|
161
|
+
if kwargs.get("application_ids"):
|
|
162
|
+
payload["applications"] = [
|
|
163
|
+
{"id": app_id} for app_id in kwargs.pop("application_ids")
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
# Add optional parameters to payload
|
|
167
|
+
for key, value in kwargs.items():
|
|
168
|
+
payload[snake_to_camel(key)] = value
|
|
169
|
+
|
|
170
|
+
resp = self.rest.put(f"segmentGroup/{group_id}", json=payload).status_code
|
|
171
|
+
|
|
172
|
+
# Return the object if it was updated successfully
|
|
173
|
+
if not isinstance(resp, Response):
|
|
174
|
+
return self.get_group(group_id)
|
|
175
|
+
|
|
176
|
+
def delete_group(self, group_id: str) -> int:
|
|
177
|
+
"""
|
|
178
|
+
Deletes the specified segment group.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
group_id (str):
|
|
182
|
+
The unique identifier for the segment group to be deleted.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
:obj:`int`: The response code for the operation.
|
|
186
|
+
|
|
187
|
+
Examples:
|
|
188
|
+
>>> zpa.segment_groups.delete_group('99999')
|
|
189
|
+
|
|
190
|
+
"""
|
|
191
|
+
return self.rest.delete(f"segmentGroup/{group_id}").status_code
|
|
@@ -0,0 +1,217 @@
|
|
|
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 add_id_groups, snake_to_camel
|
|
21
|
+
from zscaler.zpa.client import ZPAClient
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ServerGroupsAPI:
|
|
25
|
+
reformat_params = [
|
|
26
|
+
("application_ids", "applications"),
|
|
27
|
+
("server_ids", "servers"),
|
|
28
|
+
("app_connector_group_ids", "appConnectorGroups"),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
def __init__(self, client: ZPAClient):
|
|
32
|
+
self.rest = client
|
|
33
|
+
|
|
34
|
+
def list_groups(self, **kwargs) -> BoxList:
|
|
35
|
+
"""
|
|
36
|
+
Returns a list of all configured server groups.
|
|
37
|
+
|
|
38
|
+
Keyword Args:
|
|
39
|
+
**max_items (int):
|
|
40
|
+
The maximum number of items to request before stopping iteration.
|
|
41
|
+
**max_pages (int):
|
|
42
|
+
The maximum number of pages to request before stopping iteration.
|
|
43
|
+
**pagesize (int):
|
|
44
|
+
Specifies the page size. The default size is 20, but the maximum size is 500.
|
|
45
|
+
**search (str, optional):
|
|
46
|
+
The search string used to match against features and fields.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
:obj:`BoxList`: A list of all configured server groups.
|
|
50
|
+
|
|
51
|
+
Examples:
|
|
52
|
+
>>> for server_group in zpa.server_groups.list_groups():
|
|
53
|
+
... pprint(server_group)
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
list, _ = self.rest.get_paginated_data(
|
|
57
|
+
path="/serverGroup", **kwargs, api_version="v1"
|
|
58
|
+
)
|
|
59
|
+
return list
|
|
60
|
+
|
|
61
|
+
def get_group(self, group_id: str) -> Box:
|
|
62
|
+
"""
|
|
63
|
+
Provides information on the specified server group.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
group_id (str):
|
|
67
|
+
The unique id for the server group.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
:obj:`Box`: The resource record for the server group.
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
>>> pprint(zpa.server_groups.get_group('99999'))
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
return self.rest.get(f"serverGroup/{group_id}")
|
|
78
|
+
|
|
79
|
+
def get_server_group_by_name(self, name):
|
|
80
|
+
groups = self.list_groups()
|
|
81
|
+
for group in groups:
|
|
82
|
+
if group.get("name") == name:
|
|
83
|
+
return group
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
def add_group(self, app_connector_group_ids: list, name: str, **kwargs) -> Box:
|
|
87
|
+
"""
|
|
88
|
+
Adds a server group.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
name (str):
|
|
92
|
+
The name for the server group.
|
|
93
|
+
app_connector_group_ids (:obj:`list` of :obj:`str`):
|
|
94
|
+
A list of application connector IDs that will be attached to the server group.
|
|
95
|
+
**kwargs:
|
|
96
|
+
Optional params.
|
|
97
|
+
|
|
98
|
+
Keyword Args:
|
|
99
|
+
application_ids (:obj:`list` of :obj:`str`):
|
|
100
|
+
A list of unique IDs of applications to associate with this server group.
|
|
101
|
+
config_space (str): The configuration space. Accepted values are `DEFAULT` or `SIEM`.
|
|
102
|
+
description (str): Additional information about the server group.
|
|
103
|
+
enabled (bool): Enable the server group.
|
|
104
|
+
ip_anchored (bool): Enable IP Anchoring.
|
|
105
|
+
dynamic_discovery (bool): Enable Dynamic Discovery.
|
|
106
|
+
server_ids (:obj:`list` of :obj:`str`):
|
|
107
|
+
A list of unique IDs of servers to associate with this server group.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
:obj:`Box`: The resource record for the newly created server group.
|
|
111
|
+
|
|
112
|
+
Examples:
|
|
113
|
+
Create a server group with the minimum params:
|
|
114
|
+
|
|
115
|
+
>>> zpa.server_groups.add_group('new_server_group'
|
|
116
|
+
... app_connector_group_ids['99999'])
|
|
117
|
+
|
|
118
|
+
Create a server group and define a new server on the fly:
|
|
119
|
+
|
|
120
|
+
>>> zpa.server_groups.add_group('new_server_group',
|
|
121
|
+
... app_connector_group_ids=['99999'],
|
|
122
|
+
... enabled=True,
|
|
123
|
+
... servers=[{
|
|
124
|
+
... 'name': 'new_server',
|
|
125
|
+
... 'address': '10.0.0.30',
|
|
126
|
+
... 'enabled': True}])
|
|
127
|
+
|
|
128
|
+
"""
|
|
129
|
+
# Initialise payload
|
|
130
|
+
payload = {
|
|
131
|
+
"name": name,
|
|
132
|
+
"appConnectorGroups": [
|
|
133
|
+
{"id": group_id} for group_id in app_connector_group_ids
|
|
134
|
+
],
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
add_id_groups(self.reformat_params, kwargs, payload)
|
|
138
|
+
|
|
139
|
+
# Add optional parameters to payload
|
|
140
|
+
for key, value in kwargs.items():
|
|
141
|
+
payload[snake_to_camel(key)] = value
|
|
142
|
+
|
|
143
|
+
response = self.rest.post("serverGroup", json=payload)
|
|
144
|
+
if isinstance(response, Response):
|
|
145
|
+
# this is only true when the creation failed (status code is not 2xx)
|
|
146
|
+
status_code = response.status_code
|
|
147
|
+
# Handle error response
|
|
148
|
+
raise Exception(
|
|
149
|
+
f"API call failed with status {status_code}: {response.json()}"
|
|
150
|
+
)
|
|
151
|
+
return response
|
|
152
|
+
|
|
153
|
+
def update_group(self, group_id: str, **kwargs) -> Box:
|
|
154
|
+
"""
|
|
155
|
+
Updates a server group.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
group_id (str, required):
|
|
159
|
+
The unique identifier for the server group.
|
|
160
|
+
**kwargs: Optional keyword args.
|
|
161
|
+
|
|
162
|
+
Keyword Args:
|
|
163
|
+
app_connector_group_ids (:obj:`list` of :obj:`str`):
|
|
164
|
+
A list of application connector IDs that will be attached to the server group.
|
|
165
|
+
application_ids (:obj:`list` of :obj:`str`):
|
|
166
|
+
A list of unique IDs of applications to associate with this server group.
|
|
167
|
+
config_space (str): The configuration space. Accepted values are `DEFAULT` or `SIEM`.
|
|
168
|
+
description (str): Additional information about the server group.
|
|
169
|
+
enabled (bool): Enable the server group.
|
|
170
|
+
ip_anchored (bool): Enable IP Anchoring.
|
|
171
|
+
dynamic_discovery (bool): Enable Dynamic Discovery.
|
|
172
|
+
server_ids (:obj:`list` of :obj:`str`):
|
|
173
|
+
A list of unique IDs of servers to associate with this server group
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
:obj:`Box`: The resource record for the updated server group.
|
|
177
|
+
|
|
178
|
+
Examples:
|
|
179
|
+
Update the name of a server group:
|
|
180
|
+
|
|
181
|
+
>>> zpa.server_groups.update_group(name='Updated Name')
|
|
182
|
+
|
|
183
|
+
Enable IP anchoring and Dynamic Discovery:
|
|
184
|
+
|
|
185
|
+
>>> zpa.server_groups.update_group(ip_anchored=True,
|
|
186
|
+
... dynamic_discovery=True)
|
|
187
|
+
|
|
188
|
+
"""
|
|
189
|
+
# Set payload to value of existing record
|
|
190
|
+
payload = {snake_to_camel(k): v for k, v in self.get_group(group_id).items()}
|
|
191
|
+
|
|
192
|
+
add_id_groups(self.reformat_params, kwargs, payload)
|
|
193
|
+
|
|
194
|
+
# Add optional parameters to payload
|
|
195
|
+
for key, value in kwargs.items():
|
|
196
|
+
payload[snake_to_camel(key)] = value
|
|
197
|
+
|
|
198
|
+
resp = self.rest.put(f"serverGroup/{group_id}", json=payload).status_code
|
|
199
|
+
if not isinstance(resp, Response):
|
|
200
|
+
return self.get_group(group_id)
|
|
201
|
+
|
|
202
|
+
def delete_group(self, group_id: str) -> int:
|
|
203
|
+
"""
|
|
204
|
+
Deletes the specified server group.
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
group_id (str):
|
|
208
|
+
The unique id for the server group to be deleted.
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
:obj:`int`: The response code for the operation.
|
|
212
|
+
|
|
213
|
+
Examples:
|
|
214
|
+
>>> zpa.server_groups.delete_group('99999')
|
|
215
|
+
|
|
216
|
+
"""
|
|
217
|
+
return self.rest.delete(f"serverGroup/{group_id}").status_code
|
zscaler/zpa/servers.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 snake_to_camel
|
|
22
|
+
from zscaler.zpa.client import ZPAClient
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AppServersAPI:
|
|
26
|
+
def __init__(self, client: ZPAClient):
|
|
27
|
+
self.rest = client
|
|
28
|
+
|
|
29
|
+
def list_servers(self, **kwargs) -> BoxList:
|
|
30
|
+
"""
|
|
31
|
+
Returns all configured servers.
|
|
32
|
+
|
|
33
|
+
Keyword Args:
|
|
34
|
+
**max_items (int):
|
|
35
|
+
The maximum number of items to request before stopping iteration.
|
|
36
|
+
**max_pages (int):
|
|
37
|
+
The maximum number of pages to request before stopping iteration.
|
|
38
|
+
**pagesize (int):
|
|
39
|
+
Specifies the page size. The default size is 20, but the maximum size is 500.
|
|
40
|
+
**search (str, optional):
|
|
41
|
+
The search string used to match against features and fields.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
:obj:`BoxList`: List of all configured servers.
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
>>> servers = zpa.servers.list_servers()
|
|
48
|
+
"""
|
|
49
|
+
list, _ = self.rest.get_paginated_data(
|
|
50
|
+
path="/server", **kwargs, api_version="v1"
|
|
51
|
+
)
|
|
52
|
+
return list
|
|
53
|
+
|
|
54
|
+
def get_server(self, server_id: str) -> Box:
|
|
55
|
+
"""
|
|
56
|
+
Gets information on the specified server.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
server_id (str):
|
|
60
|
+
The unique identifier for the server.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
:obj:`Box`: The resource record for the server.
|
|
64
|
+
|
|
65
|
+
Examples:
|
|
66
|
+
>>> server = zpa.servers.get_server('99999')
|
|
67
|
+
|
|
68
|
+
"""
|
|
69
|
+
response = self.rest.get("/server/%s" % (server_id))
|
|
70
|
+
if isinstance(response, Response):
|
|
71
|
+
status_code = response.status_code
|
|
72
|
+
if status_code != 200:
|
|
73
|
+
return None
|
|
74
|
+
return response
|
|
75
|
+
|
|
76
|
+
def get_server_by_name(self, name):
|
|
77
|
+
apps = self.list_servers()
|
|
78
|
+
for app in apps:
|
|
79
|
+
if app.get("name") == name:
|
|
80
|
+
return app
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
def add_server(
|
|
84
|
+
self, name: str, address: str, enabled: bool = True, **kwargs
|
|
85
|
+
) -> Box:
|
|
86
|
+
"""
|
|
87
|
+
Add a new application server.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
name (str):
|
|
91
|
+
The name of the server.
|
|
92
|
+
address (str):
|
|
93
|
+
The IP address of the server.
|
|
94
|
+
enabled (bool):
|
|
95
|
+
Enable the server. Defaults to True.
|
|
96
|
+
**kwargs:
|
|
97
|
+
Optional keyword args.
|
|
98
|
+
|
|
99
|
+
Keyword Args:
|
|
100
|
+
description (str):
|
|
101
|
+
A description for the server.
|
|
102
|
+
app_server_group_ids (list):
|
|
103
|
+
Unique identifiers for the server groups the server belongs to.
|
|
104
|
+
config_space (str):
|
|
105
|
+
The configuration space for the server. Defaults to DEFAULT.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
:obj:`Box`: The resource record for the newly created server.
|
|
109
|
+
|
|
110
|
+
Examples:
|
|
111
|
+
Create a server with the minimum required parameters:
|
|
112
|
+
|
|
113
|
+
>>> zpa.servers.add_server(
|
|
114
|
+
... name='myserver.example',
|
|
115
|
+
... address='192.0.2.10',
|
|
116
|
+
... enabled=True)
|
|
117
|
+
|
|
118
|
+
"""
|
|
119
|
+
payload = {"name": name, "address": address, "enabled": enabled}
|
|
120
|
+
|
|
121
|
+
# Add optional parameters to payload
|
|
122
|
+
for key, value in kwargs.items():
|
|
123
|
+
payload[snake_to_camel(key)] = value
|
|
124
|
+
|
|
125
|
+
response = self.rest.post("/server", json=payload)
|
|
126
|
+
if isinstance(response, Response):
|
|
127
|
+
status_code = response.status_code
|
|
128
|
+
if status_code > 299:
|
|
129
|
+
return None
|
|
130
|
+
return self.get_server(response.get("id"))
|
|
131
|
+
|
|
132
|
+
def update_server(self, server_id: str, **kwargs) -> Box:
|
|
133
|
+
"""
|
|
134
|
+
Updates the specified server.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
server_id (str):
|
|
138
|
+
The unique identifier for the server being updated.
|
|
139
|
+
**kwargs:
|
|
140
|
+
Optional keyword args.
|
|
141
|
+
|
|
142
|
+
Keyword Args:
|
|
143
|
+
name (str):
|
|
144
|
+
The name of the server.
|
|
145
|
+
address (str):
|
|
146
|
+
The IP address of the server.
|
|
147
|
+
enabled (bool):
|
|
148
|
+
Enable the server.
|
|
149
|
+
description (str):
|
|
150
|
+
A description for the server.
|
|
151
|
+
app_server_group_ids (list):
|
|
152
|
+
Unique identifiers for the server groups the server belongs to.
|
|
153
|
+
config_space (str):
|
|
154
|
+
The configuration space for the server.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
:obj:`Box`: The resource record for the updated server.
|
|
158
|
+
|
|
159
|
+
Examples:
|
|
160
|
+
Update the name of a server:
|
|
161
|
+
|
|
162
|
+
>>> zpa.servers.update_server(
|
|
163
|
+
... '99999',
|
|
164
|
+
... name='newname.example')
|
|
165
|
+
|
|
166
|
+
Update the address and enable a server:
|
|
167
|
+
|
|
168
|
+
>>> zpa.servers.update_server(
|
|
169
|
+
... '99999',
|
|
170
|
+
... address='192.0.2.20',
|
|
171
|
+
... enabled=True)
|
|
172
|
+
|
|
173
|
+
"""
|
|
174
|
+
# Set payload to value of existing record
|
|
175
|
+
payload = {snake_to_camel(k): v for k, v in self.get_server(server_id).items()}
|
|
176
|
+
|
|
177
|
+
# Add optional parameters to payload
|
|
178
|
+
for key, value in kwargs.items():
|
|
179
|
+
payload[snake_to_camel(key)] = value
|
|
180
|
+
|
|
181
|
+
resp = self.rest.put(f"server/{server_id}", json=payload).status_code
|
|
182
|
+
|
|
183
|
+
if resp == 204:
|
|
184
|
+
return self.get_server(server_id)
|
|
185
|
+
|
|
186
|
+
def delete_server(self, server_id: str) -> int:
|
|
187
|
+
"""
|
|
188
|
+
Delete the specified server.
|
|
189
|
+
|
|
190
|
+
The server must not be assigned to any Server Groups or the operation will fail.
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
server_id (str): The unique identifier for the server to be deleted.
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
:obj:`int`: The response code for the operation.
|
|
197
|
+
|
|
198
|
+
Examples:
|
|
199
|
+
>>> zpa.servers.delete_server('99999')
|
|
200
|
+
|
|
201
|
+
"""
|
|
202
|
+
return self.rest.delete(f"server/{server_id}").status_code
|