CheckmarxPythonSDK 1.9.2__py3-none-any.whl → 1.9.4__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.
- CheckmarxPythonSDK/CxOne/__init__.py +43 -0
- CheckmarxPythonSDK/CxOne/apisecAPI.py +184 -7
- CheckmarxPythonSDK/CxOne/dto/BreakBuildExemptStateDto.py +28 -0
- CheckmarxPythonSDK/CxOne/dto/EnhancedIncidentsPaginationDTO.py +27 -0
- CheckmarxPythonSDK/CxOne/dto/EnhancedIncidentsWebDTO.py +52 -0
- CheckmarxPythonSDK/CxOne/dto/EvaluatedPolicyWebDto.py +34 -0
- CheckmarxPythonSDK/CxOne/dto/ExportParametersSbom.py +10 -0
- CheckmarxPythonSDK/CxOne/dto/ExportParametersScanReport.py +15 -0
- CheckmarxPythonSDK/CxOne/dto/FindingsWebDto.py +46 -0
- CheckmarxPythonSDK/CxOne/dto/IncidentResultWebDTO.py +64 -0
- CheckmarxPythonSDK/CxOne/dto/IncidentResultsDTO.py +36 -0
- CheckmarxPythonSDK/CxOne/dto/IncidentWebDto.py +47 -0
- CheckmarxPythonSDK/CxOne/dto/IncidentsPaginationDto.py +26 -0
- CheckmarxPythonSDK/CxOne/dto/PackageWebDto.py +45 -0
- CheckmarxPythonSDK/CxOne/dto/PoliciesPaginationDto.py +26 -0
- CheckmarxPythonSDK/CxOne/dto/PoliciesResultWebDto.py +31 -0
- CheckmarxPythonSDK/CxOne/dto/PolicyShortWebDto.py +21 -0
- CheckmarxPythonSDK/CxOne/dto/PolicyViolationWebDto.py +36 -0
- CheckmarxPythonSDK/CxOne/dto/PolicyWebDto.py +104 -0
- CheckmarxPythonSDK/CxOne/dto/ProjectWebDto.py +25 -0
- CheckmarxPythonSDK/CxOne/dto/ProjectsInPolicyDto.py +38 -0
- CheckmarxPythonSDK/CxOne/dto/RuleViolatedWebDto.py +35 -0
- CheckmarxPythonSDK/CxOne/dto/ScaExportFileFormats.py +18 -0
- CheckmarxPythonSDK/CxOne/dto/ScaExportStatus.py +23 -0
- CheckmarxPythonSDK/CxOne/dto/ViolatedPolicyWebDto.py +36 -0
- CheckmarxPythonSDK/CxOne/dto/ViolatingAssocProjectsWebDto.py +22 -0
- CheckmarxPythonSDK/CxOne/dto/ViolationDetailsDTO.py +31 -0
- CheckmarxPythonSDK/CxOne/dto/VulnerabilityWebDto.py +31 -0
- CheckmarxPythonSDK/CxOne/dto/__init__.py +26 -0
- CheckmarxPythonSDK/CxOne/policyManagerAPI.py +765 -0
- CheckmarxPythonSDK/CxOne/projectsAPI.py +14 -15
- CheckmarxPythonSDK/CxOne/repoManagerAPI.py +12 -2
- CheckmarxPythonSDK/CxOne/reportAPI.py +362 -58
- CheckmarxPythonSDK/CxOne/scansAPI.py +33 -11
- CheckmarxPythonSDK/CxReporting/api.py +82 -10
- CheckmarxPythonSDK/CxRestAPISDK/ScansAPI.py +40 -2
- CheckmarxPythonSDK/CxScaApiSDK/__init__.py +1 -0
- CheckmarxPythonSDK/CxScaApiSDK/api.py +148 -30
- CheckmarxPythonSDK/__version__.py +1 -1
- CheckmarxPythonSDK/api_client.py +140 -5
- {checkmarxpythonsdk-1.9.2.dist-info → checkmarxpythonsdk-1.9.4.dist-info}/METADATA +1 -1
- {checkmarxpythonsdk-1.9.2.dist-info → checkmarxpythonsdk-1.9.4.dist-info}/RECORD +45 -18
- {checkmarxpythonsdk-1.9.2.dist-info → checkmarxpythonsdk-1.9.4.dist-info}/WHEEL +0 -0
- {checkmarxpythonsdk-1.9.2.dist-info → checkmarxpythonsdk-1.9.4.dist-info}/licenses/LICENSE +0 -0
- {checkmarxpythonsdk-1.9.2.dist-info → checkmarxpythonsdk-1.9.4.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
2
|
+
|
|
3
|
+
from CheckmarxPythonSDK.api_client import ApiClient
|
|
4
|
+
from CheckmarxPythonSDK.CxOne.config import construct_configuration
|
|
5
|
+
from .dto import (
|
|
6
|
+
EnhancedIncidentsPaginationDTO,
|
|
7
|
+
IncidentResultsDTO,
|
|
8
|
+
IncidentsPaginationDto,
|
|
9
|
+
PoliciesPaginationDto,
|
|
10
|
+
PoliciesResultWebDto,
|
|
11
|
+
PolicyShortWebDto,
|
|
12
|
+
PolicyViolationWebDto,
|
|
13
|
+
PolicyWebDto,
|
|
14
|
+
ProjectsInPolicyDto,
|
|
15
|
+
ProjectWebDto,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PolicyManagerAPI(object):
|
|
20
|
+
"""API client for the Cx Policy Manager REST API.
|
|
21
|
+
|
|
22
|
+
Covers tenant policies (break-build rules evaluated against scan
|
|
23
|
+
results), the incidents and results they generate, and the per-scan
|
|
24
|
+
policy evaluation/violation views.
|
|
25
|
+
|
|
26
|
+
Base URL: {server}/api/policy_management_service_uri
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, api_client: ApiClient = None):
|
|
30
|
+
if api_client is None:
|
|
31
|
+
configuration = construct_configuration()
|
|
32
|
+
api_client = ApiClient(configuration=configuration)
|
|
33
|
+
self.api_client = api_client
|
|
34
|
+
self.base_url = (
|
|
35
|
+
f"{self.api_client.configuration.server_base_url}"
|
|
36
|
+
f"/api/policy_management_service_uri"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# =========================================================================
|
|
40
|
+
# Policies
|
|
41
|
+
# =========================================================================
|
|
42
|
+
|
|
43
|
+
def get_tenant_policies(self) -> List[PolicyWebDto]:
|
|
44
|
+
"""Get all policies for the tenant (unpaginated).
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
List[PolicyWebDto]: All tenant policies.
|
|
48
|
+
"""
|
|
49
|
+
url = f"{self.base_url}/policies"
|
|
50
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
51
|
+
return [PolicyWebDto.from_dict(p) for p in response.json()]
|
|
52
|
+
|
|
53
|
+
def create_policy(self, policy: PolicyWebDto) -> int:
|
|
54
|
+
"""Create a new policy.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
policy (PolicyWebDto): The policy to create. `name` is required.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
int: The new policy's ID.
|
|
61
|
+
"""
|
|
62
|
+
url = f"{self.base_url}/policies"
|
|
63
|
+
response = self.api_client.call_api(
|
|
64
|
+
method="POST", url=url, json=policy.to_dict()
|
|
65
|
+
)
|
|
66
|
+
return response.json()
|
|
67
|
+
|
|
68
|
+
def delete_policies(self, ids: List[int]) -> bool:
|
|
69
|
+
"""Delete multiple policies by ID.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
ids (List[int]): IDs of the policies to delete.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
bool: True if the request succeeded.
|
|
76
|
+
"""
|
|
77
|
+
url = f"{self.base_url}/policies"
|
|
78
|
+
params = {"id": ids}
|
|
79
|
+
response = self.api_client.call_api(
|
|
80
|
+
method="DELETE", url=url, params=params
|
|
81
|
+
)
|
|
82
|
+
return response.status_code in (200, 204)
|
|
83
|
+
|
|
84
|
+
def get_policy(self, policy_id: int) -> PolicyWebDto:
|
|
85
|
+
"""Get a policy by ID.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
policy_id (int): The policy ID.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
PolicyWebDto: The policy.
|
|
92
|
+
"""
|
|
93
|
+
url = f"{self.base_url}/policies/{policy_id}"
|
|
94
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
95
|
+
return PolicyWebDto.from_dict(response.json())
|
|
96
|
+
|
|
97
|
+
def update_policy(self, policy_id: int, policy: PolicyWebDto) -> int:
|
|
98
|
+
"""Update an existing policy.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
policy_id (int): The policy ID.
|
|
102
|
+
policy (PolicyWebDto): The new policy content.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
int: The policy's ID.
|
|
106
|
+
"""
|
|
107
|
+
url = f"{self.base_url}/policies/{policy_id}"
|
|
108
|
+
response = self.api_client.call_api(
|
|
109
|
+
method="PUT", url=url, json=policy.to_dict()
|
|
110
|
+
)
|
|
111
|
+
return response.json()
|
|
112
|
+
|
|
113
|
+
def delete_policy(self, policy_id: int) -> bool:
|
|
114
|
+
"""Delete a policy by ID.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
policy_id (int): The policy ID.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
bool: True if the request succeeded.
|
|
121
|
+
"""
|
|
122
|
+
url = f"{self.base_url}/policies/{policy_id}"
|
|
123
|
+
response = self.api_client.call_api(method="DELETE", url=url)
|
|
124
|
+
return response.status_code in (200, 204)
|
|
125
|
+
|
|
126
|
+
def get_policy_v2(self, policy_id: int) -> PolicyWebDto:
|
|
127
|
+
"""Get a policy by ID (V2).
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
policy_id (int): The policy ID.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
PolicyWebDto: The policy.
|
|
134
|
+
"""
|
|
135
|
+
url = f"{self.base_url}/policies/v2/{policy_id}"
|
|
136
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
137
|
+
return PolicyWebDto.from_dict(response.json())
|
|
138
|
+
|
|
139
|
+
def update_policy_v2(self, policy_id: int, policy: PolicyWebDto) -> int:
|
|
140
|
+
"""Update an existing policy (V2).
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
policy_id (int): The policy ID.
|
|
144
|
+
policy (PolicyWebDto): The new policy content.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
int: The policy's ID.
|
|
148
|
+
"""
|
|
149
|
+
url = f"{self.base_url}/policies/v2/{policy_id}"
|
|
150
|
+
response = self.api_client.call_api(
|
|
151
|
+
method="PUT", url=url, json=policy.to_dict()
|
|
152
|
+
)
|
|
153
|
+
return response.json()
|
|
154
|
+
|
|
155
|
+
def get_tenant_policies_with_pagination(
|
|
156
|
+
self, limit: int, page: int, policy_name: str = ""
|
|
157
|
+
) -> PoliciesPaginationDto:
|
|
158
|
+
"""Get tenant policies with pagination.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
limit (int): Page size. 1-1000.
|
|
162
|
+
page (int): Page number (1-based).
|
|
163
|
+
policy_name (str): Filter by policy name. Default: "".
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
PoliciesPaginationDto: Policies on the page, and the filtered total count.
|
|
167
|
+
"""
|
|
168
|
+
url = f"{self.base_url}/policies/v2"
|
|
169
|
+
params = {"limit": limit, "page": page, "policyName": policy_name}
|
|
170
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
171
|
+
return PoliciesPaginationDto.from_dict(response.json())
|
|
172
|
+
|
|
173
|
+
def create_policy_v2(self, policy: PolicyWebDto) -> int:
|
|
174
|
+
"""Create a new policy (V2).
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
policy (PolicyWebDto): The policy to create. `name` is required.
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
int: The new policy's ID. (The spec claims this returns a
|
|
181
|
+
PolicyShortWebDto object; live behavior is a bare int,
|
|
182
|
+
same as POST /policies.)
|
|
183
|
+
"""
|
|
184
|
+
url = f"{self.base_url}/policies/v2"
|
|
185
|
+
response = self.api_client.call_api(
|
|
186
|
+
method="POST", url=url, json=policy.to_dict()
|
|
187
|
+
)
|
|
188
|
+
return response.json()
|
|
189
|
+
|
|
190
|
+
def get_tenant_policies_with_pagination_v3(
|
|
191
|
+
self, limit: int, page: int, policy_name: str = ""
|
|
192
|
+
) -> PoliciesPaginationDto:
|
|
193
|
+
"""Get tenant policies with pagination (V3, path /policies/v3).
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
limit (int): Page size. 1-1000.
|
|
197
|
+
page (int): Page number (1-based).
|
|
198
|
+
policy_name (str): Filter by policy name. Default: "".
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
PoliciesPaginationDto: Policies on the page, and the filtered total count.
|
|
202
|
+
"""
|
|
203
|
+
url = f"{self.base_url}/policies/v3"
|
|
204
|
+
params = {"limit": limit, "page": page, "policyName": policy_name}
|
|
205
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
206
|
+
return PoliciesPaginationDto.from_dict(response.json())
|
|
207
|
+
|
|
208
|
+
def get_default_policy(self) -> Optional[PolicyShortWebDto]:
|
|
209
|
+
"""Get the tenant's default policy.
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
Optional[PolicyShortWebDto]: The default policy's ID and name,
|
|
213
|
+
or None if the tenant has no default policy configured
|
|
214
|
+
(the API responds 200 with an empty body in that case).
|
|
215
|
+
"""
|
|
216
|
+
url = f"{self.base_url}/policies/default"
|
|
217
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
218
|
+
if not response.text:
|
|
219
|
+
return None
|
|
220
|
+
return PolicyShortWebDto.from_dict(response.json())
|
|
221
|
+
|
|
222
|
+
def assign_projects_to_policy(
|
|
223
|
+
self, policy_id: int, projects: ProjectsInPolicyDto
|
|
224
|
+
) -> int:
|
|
225
|
+
"""Assign projects to an existing policy.
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
policy_id (int): The policy ID.
|
|
229
|
+
projects (ProjectsInPolicyDto): Projects to assign.
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
int: The policy's ID.
|
|
233
|
+
"""
|
|
234
|
+
url = f"{self.base_url}/policies/projects/{policy_id}"
|
|
235
|
+
response = self.api_client.call_api(
|
|
236
|
+
method="PUT", url=url, json=projects.to_dict()
|
|
237
|
+
)
|
|
238
|
+
return response.json()
|
|
239
|
+
|
|
240
|
+
def delete_projects_from_policy(
|
|
241
|
+
self, policy_id: int, projects: ProjectsInPolicyDto
|
|
242
|
+
) -> bool:
|
|
243
|
+
"""Remove projects from an existing policy.
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
policy_id (int): The policy ID.
|
|
247
|
+
projects (ProjectsInPolicyDto): Projects to remove.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
bool: True if the request succeeded.
|
|
251
|
+
"""
|
|
252
|
+
url = f"{self.base_url}/policies/projects/{policy_id}"
|
|
253
|
+
response = self.api_client.call_api(
|
|
254
|
+
method="DELETE", url=url, json=projects.to_dict()
|
|
255
|
+
)
|
|
256
|
+
return response.status_code in (200, 204)
|
|
257
|
+
|
|
258
|
+
def pin_policy(self, policy_id: int, pin_policy: bool) -> int:
|
|
259
|
+
"""Pin or unpin a policy in the policies table.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
policy_id (int): The policy ID.
|
|
263
|
+
pin_policy (bool): True to pin, False to unpin.
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
int: The policy's ID.
|
|
267
|
+
"""
|
|
268
|
+
url = f"{self.base_url}/policies/pinPolicy/{policy_id}/{pin_policy}"
|
|
269
|
+
response = self.api_client.call_api(method="PUT", url=url)
|
|
270
|
+
return response.json()
|
|
271
|
+
|
|
272
|
+
# =========================================================================
|
|
273
|
+
# Projects
|
|
274
|
+
# =========================================================================
|
|
275
|
+
|
|
276
|
+
def get_tenant_projects(self) -> List[ProjectWebDto]:
|
|
277
|
+
"""Get all AST projects known to the Policy Manager service.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
List[ProjectWebDto]: Tenant projects.
|
|
281
|
+
"""
|
|
282
|
+
url = f"{self.base_url}/projects"
|
|
283
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
284
|
+
return [ProjectWebDto.from_dict(p) for p in response.json()]
|
|
285
|
+
|
|
286
|
+
def get_projects_tags(self) -> List[str]:
|
|
287
|
+
"""Get all AST project tags known to the Policy Manager service.
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
List[str]: Project tags.
|
|
291
|
+
"""
|
|
292
|
+
url = f"{self.base_url}/projects/tags"
|
|
293
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
294
|
+
return response.json()
|
|
295
|
+
|
|
296
|
+
# =========================================================================
|
|
297
|
+
# Policy violations and evaluation
|
|
298
|
+
# =========================================================================
|
|
299
|
+
|
|
300
|
+
def get_policy_violations(
|
|
301
|
+
self, project_id: str, scan_id: str
|
|
302
|
+
) -> PolicyViolationWebDto:
|
|
303
|
+
"""Get policy violations for a project's scan.
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
project_id (str): The project ID.
|
|
307
|
+
scan_id (str): The scan UUID.
|
|
308
|
+
|
|
309
|
+
Returns:
|
|
310
|
+
PolicyViolationWebDto: Policies violated by the scan.
|
|
311
|
+
"""
|
|
312
|
+
url = f"{self.base_url}/policy_violations"
|
|
313
|
+
params = {"projectId": project_id, "scanId": scan_id}
|
|
314
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
315
|
+
return PolicyViolationWebDto.from_dict(response.json())
|
|
316
|
+
|
|
317
|
+
def get_evaluated_policies_by_scan_id_and_project_id(
|
|
318
|
+
self, scan_id: str, ast_project_id: str
|
|
319
|
+
) -> PoliciesResultWebDto:
|
|
320
|
+
"""Get the policy evaluation result for a scan and project.
|
|
321
|
+
|
|
322
|
+
Args:
|
|
323
|
+
scan_id (str): The scan UUID.
|
|
324
|
+
ast_project_id (str): The project ID.
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
PoliciesResultWebDto: Overall status, breakBuild flag, and
|
|
328
|
+
per-policy evaluation results.
|
|
329
|
+
"""
|
|
330
|
+
url = f"{self.base_url}/evaluation"
|
|
331
|
+
params = {"scanId": scan_id, "astProjectId": ast_project_id}
|
|
332
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
333
|
+
return PoliciesResultWebDto.from_dict(response.json())
|
|
334
|
+
|
|
335
|
+
# =========================================================================
|
|
336
|
+
# Incidents
|
|
337
|
+
# =========================================================================
|
|
338
|
+
|
|
339
|
+
def get_tenant_incidents(self) -> IncidentsPaginationDto:
|
|
340
|
+
"""Get all tenant incidents (unpaginated).
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
IncidentsPaginationDto: Incidents and the filtered total count.
|
|
344
|
+
"""
|
|
345
|
+
url = f"{self.base_url}/incidents"
|
|
346
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
347
|
+
return IncidentsPaginationDto.from_dict(response.json())
|
|
348
|
+
|
|
349
|
+
def get_tenant_incidents_total_count(self) -> int:
|
|
350
|
+
"""Get the tenant's total incident count.
|
|
351
|
+
|
|
352
|
+
Returns:
|
|
353
|
+
int: Total number of incidents.
|
|
354
|
+
"""
|
|
355
|
+
url = f"{self.base_url}/incidents/total"
|
|
356
|
+
response = self.api_client.call_api(method="GET", url=url)
|
|
357
|
+
return response.json()
|
|
358
|
+
|
|
359
|
+
def get_tenant_incidents_with_pagination(
|
|
360
|
+
self, limit: int, page: int, incident_name: str = ""
|
|
361
|
+
) -> IncidentsPaginationDto:
|
|
362
|
+
"""Get tenant incidents with pagination.
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
limit (int): Page size. 1-1000.
|
|
366
|
+
page (int): Page number (1-based).
|
|
367
|
+
incident_name (str): Filter by incident name. Default: "".
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
IncidentsPaginationDto: Incidents on the page, and the filtered
|
|
371
|
+
total count.
|
|
372
|
+
"""
|
|
373
|
+
url = f"{self.base_url}/incidents/"
|
|
374
|
+
params = {"limit": limit, "page": page, "incidentName": incident_name}
|
|
375
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
376
|
+
return IncidentsPaginationDto.from_dict(response.json())
|
|
377
|
+
|
|
378
|
+
def get_tenant_incidents_with_pagination_and_filters(
|
|
379
|
+
self,
|
|
380
|
+
limit: int,
|
|
381
|
+
page: int,
|
|
382
|
+
policy_name: str = "",
|
|
383
|
+
rule_name: str = "",
|
|
384
|
+
scan_id: str = "",
|
|
385
|
+
project_name: str = "",
|
|
386
|
+
branch: str = "",
|
|
387
|
+
scan_date: str = "",
|
|
388
|
+
) -> IncidentsPaginationDto:
|
|
389
|
+
"""Get tenant incidents with pagination and filters.
|
|
390
|
+
|
|
391
|
+
Args:
|
|
392
|
+
limit (int): Page size. 1-1000.
|
|
393
|
+
page (int): Page number (1-based).
|
|
394
|
+
policy_name (str): Filter by policy name. Default: "".
|
|
395
|
+
rule_name (str): Filter by rule name. Default: "".
|
|
396
|
+
scan_id (str): Filter by scan UUID. Default: "".
|
|
397
|
+
project_name (str): Filter by project name. Default: "".
|
|
398
|
+
branch (str): Filter by branch. Default: "".
|
|
399
|
+
scan_date (str): Filter by scan date. Default: "".
|
|
400
|
+
|
|
401
|
+
Returns:
|
|
402
|
+
IncidentsPaginationDto: Incidents on the page, and the filtered
|
|
403
|
+
total count.
|
|
404
|
+
"""
|
|
405
|
+
url = f"{self.base_url}/incidents/filters"
|
|
406
|
+
params = {
|
|
407
|
+
"limit": limit,
|
|
408
|
+
"page": page,
|
|
409
|
+
"policyName": policy_name,
|
|
410
|
+
"ruleName": rule_name,
|
|
411
|
+
"scanId": scan_id,
|
|
412
|
+
"projectName": project_name,
|
|
413
|
+
"branch": branch,
|
|
414
|
+
"scanDate": scan_date,
|
|
415
|
+
}
|
|
416
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
417
|
+
return IncidentsPaginationDto.from_dict(response.json())
|
|
418
|
+
|
|
419
|
+
def get_enhanced_incidents_with_pagination_and_filters(
|
|
420
|
+
self,
|
|
421
|
+
limit: int,
|
|
422
|
+
page: int,
|
|
423
|
+
policy_name: str = "",
|
|
424
|
+
rule_name: str = "",
|
|
425
|
+
scan_id: str = "",
|
|
426
|
+
project_name: str = "",
|
|
427
|
+
branch: str = "",
|
|
428
|
+
scanner: str = "",
|
|
429
|
+
tags: str = "",
|
|
430
|
+
scan_date_from: str = "",
|
|
431
|
+
scan_date_to: str = "",
|
|
432
|
+
sort: str = "",
|
|
433
|
+
sort_field: str = "",
|
|
434
|
+
sort_order: str = "",
|
|
435
|
+
) -> EnhancedIncidentsPaginationDTO:
|
|
436
|
+
"""Get tenant incidents (V2, with engine info) with pagination,
|
|
437
|
+
filters, and sorting.
|
|
438
|
+
|
|
439
|
+
Args:
|
|
440
|
+
limit (int): Page size. Minimum 1.
|
|
441
|
+
page (int): Page number (1-based).
|
|
442
|
+
policy_name (str): Filter by policy name. Default: "".
|
|
443
|
+
rule_name (str): Filter by rule name. Default: "".
|
|
444
|
+
scan_id (str): Filter by scan UUID. Default: "".
|
|
445
|
+
project_name (str): Filter by project name. Default: "".
|
|
446
|
+
branch (str): Filter by branch. Default: "".
|
|
447
|
+
scanner (str): Filter by scanner engine. Default: "".
|
|
448
|
+
tags (str): Filter by policy tags. Default: "".
|
|
449
|
+
scan_date_from (str): Filter by scan date range start. Default: "".
|
|
450
|
+
scan_date_to (str): Filter by scan date range end. Default: "".
|
|
451
|
+
sort (str): Sort direction. Default: "".
|
|
452
|
+
sort_field (str): Field to sort by. Default: "".
|
|
453
|
+
sort_order (str): Sort order. Default: "".
|
|
454
|
+
|
|
455
|
+
Returns:
|
|
456
|
+
EnhancedIncidentsPaginationDTO: Incidents on the page, and the
|
|
457
|
+
filtered total count.
|
|
458
|
+
"""
|
|
459
|
+
url = f"{self.base_url}/incidents/filters/v2"
|
|
460
|
+
params = {
|
|
461
|
+
"limit": limit,
|
|
462
|
+
"page": page,
|
|
463
|
+
"policyName": policy_name,
|
|
464
|
+
"ruleName": rule_name,
|
|
465
|
+
"scanId": scan_id,
|
|
466
|
+
"projectName": project_name,
|
|
467
|
+
"branch": branch,
|
|
468
|
+
"scanner": scanner,
|
|
469
|
+
"tags": tags,
|
|
470
|
+
"scanDateFrom": scan_date_from,
|
|
471
|
+
"scanDateTo": scan_date_to,
|
|
472
|
+
"sort": sort,
|
|
473
|
+
"sortField": sort_field,
|
|
474
|
+
"sortOrder": sort_order,
|
|
475
|
+
}
|
|
476
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
477
|
+
return EnhancedIncidentsPaginationDTO.from_dict(response.json())
|
|
478
|
+
|
|
479
|
+
def get_incident_results(
|
|
480
|
+
self,
|
|
481
|
+
incident_id: int,
|
|
482
|
+
limit: int,
|
|
483
|
+
page: int,
|
|
484
|
+
issue: str = "",
|
|
485
|
+
search: str = "",
|
|
486
|
+
severity: str = "",
|
|
487
|
+
sort_field: str = "severity",
|
|
488
|
+
sort_order: str = "descend",
|
|
489
|
+
) -> IncidentResultsDTO:
|
|
490
|
+
"""Get the results underlying a specific incident.
|
|
491
|
+
|
|
492
|
+
Args:
|
|
493
|
+
incident_id (int): The incident ID.
|
|
494
|
+
limit (int): Page size. Minimum 1.
|
|
495
|
+
page (int): Page number (1-based).
|
|
496
|
+
issue (str): Legacy issue-name filter. Ignored if `search` is
|
|
497
|
+
also provided (a non-blank `search` takes precedence).
|
|
498
|
+
Default: "".
|
|
499
|
+
search (str): Free-text search over the issue name. Takes
|
|
500
|
+
precedence over `issue` when non-blank. Default: "".
|
|
501
|
+
severity (str): Filter by severity. Default: "".
|
|
502
|
+
sort_field (str): Field to sort by. Default: "severity".
|
|
503
|
+
sort_order (str): Sort order. Default: "descend".
|
|
504
|
+
|
|
505
|
+
Returns:
|
|
506
|
+
IncidentResultsDTO: Violation details common to all results,
|
|
507
|
+
the results on the page, and the filtered total count.
|
|
508
|
+
"""
|
|
509
|
+
url = f"{self.base_url}/incidents/{incident_id}/results"
|
|
510
|
+
params = {
|
|
511
|
+
"limit": limit,
|
|
512
|
+
"page": page,
|
|
513
|
+
"issue": issue,
|
|
514
|
+
"search": search,
|
|
515
|
+
"severity": severity,
|
|
516
|
+
"sortField": sort_field,
|
|
517
|
+
"sortOrder": sort_order,
|
|
518
|
+
}
|
|
519
|
+
response = self.api_client.call_api(method="GET", url=url, params=params)
|
|
520
|
+
return IncidentResultsDTO.from_dict(response.json())
|
|
521
|
+
|
|
522
|
+
# =========================================================================
|
|
523
|
+
# Internal data retention
|
|
524
|
+
# =========================================================================
|
|
525
|
+
|
|
526
|
+
def delete_data(self, limitation: int = None) -> bool:
|
|
527
|
+
"""Delete data from all services implementing IDataRetention.
|
|
528
|
+
|
|
529
|
+
Args:
|
|
530
|
+
limitation (int): Maximum number of records to delete, if given.
|
|
531
|
+
|
|
532
|
+
Returns:
|
|
533
|
+
bool: True if the request succeeded.
|
|
534
|
+
"""
|
|
535
|
+
url = f"{self.base_url}/internal/data-retention"
|
|
536
|
+
params = {"limitation": limitation}
|
|
537
|
+
response = self.api_client.call_api(
|
|
538
|
+
method="DELETE", url=url, params=params
|
|
539
|
+
)
|
|
540
|
+
return response.status_code in (200, 204)
|
|
541
|
+
|
|
542
|
+
def delete_data_for_service(
|
|
543
|
+
self, service_name: str, limitation: int = None
|
|
544
|
+
) -> bool:
|
|
545
|
+
"""Delete data from a specific service implementing IDataRetention.
|
|
546
|
+
|
|
547
|
+
Args:
|
|
548
|
+
service_name (str): The service's name.
|
|
549
|
+
limitation (int): Maximum number of records to delete, if given.
|
|
550
|
+
|
|
551
|
+
Returns:
|
|
552
|
+
bool: True if the request succeeded.
|
|
553
|
+
"""
|
|
554
|
+
url = f"{self.base_url}/internal/data-retention/{service_name}"
|
|
555
|
+
params = {"limitation": limitation}
|
|
556
|
+
response = self.api_client.call_api(
|
|
557
|
+
method="DELETE", url=url, params=params
|
|
558
|
+
)
|
|
559
|
+
return response.status_code in (200, 204)
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
# ---- Module-level convenience functions ----
|
|
563
|
+
|
|
564
|
+
def get_tenant_policies() -> List[PolicyWebDto]:
|
|
565
|
+
return PolicyManagerAPI().get_tenant_policies()
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def create_policy(policy: PolicyWebDto) -> int:
|
|
569
|
+
return PolicyManagerAPI().create_policy(policy=policy)
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
def delete_policies(ids: List[int]) -> bool:
|
|
573
|
+
return PolicyManagerAPI().delete_policies(ids=ids)
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
def get_policy(policy_id: int) -> PolicyWebDto:
|
|
577
|
+
return PolicyManagerAPI().get_policy(policy_id=policy_id)
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def update_policy(policy_id: int, policy: PolicyWebDto) -> int:
|
|
581
|
+
return PolicyManagerAPI().update_policy(policy_id=policy_id, policy=policy)
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
def delete_policy(policy_id: int) -> bool:
|
|
585
|
+
return PolicyManagerAPI().delete_policy(policy_id=policy_id)
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def get_policy_v2(policy_id: int) -> PolicyWebDto:
|
|
589
|
+
return PolicyManagerAPI().get_policy_v2(policy_id=policy_id)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def update_policy_v2(policy_id: int, policy: PolicyWebDto) -> int:
|
|
593
|
+
return PolicyManagerAPI().update_policy_v2(policy_id=policy_id, policy=policy)
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def get_tenant_policies_with_pagination(
|
|
597
|
+
limit: int, page: int, policy_name: str = ""
|
|
598
|
+
) -> PoliciesPaginationDto:
|
|
599
|
+
return PolicyManagerAPI().get_tenant_policies_with_pagination(
|
|
600
|
+
limit=limit, page=page, policy_name=policy_name
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def create_policy_v2(policy: PolicyWebDto) -> int:
|
|
605
|
+
return PolicyManagerAPI().create_policy_v2(policy=policy)
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def get_tenant_policies_with_pagination_v3(
|
|
609
|
+
limit: int, page: int, policy_name: str = ""
|
|
610
|
+
) -> PoliciesPaginationDto:
|
|
611
|
+
return PolicyManagerAPI().get_tenant_policies_with_pagination_v3(
|
|
612
|
+
limit=limit, page=page, policy_name=policy_name
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
def get_default_policy() -> Optional[PolicyShortWebDto]:
|
|
617
|
+
return PolicyManagerAPI().get_default_policy()
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def assign_projects_to_policy(
|
|
621
|
+
policy_id: int, projects: ProjectsInPolicyDto
|
|
622
|
+
) -> int:
|
|
623
|
+
return PolicyManagerAPI().assign_projects_to_policy(
|
|
624
|
+
policy_id=policy_id, projects=projects
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def delete_projects_from_policy(
|
|
629
|
+
policy_id: int, projects: ProjectsInPolicyDto
|
|
630
|
+
) -> bool:
|
|
631
|
+
return PolicyManagerAPI().delete_projects_from_policy(
|
|
632
|
+
policy_id=policy_id, projects=projects
|
|
633
|
+
)
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
def pin_policy(policy_id: int, pin_policy_flag: bool) -> int:
|
|
637
|
+
return PolicyManagerAPI().pin_policy(
|
|
638
|
+
policy_id=policy_id, pin_policy=pin_policy_flag
|
|
639
|
+
)
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def get_tenant_projects() -> List[ProjectWebDto]:
|
|
643
|
+
return PolicyManagerAPI().get_tenant_projects()
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def get_projects_tags() -> List[str]:
|
|
647
|
+
return PolicyManagerAPI().get_projects_tags()
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def get_policy_violations(project_id: str, scan_id: str) -> PolicyViolationWebDto:
|
|
651
|
+
return PolicyManagerAPI().get_policy_violations(
|
|
652
|
+
project_id=project_id, scan_id=scan_id
|
|
653
|
+
)
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
def get_evaluated_policies_by_scan_id_and_project_id(
|
|
657
|
+
scan_id: str, ast_project_id: str
|
|
658
|
+
) -> PoliciesResultWebDto:
|
|
659
|
+
return PolicyManagerAPI().get_evaluated_policies_by_scan_id_and_project_id(
|
|
660
|
+
scan_id=scan_id, ast_project_id=ast_project_id
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
def get_tenant_incidents() -> IncidentsPaginationDto:
|
|
665
|
+
return PolicyManagerAPI().get_tenant_incidents()
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
def get_tenant_incidents_total_count() -> int:
|
|
669
|
+
return PolicyManagerAPI().get_tenant_incidents_total_count()
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def get_tenant_incidents_with_pagination(
|
|
673
|
+
limit: int, page: int, incident_name: str = ""
|
|
674
|
+
) -> IncidentsPaginationDto:
|
|
675
|
+
return PolicyManagerAPI().get_tenant_incidents_with_pagination(
|
|
676
|
+
limit=limit, page=page, incident_name=incident_name
|
|
677
|
+
)
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def get_tenant_incidents_with_pagination_and_filters(
|
|
681
|
+
limit: int,
|
|
682
|
+
page: int,
|
|
683
|
+
policy_name: str = "",
|
|
684
|
+
rule_name: str = "",
|
|
685
|
+
scan_id: str = "",
|
|
686
|
+
project_name: str = "",
|
|
687
|
+
branch: str = "",
|
|
688
|
+
scan_date: str = "",
|
|
689
|
+
) -> IncidentsPaginationDto:
|
|
690
|
+
return PolicyManagerAPI().get_tenant_incidents_with_pagination_and_filters(
|
|
691
|
+
limit=limit,
|
|
692
|
+
page=page,
|
|
693
|
+
policy_name=policy_name,
|
|
694
|
+
rule_name=rule_name,
|
|
695
|
+
scan_id=scan_id,
|
|
696
|
+
project_name=project_name,
|
|
697
|
+
branch=branch,
|
|
698
|
+
scan_date=scan_date,
|
|
699
|
+
)
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def get_enhanced_incidents_with_pagination_and_filters(
|
|
703
|
+
limit: int,
|
|
704
|
+
page: int,
|
|
705
|
+
policy_name: str = "",
|
|
706
|
+
rule_name: str = "",
|
|
707
|
+
scan_id: str = "",
|
|
708
|
+
project_name: str = "",
|
|
709
|
+
branch: str = "",
|
|
710
|
+
scanner: str = "",
|
|
711
|
+
tags: str = "",
|
|
712
|
+
scan_date_from: str = "",
|
|
713
|
+
scan_date_to: str = "",
|
|
714
|
+
sort: str = "",
|
|
715
|
+
sort_field: str = "",
|
|
716
|
+
sort_order: str = "",
|
|
717
|
+
) -> EnhancedIncidentsPaginationDTO:
|
|
718
|
+
return PolicyManagerAPI().get_enhanced_incidents_with_pagination_and_filters(
|
|
719
|
+
limit=limit,
|
|
720
|
+
page=page,
|
|
721
|
+
policy_name=policy_name,
|
|
722
|
+
rule_name=rule_name,
|
|
723
|
+
scan_id=scan_id,
|
|
724
|
+
project_name=project_name,
|
|
725
|
+
branch=branch,
|
|
726
|
+
scanner=scanner,
|
|
727
|
+
tags=tags,
|
|
728
|
+
scan_date_from=scan_date_from,
|
|
729
|
+
scan_date_to=scan_date_to,
|
|
730
|
+
sort=sort,
|
|
731
|
+
sort_field=sort_field,
|
|
732
|
+
sort_order=sort_order,
|
|
733
|
+
)
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
def get_incident_results(
|
|
737
|
+
incident_id: int,
|
|
738
|
+
limit: int,
|
|
739
|
+
page: int,
|
|
740
|
+
issue: str = "",
|
|
741
|
+
search: str = "",
|
|
742
|
+
severity: str = "",
|
|
743
|
+
sort_field: str = "severity",
|
|
744
|
+
sort_order: str = "descend",
|
|
745
|
+
) -> IncidentResultsDTO:
|
|
746
|
+
return PolicyManagerAPI().get_incident_results(
|
|
747
|
+
incident_id=incident_id,
|
|
748
|
+
limit=limit,
|
|
749
|
+
page=page,
|
|
750
|
+
issue=issue,
|
|
751
|
+
search=search,
|
|
752
|
+
severity=severity,
|
|
753
|
+
sort_field=sort_field,
|
|
754
|
+
sort_order=sort_order,
|
|
755
|
+
)
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
def delete_data(limitation: int = None) -> bool:
|
|
759
|
+
return PolicyManagerAPI().delete_data(limitation=limitation)
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
def delete_data_for_service(service_name: str, limitation: int = None) -> bool:
|
|
763
|
+
return PolicyManagerAPI().delete_data_for_service(
|
|
764
|
+
service_name=service_name, limitation=limitation
|
|
765
|
+
)
|