1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2018-2021 Greenbone Networks GmbH |
3
|
|
|
# |
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
5
|
|
|
# |
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# This program is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
# pylint: disable=arguments-differ, redefined-builtin, too-many-lines |
20
|
|
|
|
21
|
|
|
""" |
22
|
|
|
Module for communication with gvmd in |
23
|
|
|
`Greenbone Management Protocol version 20.08`_ |
24
|
|
|
|
25
|
|
|
.. _Greenbone Management Protocol version 20.08: |
26
|
|
|
https://docs.greenbone.net/API/GMP/gmp-20.08.html |
27
|
|
|
""" |
28
|
|
|
import collections |
29
|
|
|
import logging |
30
|
|
|
import numbers |
31
|
|
|
|
32
|
|
|
from typing import Any, List, Optional, Callable, Union, Tuple |
33
|
|
|
from lxml import etree |
34
|
|
|
|
35
|
|
|
from gvm.connections import GvmConnection |
36
|
|
|
from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument |
37
|
|
|
from gvm.protocols.base import GvmProtocol |
38
|
|
|
from gvm.protocols.gmpv208.entities.report_formats import ( |
39
|
|
|
ReportFormatType, |
40
|
|
|
) |
41
|
|
|
from gvm.utils import ( |
42
|
|
|
deprecation, |
43
|
|
|
check_command_status, |
44
|
|
|
is_list_like, |
45
|
|
|
to_base64, |
46
|
|
|
to_bool, |
47
|
|
|
to_comma_list, |
48
|
|
|
add_filter, |
49
|
|
|
) |
50
|
|
|
from gvm.xml import XmlCommand |
51
|
|
|
|
52
|
|
|
from . import types |
53
|
|
|
from .types import * # pylint: disable=unused-wildcard-import, wildcard-import |
54
|
|
|
from .types import _UsageType as UsageType |
55
|
|
|
|
56
|
|
|
_EMPTY_POLICY_ID = '085569ce-73ed-11df-83c3-002264764cea' |
57
|
|
|
|
58
|
|
|
PROTOCOL_VERSION = (20, 8) |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
logger = logging.getLogger(__name__) |
62
|
|
|
|
63
|
|
|
Severity = numbers.Real |
64
|
|
|
|
65
|
|
|
# put this into the Alert Entity |
66
|
|
|
def _check_event( |
67
|
|
|
event: AlertEvent, condition: AlertCondition, method: AlertMethod |
68
|
|
|
): |
69
|
|
|
if event == AlertEvent.TASK_RUN_STATUS_CHANGED: |
70
|
|
|
if not condition: |
71
|
|
|
raise RequiredArgument( |
72
|
|
|
"condition is required for event {}".format(event.name) |
73
|
|
|
) |
74
|
|
|
|
75
|
|
|
if not method: |
76
|
|
|
raise RequiredArgument( |
77
|
|
|
"method is required for event {}".format(event.name) |
78
|
|
|
) |
79
|
|
|
|
80
|
|
|
if condition not in ( |
81
|
|
|
AlertCondition.ALWAYS, |
82
|
|
|
AlertCondition.FILTER_COUNT_CHANGED, |
83
|
|
|
AlertCondition.FILTER_COUNT_AT_LEAST, |
84
|
|
|
AlertCondition.SEVERITY_AT_LEAST, |
85
|
|
|
AlertCondition.SEVERITY_CHANGED, |
86
|
|
|
): |
87
|
|
|
raise InvalidArgument( |
88
|
|
|
"Invalid condition {} for event {}".format( |
89
|
|
|
condition.name, event.name |
90
|
|
|
) |
91
|
|
|
) |
92
|
|
|
elif event in ( |
93
|
|
|
AlertEvent.NEW_SECINFO_ARRIVED, |
94
|
|
|
AlertEvent.UPDATED_SECINFO_ARRIVED, |
95
|
|
|
): |
96
|
|
|
if not condition: |
97
|
|
|
raise RequiredArgument( |
98
|
|
|
"condition is required for event {}".format(event.name) |
99
|
|
|
) |
100
|
|
|
|
101
|
|
|
if not method: |
102
|
|
|
raise RequiredArgument( |
103
|
|
|
"method is required for event {}".format(event.name) |
104
|
|
|
) |
105
|
|
|
|
106
|
|
|
if condition != AlertCondition.ALWAYS: |
107
|
|
|
raise InvalidArgument( |
108
|
|
|
"Invalid condition {} for event {}".format( |
109
|
|
|
condition.name, event.name |
110
|
|
|
) |
111
|
|
|
) |
112
|
|
|
if method not in ( |
113
|
|
|
AlertMethod.SCP, |
114
|
|
|
AlertMethod.SEND, |
115
|
|
|
AlertMethod.SMB, |
116
|
|
|
AlertMethod.SNMP, |
117
|
|
|
AlertMethod.SYSLOG, |
118
|
|
|
AlertMethod.EMAIL, |
119
|
|
|
): |
120
|
|
|
raise InvalidArgument( |
121
|
|
|
"Invalid method {} for event {}".format(method.name, event.name) |
122
|
|
|
) |
123
|
|
|
elif event in ( |
124
|
|
|
AlertEvent.TICKET_RECEIVED, |
125
|
|
|
AlertEvent.OWNED_TICKET_CHANGED, |
126
|
|
|
AlertEvent.ASSIGNED_TICKET_CHANGED, |
127
|
|
|
): |
128
|
|
|
if not condition: |
129
|
|
|
raise RequiredArgument( |
130
|
|
|
"condition is required for event {}".format(event.name) |
131
|
|
|
) |
132
|
|
|
|
133
|
|
|
if not method: |
134
|
|
|
raise RequiredArgument( |
135
|
|
|
"method is required for event {}".format(event.name) |
136
|
|
|
) |
137
|
|
|
if condition != AlertCondition.ALWAYS: |
138
|
|
|
raise InvalidArgument( |
139
|
|
|
"Invalid condition {} for event {}".format( |
140
|
|
|
condition.name, event.name |
141
|
|
|
) |
142
|
|
|
) |
143
|
|
|
if method not in ( |
144
|
|
|
AlertMethod.EMAIL, |
145
|
|
|
AlertMethod.START_TASK, |
146
|
|
|
AlertMethod.SYSLOG, |
147
|
|
|
): |
148
|
|
|
raise InvalidArgument( |
149
|
|
|
"Invalid method {} for event {}".format(method.name, event.name) |
150
|
|
|
) |
151
|
|
|
elif event is not None: |
152
|
|
|
raise InvalidArgument('Invalid event "{}"'.format(event.name)) |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
class GmpV208Mixin(GvmProtocol): |
156
|
|
|
"""Python interface for Greenbone Management Protocol |
157
|
|
|
|
158
|
|
|
This class implements the `Greenbone Management Protocol version 20.08`_ |
159
|
|
|
|
160
|
|
|
Arguments: |
161
|
|
|
connection: Connection to use to talk with the gvmd daemon. See |
162
|
|
|
:mod:`gvm.connections` for possible connection types. |
163
|
|
|
transform: Optional transform `callable`_ to convert response data. |
164
|
|
|
After each request the callable gets passed the plain response data |
165
|
|
|
which can be used to check the data and/or conversion into different |
166
|
|
|
representations like a xml dom. |
167
|
|
|
|
168
|
|
|
See :mod:`gvm.transforms` for existing transforms. |
169
|
|
|
|
170
|
|
|
.. _Greenbone Management Protocol version 20.08: |
171
|
|
|
https://docs.greenbone.net/API/GMP/gmp-20.08.html |
172
|
|
|
.. _callable: |
173
|
|
|
https://docs.python.org/3/library/functions.html#callable |
174
|
|
|
""" |
175
|
|
|
|
176
|
|
|
types = types |
|
|
|
|
177
|
|
|
|
178
|
|
|
def __init__( |
179
|
|
|
self, |
180
|
|
|
connection: GvmConnection, |
181
|
|
|
*, |
182
|
|
|
transform: Optional[Callable[[str], Any]] = None, |
183
|
|
|
): |
184
|
|
|
super().__init__(connection, transform=transform) |
185
|
|
|
|
186
|
|
|
# Is authenticated on gvmd |
187
|
|
|
self._authenticated = False |
188
|
|
|
|
189
|
|
|
def is_authenticated(self) -> bool: |
190
|
|
|
"""Checks if the user is authenticated |
191
|
|
|
|
192
|
|
|
If the user is authenticated privileged GMP commands like get_tasks |
193
|
|
|
may be send to gvmd. |
194
|
|
|
|
195
|
|
|
Returns: |
196
|
|
|
bool: True if an authenticated connection to gvmd has been |
197
|
|
|
established. |
198
|
|
|
""" |
199
|
|
|
return self._authenticated |
200
|
|
|
|
201
|
|
|
def authenticate(self, username: str, password: str) -> Any: |
202
|
|
|
"""Authenticate to gvmd. |
203
|
|
|
|
204
|
|
|
The generated authenticate command will be send to server. |
205
|
|
|
Afterwards the response is read, transformed and returned. |
206
|
|
|
|
207
|
|
|
Arguments: |
208
|
|
|
username: Username |
209
|
|
|
password: Password |
210
|
|
|
|
211
|
|
|
Returns: |
212
|
|
|
Transformed response from server. |
213
|
|
|
""" |
214
|
|
|
cmd = XmlCommand("authenticate") |
215
|
|
|
|
216
|
|
|
if not username: |
217
|
|
|
raise RequiredArgument( |
218
|
|
|
function=self.authenticate.__name__, argument='username' |
219
|
|
|
) |
220
|
|
|
|
221
|
|
|
if not password: |
222
|
|
|
raise RequiredArgument( |
223
|
|
|
function=self.authenticate.__name__, argument='password' |
224
|
|
|
) |
225
|
|
|
|
226
|
|
|
credentials = cmd.add_element("credentials") |
227
|
|
|
credentials.add_element("username", username) |
228
|
|
|
credentials.add_element("password", password) |
229
|
|
|
|
230
|
|
|
self._send(cmd.to_string()) |
231
|
|
|
response = self._read() |
232
|
|
|
|
233
|
|
|
if check_command_status(response): |
234
|
|
|
self._authenticated = True |
235
|
|
|
|
236
|
|
|
return self._transform(response) |
237
|
|
|
|
238
|
|
|
def create_alert( |
239
|
|
|
self, |
240
|
|
|
name: str, |
241
|
|
|
condition: AlertCondition, |
242
|
|
|
event: AlertEvent, |
243
|
|
|
method: AlertMethod, |
244
|
|
|
*, |
245
|
|
|
method_data: Optional[dict] = None, |
246
|
|
|
event_data: Optional[dict] = None, |
247
|
|
|
condition_data: Optional[dict] = None, |
248
|
|
|
filter_id: Optional[int] = None, |
249
|
|
|
comment: Optional[str] = None, |
250
|
|
|
) -> Any: |
251
|
|
|
"""Create a new alert |
252
|
|
|
|
253
|
|
|
Arguments: |
254
|
|
|
name: Name of the new Alert |
255
|
|
|
condition: The condition that must be satisfied for the alert |
256
|
|
|
to occur; if the event is either 'Updated SecInfo arrived' or |
257
|
|
|
'New SecInfo arrived', condition must be 'Always'. Otherwise, |
258
|
|
|
condition can also be on of 'Severity at least', 'Filter count |
259
|
|
|
changed' or 'Filter count at least'. |
260
|
|
|
event: The event that must happen for the alert to occur, one |
261
|
|
|
of 'Task run status changed', 'Updated SecInfo arrived' or 'New |
262
|
|
|
SecInfo arrived' |
263
|
|
|
method: The method by which the user is alerted, one of 'SCP', |
264
|
|
|
'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is |
265
|
|
|
neither 'Updated SecInfo arrived' nor 'New SecInfo arrived', |
266
|
|
|
method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire |
267
|
|
|
Connector' or 'verinice Connector'. |
268
|
|
|
condition_data: Data that defines the condition |
269
|
|
|
event_data: Data that defines the event |
270
|
|
|
method_data: Data that defines the method |
271
|
|
|
filter_id: Filter to apply when executing alert |
272
|
|
|
comment: Comment for the alert |
273
|
|
|
|
274
|
|
|
Returns: |
275
|
|
|
The response. See :py:meth:`send_command` for details. |
276
|
|
|
""" |
277
|
|
|
if not name: |
278
|
|
|
raise RequiredArgument( |
279
|
|
|
function=self.create_alert.__name__, argument='name' |
280
|
|
|
) |
281
|
|
|
|
282
|
|
|
if not condition: |
283
|
|
|
raise RequiredArgument( |
284
|
|
|
function=self.create_alert.__name__, argument='condition' |
285
|
|
|
) |
286
|
|
|
|
287
|
|
|
if not event: |
288
|
|
|
raise RequiredArgument( |
289
|
|
|
function=self.create_alert.__name__, argument='event' |
290
|
|
|
) |
291
|
|
|
|
292
|
|
|
if not method: |
293
|
|
|
raise RequiredArgument( |
294
|
|
|
function=self.create_alert.__name__, argument='method' |
295
|
|
|
) |
296
|
|
|
|
297
|
|
|
if not isinstance(condition, AlertCondition): |
298
|
|
|
raise InvalidArgumentType( |
299
|
|
|
function=self.create_alert.__name__, |
300
|
|
|
argument='condition', |
301
|
|
|
arg_type=AlertCondition.__name__, |
302
|
|
|
) |
303
|
|
|
|
304
|
|
|
if not isinstance(event, AlertEvent): |
305
|
|
|
raise InvalidArgumentType( |
306
|
|
|
function=self.create_alert.__name__, |
307
|
|
|
argument='even', |
308
|
|
|
arg_type=AlertEvent.__name__, |
309
|
|
|
) |
310
|
|
|
|
311
|
|
|
if not isinstance(method, AlertMethod): |
312
|
|
|
raise InvalidArgumentType( |
313
|
|
|
function=self.create_alert.__name__, |
314
|
|
|
argument='method', |
315
|
|
|
arg_type=AlertMethod.__name__, |
316
|
|
|
) |
317
|
|
|
|
318
|
|
|
_check_event(event, condition, method) |
319
|
|
|
|
320
|
|
|
cmd = XmlCommand("create_alert") |
321
|
|
|
cmd.add_element("name", name) |
322
|
|
|
|
323
|
|
|
conditions = cmd.add_element("condition", condition.value) |
324
|
|
|
|
325
|
|
|
if condition_data is not None: |
326
|
|
|
for key, value in condition_data.items(): |
327
|
|
|
_data = conditions.add_element("data", value) |
328
|
|
|
_data.add_element("name", key) |
329
|
|
|
|
330
|
|
|
events = cmd.add_element("event", event.value) |
331
|
|
|
|
332
|
|
|
if event_data is not None: |
333
|
|
|
for key, value in event_data.items(): |
334
|
|
|
_data = events.add_element("data", value) |
335
|
|
|
_data.add_element("name", key) |
336
|
|
|
|
337
|
|
|
methods = cmd.add_element("method", method.value) |
338
|
|
|
|
339
|
|
|
if method_data is not None: |
340
|
|
|
for key, value in method_data.items(): |
341
|
|
|
_data = methods.add_element("data", value) |
342
|
|
|
_data.add_element("name", key) |
343
|
|
|
|
344
|
|
|
if filter_id: |
345
|
|
|
cmd.add_element("filter", attrs={"id": filter_id}) |
346
|
|
|
|
347
|
|
|
if comment: |
348
|
|
|
cmd.add_element("comment", comment) |
349
|
|
|
|
350
|
|
|
return self._send_xml_command(cmd) |
351
|
|
|
|
352
|
|
|
def create_audit( |
353
|
|
|
self, |
354
|
|
|
name: str, |
355
|
|
|
policy_id: str, |
356
|
|
|
target_id: str, |
357
|
|
|
scanner_id: str, |
358
|
|
|
*, |
359
|
|
|
alterable: Optional[bool] = None, |
360
|
|
|
hosts_ordering: Optional[HostsOrdering] = None, |
361
|
|
|
schedule_id: Optional[str] = None, |
362
|
|
|
alert_ids: Optional[List[str]] = None, |
363
|
|
|
comment: Optional[str] = None, |
364
|
|
|
schedule_periods: Optional[int] = None, |
365
|
|
|
observers: Optional[List[str]] = None, |
366
|
|
|
preferences: Optional[dict] = None, |
367
|
|
|
) -> Any: |
368
|
|
|
"""Create a new audit task |
369
|
|
|
|
370
|
|
|
Arguments: |
371
|
|
|
name: Name of the new audit |
372
|
|
|
policy_id: UUID of policy to use by the audit |
373
|
|
|
target_id: UUID of target to be scanned |
374
|
|
|
scanner_id: UUID of scanner to use for scanning the target |
375
|
|
|
comment: Comment for the audit |
376
|
|
|
alterable: Whether the task should be alterable |
377
|
|
|
alert_ids: List of UUIDs for alerts to be applied to the audit |
378
|
|
|
hosts_ordering: The order hosts are scanned in |
379
|
|
|
schedule_id: UUID of a schedule when the audit should be run. |
380
|
|
|
schedule_periods: A limit to the number of times the audit will be |
381
|
|
|
scheduled, or 0 for no limit |
382
|
|
|
observers: List of names or ids of users which should be allowed to |
383
|
|
|
observe this audit |
384
|
|
|
preferences: Name/Value pairs of scanner preferences. |
385
|
|
|
|
386
|
|
|
Returns: |
387
|
|
|
The response. See :py:meth:`send_command` for details. |
388
|
|
|
""" |
389
|
|
|
|
390
|
|
|
return self.__create_task( |
391
|
|
|
name=name, |
392
|
|
|
config_id=policy_id, |
393
|
|
|
target_id=target_id, |
394
|
|
|
scanner_id=scanner_id, |
395
|
|
|
usage_type=UsageType.AUDIT, |
396
|
|
|
function=self.create_audit.__name__, |
397
|
|
|
alterable=alterable, |
398
|
|
|
hosts_ordering=hosts_ordering, |
399
|
|
|
schedule_id=schedule_id, |
400
|
|
|
alert_ids=alert_ids, |
401
|
|
|
comment=comment, |
402
|
|
|
schedule_periods=schedule_periods, |
403
|
|
|
observers=observers, |
404
|
|
|
preferences=preferences, |
405
|
|
|
) |
406
|
|
|
|
407
|
|
|
def create_config( |
408
|
|
|
self, config_id: str, name: str, *, comment: Optional[str] = None |
409
|
|
|
) -> Any: |
410
|
|
|
"""Create a new scan config |
411
|
|
|
|
412
|
|
|
Arguments: |
413
|
|
|
config_id: UUID of the existing scan config |
414
|
|
|
name: Name of the new scan config |
415
|
|
|
comment: A comment on the config |
416
|
|
|
|
417
|
|
|
Returns: |
418
|
|
|
The response. See :py:meth:`send_command` for details. |
419
|
|
|
""" |
420
|
|
|
return self.__create_config( |
421
|
|
|
config_id=config_id, |
422
|
|
|
name=name, |
423
|
|
|
comment=comment, |
424
|
|
|
usage_type=UsageType.SCAN, |
425
|
|
|
function=self.create_config.__name__, |
426
|
|
|
) |
427
|
|
|
|
428
|
|
|
def create_config_from_osp_scanner( |
429
|
|
|
self, scanner_id: str, name: str, *, comment: Optional[str] = None |
430
|
|
|
) -> Any: |
431
|
|
|
"""Create a new scan config from an ospd scanner. |
432
|
|
|
|
433
|
|
|
Create config by retrieving the expected preferences from the given |
434
|
|
|
scanner via OSP. |
435
|
|
|
|
436
|
|
|
Arguments: |
437
|
|
|
scanner_id: UUID of an OSP scanner to get config data from |
438
|
|
|
name: Name of the new scan config |
439
|
|
|
comment: A comment on the config |
440
|
|
|
|
441
|
|
|
Returns: |
442
|
|
|
The response. See :py:meth:`send_command` for details. |
443
|
|
|
""" |
444
|
|
|
return self.__create_config_from_osp_scanner( |
445
|
|
|
scanner_id=scanner_id, |
446
|
|
|
name=name, |
447
|
|
|
comment=comment, |
448
|
|
|
usage_type=UsageType.SCAN, |
449
|
|
|
function=self.create_config.__name__, |
450
|
|
|
) |
451
|
|
|
|
452
|
|
|
def create_permission( |
453
|
|
|
self, |
454
|
|
|
name: str, |
455
|
|
|
subject_id: str, |
456
|
|
|
subject_type: PermissionSubjectType, |
457
|
|
|
*, |
458
|
|
|
resource_id: Optional[str] = None, |
459
|
|
|
resource_type: Optional[EntityType] = None, |
460
|
|
|
comment: Optional[str] = None, |
461
|
|
|
) -> Any: |
462
|
|
|
"""Create a new permission |
463
|
|
|
|
464
|
|
|
Arguments: |
465
|
|
|
name: Name of the new permission |
466
|
|
|
subject_id: UUID of subject to whom the permission is granted |
467
|
|
|
subject_type: Type of the subject user, group or role |
468
|
|
|
comment: Comment for the permission |
469
|
|
|
resource_id: UUID of entity to which the permission applies |
470
|
|
|
resource_type: Type of the resource. For Super permissions user, |
471
|
|
|
group or role |
472
|
|
|
|
473
|
|
|
Returns: |
474
|
|
|
The response. See :py:meth:`send_command` for details. |
475
|
|
|
""" |
476
|
|
|
if not name: |
477
|
|
|
raise RequiredArgument( |
478
|
|
|
function=self.create_permission.__name__, argument='name' |
479
|
|
|
) |
480
|
|
|
|
481
|
|
|
if not subject_id: |
482
|
|
|
raise RequiredArgument( |
483
|
|
|
function=self.create_permission.__name__, argument='subject_id' |
484
|
|
|
) |
485
|
|
|
|
486
|
|
|
if not isinstance(subject_type, PermissionSubjectType): |
487
|
|
|
raise InvalidArgumentType( |
488
|
|
|
function=self.create_permission.__name__, |
489
|
|
|
argument='subject_type', |
490
|
|
|
arg_type=PermissionSubjectType.__name__, |
491
|
|
|
) |
492
|
|
|
|
493
|
|
|
cmd = XmlCommand("create_permission") |
494
|
|
|
cmd.add_element("name", name) |
495
|
|
|
|
496
|
|
|
_xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
497
|
|
|
_xmlsubject.add_element("type", subject_type.value) |
498
|
|
|
|
499
|
|
|
if comment: |
500
|
|
|
cmd.add_element("comment", comment) |
501
|
|
|
|
502
|
|
View Code Duplication |
if resource_id or resource_type: |
|
|
|
|
503
|
|
|
if not resource_id: |
504
|
|
|
raise RequiredArgument( |
505
|
|
|
function=self.create_permission.__name__, |
506
|
|
|
argument='resource_id', |
507
|
|
|
) |
508
|
|
|
|
509
|
|
|
if not resource_type: |
510
|
|
|
raise RequiredArgument( |
511
|
|
|
function=self.create_permission.__name__, |
512
|
|
|
argument='resource_type', |
513
|
|
|
) |
514
|
|
|
|
515
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
516
|
|
|
raise InvalidArgumentType( |
517
|
|
|
function=self.create_permission.__name__, |
518
|
|
|
argument='resource_type', |
519
|
|
|
arg_type=self.types.EntityType.__name__, |
520
|
|
|
) |
521
|
|
|
|
522
|
|
|
_xmlresource = cmd.add_element( |
523
|
|
|
"resource", attrs={"id": resource_id} |
524
|
|
|
) |
525
|
|
|
|
526
|
|
|
_actual_resource_type = resource_type |
527
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
528
|
|
|
_actual_resource_type = EntityType.TASK |
529
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
530
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
531
|
|
|
|
532
|
|
|
_xmlresource.add_element("type", _actual_resource_type.value) |
533
|
|
|
|
534
|
|
|
return self._send_xml_command(cmd) |
535
|
|
|
|
536
|
|
|
def create_policy( |
537
|
|
|
self, name: str, *, policy_id: str = None, comment: Optional[str] = None |
538
|
|
|
) -> Any: |
539
|
|
|
"""Create a new policy config |
540
|
|
|
|
541
|
|
|
Arguments: |
542
|
|
|
name: Name of the new policy |
543
|
|
|
policy_id: UUID of an existing policy as base. By default the empty |
544
|
|
|
policy is used. |
545
|
|
|
comment: A comment on the policy |
546
|
|
|
|
547
|
|
|
Returns: |
548
|
|
|
The response. See :py:meth:`send_command` for details. |
549
|
|
|
""" |
550
|
|
|
if policy_id is None: |
551
|
|
|
policy_id = _EMPTY_POLICY_ID |
552
|
|
|
return self.__create_config( |
553
|
|
|
config_id=policy_id, |
554
|
|
|
name=name, |
555
|
|
|
comment=comment, |
556
|
|
|
usage_type=UsageType.POLICY, |
557
|
|
|
function=self.create_policy.__name__, |
558
|
|
|
) |
559
|
|
|
|
560
|
|
|
def create_tag( |
561
|
|
|
self, |
562
|
|
|
name: str, |
563
|
|
|
resource_type: EntityType, |
564
|
|
|
*, |
565
|
|
|
resource_filter: Optional[str] = None, |
566
|
|
|
resource_ids: Optional[List[str]] = None, |
567
|
|
|
value: Optional[str] = None, |
568
|
|
|
comment: Optional[str] = None, |
569
|
|
|
active: Optional[bool] = None, |
570
|
|
|
) -> Any: |
571
|
|
|
"""Create a tag. |
572
|
|
|
|
573
|
|
|
Arguments: |
574
|
|
|
name: Name of the tag. A full tag name consisting of namespace and |
575
|
|
|
predicate e.g. `foo:bar`. |
576
|
|
|
resource_type: Entity type the tag is to be attached to. |
577
|
|
|
resource_filter: Filter term to select resources the tag is to be |
578
|
|
|
attached to. Only one of resource_filter or resource_ids can be |
579
|
|
|
provided. |
580
|
|
|
resource_ids: IDs of the resources the tag is to be attached to. |
581
|
|
|
Only one of resource_filter or resource_ids can be provided. |
582
|
|
|
value: Value associated with the tag. |
583
|
|
|
comment: Comment for the tag. |
584
|
|
|
active: Whether the tag should be active. |
585
|
|
|
|
586
|
|
|
Returns: |
587
|
|
|
The response. See :py:meth:`send_command` for details. |
588
|
|
|
""" |
589
|
|
|
if not name: |
590
|
|
|
raise RequiredArgument( |
591
|
|
|
function=self.create_tag.__name__, argument='name' |
592
|
|
|
) |
593
|
|
|
|
594
|
|
|
if resource_filter and resource_ids: |
595
|
|
|
raise InvalidArgument( |
596
|
|
|
"create_tag accepts either resource_filter or resource_ids " |
597
|
|
|
"argument", |
598
|
|
|
function=self.create_tag.__name__, |
599
|
|
|
) |
600
|
|
|
|
601
|
|
|
if not resource_type: |
602
|
|
|
raise RequiredArgument( |
603
|
|
|
function=self.create_tag.__name__, argument='resource_type' |
604
|
|
|
) |
605
|
|
|
|
606
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
607
|
|
|
raise InvalidArgumentType( |
608
|
|
|
function=self.create_tag.__name__, |
609
|
|
|
argument='resource_type', |
610
|
|
|
arg_type=EntityType.__name__, |
611
|
|
|
) |
612
|
|
|
|
613
|
|
|
cmd = XmlCommand('create_tag') |
614
|
|
|
cmd.add_element('name', name) |
615
|
|
|
|
616
|
|
|
_xmlresources = cmd.add_element("resources") |
617
|
|
|
if resource_filter is not None: |
618
|
|
|
_xmlresources.set_attribute("filter", resource_filter) |
619
|
|
|
|
620
|
|
|
for resource_id in resource_ids or []: |
621
|
|
|
_xmlresources.add_element( |
622
|
|
|
"resource", attrs={"id": str(resource_id)} |
623
|
|
|
) |
624
|
|
|
|
625
|
|
|
_actual_resource_type = resource_type |
626
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
627
|
|
|
_actual_resource_type = EntityType.TASK |
628
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
629
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
630
|
|
|
_xmlresources.add_element("type", _actual_resource_type.value) |
631
|
|
|
|
632
|
|
|
if comment: |
633
|
|
|
cmd.add_element("comment", comment) |
634
|
|
|
|
635
|
|
|
if value: |
636
|
|
|
cmd.add_element("value", value) |
637
|
|
|
|
638
|
|
|
if active is not None: |
639
|
|
|
if active: |
640
|
|
|
cmd.add_element("active", "1") |
641
|
|
|
else: |
642
|
|
|
cmd.add_element("active", "0") |
643
|
|
|
|
644
|
|
|
return self._send_xml_command(cmd) |
645
|
|
|
|
646
|
|
View Code Duplication |
def create_tls_certificate( |
|
|
|
|
647
|
|
|
self, |
648
|
|
|
name: str, |
649
|
|
|
certificate: str, |
650
|
|
|
*, |
651
|
|
|
comment: Optional[str] = None, |
652
|
|
|
trust: Optional[bool] = None, |
653
|
|
|
) -> Any: |
654
|
|
|
"""Create a new TLS certificate |
655
|
|
|
|
656
|
|
|
Arguments: |
657
|
|
|
name: Name of the TLS certificate, defaulting to the MD5 |
658
|
|
|
fingerprint. |
659
|
|
|
certificate: The Base64 encoded certificate data (x.509 DER or PEM). |
660
|
|
|
comment: Comment for the TLS certificate. |
661
|
|
|
trust: Whether the certificate is trusted. |
662
|
|
|
|
663
|
|
|
Returns: |
664
|
|
|
The response. See :py:meth:`send_command` for details. |
665
|
|
|
""" |
666
|
|
|
if not name: |
667
|
|
|
raise RequiredArgument( |
668
|
|
|
function=self.create_tls_certificate.__name__, argument='name' |
669
|
|
|
) |
670
|
|
|
if not certificate: |
671
|
|
|
raise RequiredArgument( |
672
|
|
|
function=self.create_tls_certificate.__name__, |
673
|
|
|
argument='certificate', |
674
|
|
|
) |
675
|
|
|
|
676
|
|
|
cmd = XmlCommand("create_tls_certificate") |
677
|
|
|
|
678
|
|
|
if comment: |
679
|
|
|
cmd.add_element("comment", comment) |
680
|
|
|
|
681
|
|
|
cmd.add_element("name", name) |
682
|
|
|
cmd.add_element("certificate", certificate) |
683
|
|
|
|
684
|
|
|
if trust: |
685
|
|
|
cmd.add_element("trust", to_bool(trust)) |
686
|
|
|
|
687
|
|
|
return self._send_xml_command(cmd) |
688
|
|
|
|
689
|
|
|
def get_aggregates( |
690
|
|
|
self, |
691
|
|
|
resource_type: EntityType, |
692
|
|
|
*, |
693
|
|
|
filter: Optional[str] = None, |
694
|
|
|
filter_id: Optional[str] = None, |
695
|
|
|
sort_criteria: Optional[list] = None, |
696
|
|
|
data_columns: Optional[list] = None, |
697
|
|
|
group_column: Optional[str] = None, |
698
|
|
|
subgroup_column: Optional[str] = None, |
699
|
|
|
text_columns: Optional[list] = None, |
700
|
|
|
first_group: Optional[int] = None, |
701
|
|
|
max_groups: Optional[int] = None, |
702
|
|
|
mode: Optional[int] = None, |
703
|
|
|
**kwargs, |
704
|
|
|
) -> Any: |
705
|
|
|
"""Request aggregated information on a resource / entity type |
706
|
|
|
|
707
|
|
|
Additional arguments can be set via the kwargs parameter for backward |
708
|
|
|
compatibility with older versions of python-gvm, but are not validated. |
709
|
|
|
|
710
|
|
|
Arguments: |
711
|
|
|
resource_type: The entity type to gather data from |
712
|
|
|
filter: Filter term to use for the query |
713
|
|
|
filter_id: UUID of an existing filter to use for the query |
714
|
|
|
sort_criteria: List of sort criteria (dicts that can contain |
715
|
|
|
a field, stat and order) |
716
|
|
|
data_columns: List of fields to aggregate data from |
717
|
|
|
group_column: The field to group the entities by |
718
|
|
|
subgroup_column: The field to further group the entities |
719
|
|
|
inside groups by |
720
|
|
|
text_columns: List of simple text columns which no statistics |
721
|
|
|
are calculated for |
722
|
|
|
first_group: The index of the first aggregate group to return |
723
|
|
|
max_groups: The maximum number of aggregate groups to return, |
724
|
|
|
-1 for all |
725
|
|
|
mode: Special mode for aggregation |
726
|
|
|
|
727
|
|
|
Returns: |
728
|
|
|
The response. See :py:meth:`send_command` for details. |
729
|
|
|
""" |
730
|
|
|
if not resource_type: |
731
|
|
|
raise RequiredArgument( |
732
|
|
|
function=self.get_aggregates.__name__, argument='resource_type' |
733
|
|
|
) |
734
|
|
|
|
735
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
736
|
|
|
raise InvalidArgumentType( |
737
|
|
|
function=self.get_aggregates.__name__, |
738
|
|
|
argument='resource_type', |
739
|
|
|
arg_type=self.types.EntityType.__name__, |
740
|
|
|
) |
741
|
|
|
|
742
|
|
|
cmd = XmlCommand('get_aggregates') |
743
|
|
|
|
744
|
|
|
_actual_resource_type = resource_type |
745
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
746
|
|
|
_actual_resource_type = EntityType.TASK |
747
|
|
|
cmd.set_attribute('usage_type', 'audit') |
748
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
749
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
750
|
|
|
cmd.set_attribute('usage_type', 'policy') |
751
|
|
|
elif resource_type.value == EntityType.SCAN_CONFIG.value: |
752
|
|
|
cmd.set_attribute('usage_type', 'scan') |
753
|
|
|
elif resource_type.value == EntityType.TASK.value: |
754
|
|
|
cmd.set_attribute('usage_type', 'scan') |
755
|
|
|
cmd.set_attribute('type', _actual_resource_type.value) |
756
|
|
|
|
757
|
|
|
add_filter(cmd, filter, filter_id) |
758
|
|
|
|
759
|
|
|
if first_group is not None: |
760
|
|
|
if not isinstance(first_group, int): |
761
|
|
|
raise InvalidArgumentType( |
762
|
|
|
function=self.get_aggregates.__name__, |
763
|
|
|
argument='first_group', |
764
|
|
|
arg_type=int.__name__, |
765
|
|
|
) |
766
|
|
|
cmd.set_attribute('first_group', str(first_group)) |
767
|
|
|
|
768
|
|
|
if max_groups is not None: |
769
|
|
|
if not isinstance(max_groups, int): |
770
|
|
|
raise InvalidArgumentType( |
771
|
|
|
function=self.get_aggregates.__name__, |
772
|
|
|
argument='max_groups', |
773
|
|
|
arg_type=int.__name__, |
774
|
|
|
) |
775
|
|
|
cmd.set_attribute('max_groups', str(max_groups)) |
776
|
|
|
|
777
|
|
|
if sort_criteria is not None: |
778
|
|
|
if not isinstance(sort_criteria, list): |
779
|
|
|
raise InvalidArgumentType( |
780
|
|
|
function=self.get_aggregates.__name__, |
781
|
|
|
argument='sort_criteria', |
782
|
|
|
arg_type=list.__name__, |
783
|
|
|
) |
784
|
|
|
for sort in sort_criteria: |
785
|
|
|
if not isinstance(sort, dict): |
786
|
|
|
raise InvalidArgumentType( |
787
|
|
|
function=self.get_aggregates.__name__, |
788
|
|
|
argument='sort_criteria', |
789
|
|
|
) |
790
|
|
|
|
791
|
|
|
sort_elem = cmd.add_element('sort') |
792
|
|
|
if sort.get('field'): |
793
|
|
|
sort_elem.set_attribute('field', sort.get('field')) |
794
|
|
|
|
795
|
|
|
if sort.get('stat'): |
796
|
|
|
if isinstance(sort['stat'], AggregateStatistic): |
797
|
|
|
sort_elem.set_attribute('stat', sort['stat'].value) |
798
|
|
|
else: |
799
|
|
|
stat = get_aggregate_statistic_from_string(sort['stat']) |
800
|
|
|
sort_elem.set_attribute('stat', stat.value) |
801
|
|
|
|
802
|
|
|
if sort.get('order'): |
803
|
|
|
if isinstance(sort['order'], SortOrder): |
804
|
|
|
sort_elem.set_attribute('order', sort['order'].value) |
805
|
|
|
else: |
806
|
|
|
so = get_sort_order_from_string(sort['order']) |
807
|
|
|
sort_elem.set_attribute('order', so.value) |
808
|
|
|
|
809
|
|
|
if data_columns is not None: |
810
|
|
|
if not isinstance(data_columns, list): |
811
|
|
|
raise InvalidArgumentType( |
812
|
|
|
function=self.get_aggregates.__name__, |
813
|
|
|
argument='data_columns', |
814
|
|
|
arg_type=list.__name__, |
815
|
|
|
) |
816
|
|
|
for column in data_columns: |
817
|
|
|
cmd.add_element('data_column', column) |
818
|
|
|
|
819
|
|
|
if group_column is not None: |
820
|
|
|
cmd.set_attribute('group_column', group_column) |
821
|
|
|
|
822
|
|
|
if subgroup_column is not None: |
823
|
|
|
if not group_column: |
824
|
|
|
raise RequiredArgument( |
825
|
|
|
'{} requires a group_column argument' |
826
|
|
|
' if subgroup_column is given'.format( |
827
|
|
|
self.get_aggregates.__name__ |
828
|
|
|
), |
829
|
|
|
function=self.get_aggregates.__name__, |
830
|
|
|
argument='subgroup_column', |
831
|
|
|
) |
832
|
|
|
cmd.set_attribute('subgroup_column', subgroup_column) |
833
|
|
|
|
834
|
|
|
if text_columns is not None: |
835
|
|
|
if not isinstance(text_columns, list): |
836
|
|
|
raise InvalidArgumentType( |
837
|
|
|
function=self.get_aggregates.__name__, |
838
|
|
|
argument='text_columns', |
839
|
|
|
arg_type=list.__name__, |
840
|
|
|
) |
841
|
|
|
for column in text_columns: |
842
|
|
|
cmd.add_element('text_column', column) |
843
|
|
|
|
844
|
|
|
if mode is not None: |
845
|
|
|
cmd.set_attribute('mode', mode) |
846
|
|
|
|
847
|
|
|
# Add additional keyword args as attributes for backward compatibility. |
848
|
|
|
cmd.set_attributes(kwargs) |
849
|
|
|
|
850
|
|
|
return self._send_xml_command(cmd) |
851
|
|
|
|
852
|
|
View Code Duplication |
def get_tls_certificates( |
|
|
|
|
853
|
|
|
self, |
854
|
|
|
*, |
855
|
|
|
filter: Optional[str] = None, |
856
|
|
|
filter_id: Optional[str] = None, |
857
|
|
|
include_certificate_data: Optional[bool] = None, |
858
|
|
|
details: Optional[bool] = None, |
859
|
|
|
) -> Any: |
860
|
|
|
"""Request a list of TLS certificates |
861
|
|
|
|
862
|
|
|
Arguments: |
863
|
|
|
filter: Filter term to use for the query |
864
|
|
|
filter_id: UUID of an existing filter to use for the query |
865
|
|
|
include_certificate_data: Whether to include the certificate data in |
866
|
|
|
the response |
867
|
|
|
|
868
|
|
|
Returns: |
869
|
|
|
The response. See :py:meth:`send_command` for details. |
870
|
|
|
""" |
871
|
|
|
|
872
|
|
|
cmd = XmlCommand("get_tls_certificates") |
873
|
|
|
|
874
|
|
|
add_filter(cmd, filter, filter_id) |
875
|
|
|
|
876
|
|
|
if details is not None: |
877
|
|
|
cmd.set_attribute("details", to_bool(details)) |
878
|
|
|
|
879
|
|
|
if include_certificate_data is not None: |
880
|
|
|
cmd.set_attribute( |
881
|
|
|
"include_certificate_data", to_bool(include_certificate_data) |
882
|
|
|
) |
883
|
|
|
|
884
|
|
|
return self._send_xml_command(cmd) |
885
|
|
|
|
886
|
|
|
def get_tls_certificate(self, tls_certificate_id: str) -> Any: |
887
|
|
|
"""Request a single TLS certificate |
888
|
|
|
|
889
|
|
|
Arguments: |
890
|
|
|
tls_certificate_id: UUID of an existing TLS certificate |
891
|
|
|
|
892
|
|
|
Returns: |
893
|
|
|
The response. See :py:meth:`send_command` for details. |
894
|
|
|
""" |
895
|
|
|
cmd = XmlCommand("get_tls_certificates") |
896
|
|
|
|
897
|
|
|
if not tls_certificate_id: |
898
|
|
|
raise RequiredArgument( |
899
|
|
|
function=self.get_tls_certificate.__name__, |
900
|
|
|
argument='tls_certificate_id', |
901
|
|
|
) |
902
|
|
|
|
903
|
|
|
cmd.set_attribute("tls_certificate_id", tls_certificate_id) |
904
|
|
|
|
905
|
|
|
# for single tls certificate always request cert data |
906
|
|
|
cmd.set_attribute("include_certificate_data", "1") |
907
|
|
|
|
908
|
|
|
# for single entity always request all details |
909
|
|
|
cmd.set_attribute("details", "1") |
910
|
|
|
|
911
|
|
|
return self._send_xml_command(cmd) |
912
|
|
|
|
913
|
|
|
def modify_alert( |
914
|
|
|
self, |
915
|
|
|
alert_id: str, |
916
|
|
|
*, |
917
|
|
|
name: Optional[str] = None, |
918
|
|
|
comment: Optional[str] = None, |
919
|
|
|
filter_id: Optional[str] = None, |
920
|
|
|
event: Optional[AlertEvent] = None, |
921
|
|
|
event_data: Optional[dict] = None, |
922
|
|
|
condition: Optional[AlertCondition] = None, |
923
|
|
|
condition_data: Optional[dict] = None, |
924
|
|
|
method: Optional[AlertMethod] = None, |
925
|
|
|
method_data: Optional[dict] = None, |
926
|
|
|
) -> Any: |
927
|
|
|
"""Modifies an existing alert. |
928
|
|
|
|
929
|
|
|
Arguments: |
930
|
|
|
alert_id: UUID of the alert to be modified. |
931
|
|
|
name: Name of the Alert. |
932
|
|
|
condition: The condition that must be satisfied for the alert to |
933
|
|
|
occur. If the event is either 'Updated SecInfo |
934
|
|
|
arrived' or 'New SecInfo arrived', condition must be 'Always'. |
935
|
|
|
Otherwise, condition can also be on of 'Severity at least', |
936
|
|
|
'Filter count changed' or 'Filter count at least'. |
937
|
|
|
condition_data: Data that defines the condition |
938
|
|
|
event: The event that must happen for the alert to occur, one of |
939
|
|
|
'Task run status changed', 'Updated SecInfo arrived' or |
940
|
|
|
'New SecInfo arrived' |
941
|
|
|
event_data: Data that defines the event |
942
|
|
|
method: The method by which the user is alerted, one of 'SCP', |
943
|
|
|
'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
944
|
|
|
if the event is neither 'Updated SecInfo arrived' nor |
945
|
|
|
'New SecInfo arrived', method can also be one of 'Start Task', |
946
|
|
|
'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
947
|
|
|
method_data: Data that defines the method |
948
|
|
|
filter_id: Filter to apply when executing alert |
949
|
|
|
comment: Comment for the alert |
950
|
|
|
|
951
|
|
|
Returns: |
952
|
|
|
The response. See :py:meth:`send_command` for details. |
953
|
|
|
""" |
954
|
|
|
|
955
|
|
|
if not alert_id: |
956
|
|
|
raise RequiredArgument( |
957
|
|
|
function=self.modify_alert.__name__, argument='alert_id' |
958
|
|
|
) |
959
|
|
|
|
960
|
|
|
cmd = XmlCommand("modify_alert") |
961
|
|
|
cmd.set_attribute("alert_id", str(alert_id)) |
962
|
|
|
|
963
|
|
|
if name: |
964
|
|
|
cmd.add_element("name", name) |
965
|
|
|
|
966
|
|
|
if comment: |
967
|
|
|
cmd.add_element("comment", comment) |
968
|
|
|
|
969
|
|
|
if filter_id: |
970
|
|
|
cmd.add_element("filter", attrs={"id": filter_id}) |
971
|
|
|
|
972
|
|
|
if condition: |
973
|
|
|
if not isinstance(condition, AlertCondition): |
974
|
|
|
raise InvalidArgumentType( |
975
|
|
|
function=self.modify_alert.__name__, |
976
|
|
|
argument='condition', |
977
|
|
|
arg_type=AlertCondition.__name__, |
978
|
|
|
) |
979
|
|
|
|
980
|
|
|
conditions = cmd.add_element("condition", condition.value) |
981
|
|
|
|
982
|
|
|
if condition_data is not None: |
983
|
|
|
for key, value in condition_data.items(): |
984
|
|
|
_data = conditions.add_element("data", value) |
985
|
|
|
_data.add_element("name", key) |
986
|
|
|
|
987
|
|
|
if method: |
988
|
|
|
if not isinstance(method, AlertMethod): |
989
|
|
|
raise InvalidArgumentType( |
990
|
|
|
function=self.modify_alert.__name__, |
991
|
|
|
argument='method', |
992
|
|
|
arg_type=AlertMethod.__name__, |
993
|
|
|
) |
994
|
|
|
|
995
|
|
|
methods = cmd.add_element("method", method.value) |
996
|
|
|
|
997
|
|
|
if method_data is not None: |
998
|
|
|
for key, value in method_data.items(): |
999
|
|
|
_data = methods.add_element("data", value) |
1000
|
|
|
_data.add_element("name", key) |
1001
|
|
|
|
1002
|
|
|
if event: |
1003
|
|
|
if not isinstance(event, AlertEvent): |
1004
|
|
|
raise InvalidArgumentType( |
1005
|
|
|
function=self.modify_alert.__name__, |
1006
|
|
|
argument='event', |
1007
|
|
|
arg_type=AlertEvent.__name__, |
1008
|
|
|
) |
1009
|
|
|
|
1010
|
|
|
_check_event(event, condition, method) |
1011
|
|
|
|
1012
|
|
|
events = cmd.add_element("event", event.value) |
1013
|
|
|
|
1014
|
|
|
if event_data is not None: |
1015
|
|
|
for key, value in event_data.items(): |
1016
|
|
|
_data = events.add_element("data", value) |
1017
|
|
|
_data.add_element("name", key) |
1018
|
|
|
|
1019
|
|
|
return self._send_xml_command(cmd) |
1020
|
|
|
|
1021
|
|
|
def modify_audit( |
1022
|
|
|
self, |
1023
|
|
|
audit_id: str, |
1024
|
|
|
*, |
1025
|
|
|
name: Optional[str] = None, |
1026
|
|
|
policy_id: Optional[str] = None, |
1027
|
|
|
target_id: Optional[str] = None, |
1028
|
|
|
scanner_id: Optional[str] = None, |
1029
|
|
|
alterable: Optional[bool] = None, |
1030
|
|
|
hosts_ordering: Optional[HostsOrdering] = None, |
1031
|
|
|
schedule_id: Optional[str] = None, |
1032
|
|
|
schedule_periods: Optional[int] = None, |
1033
|
|
|
comment: Optional[str] = None, |
1034
|
|
|
alert_ids: Optional[List[str]] = None, |
1035
|
|
|
observers: Optional[List[str]] = None, |
1036
|
|
|
preferences: Optional[dict] = None, |
1037
|
|
|
) -> Any: |
1038
|
|
|
"""Modifies an existing task. |
1039
|
|
|
|
1040
|
|
|
Arguments: |
1041
|
|
|
audit_id: UUID of audit to modify. |
1042
|
|
|
name: The name of the audit. |
1043
|
|
|
policy_id: UUID of policy to use by the audit |
1044
|
|
|
target_id: UUID of target to be scanned |
1045
|
|
|
scanner_id: UUID of scanner to use for scanning the target |
1046
|
|
|
comment: The comment on the audit. |
1047
|
|
|
alert_ids: List of UUIDs for alerts to be applied to the audit |
1048
|
|
|
hosts_ordering: The order hosts are scanned in |
1049
|
|
|
schedule_id: UUID of a schedule when the audit should be run. |
1050
|
|
|
schedule_periods: A limit to the number of times the audit will be |
1051
|
|
|
scheduled, or 0 for no limit. |
1052
|
|
|
observers: List of names or ids of users which should be allowed to |
1053
|
|
|
observe this audit |
1054
|
|
|
preferences: Name/Value pairs of scanner preferences. |
1055
|
|
|
|
1056
|
|
|
Returns: |
1057
|
|
|
The response. See :py:meth:`send_command` for details. |
1058
|
|
|
""" |
1059
|
|
|
self.modify_task( |
1060
|
|
|
task_id=audit_id, |
1061
|
|
|
name=name, |
1062
|
|
|
config_id=policy_id, |
1063
|
|
|
target_id=target_id, |
1064
|
|
|
scanner_id=scanner_id, |
1065
|
|
|
alterable=alterable, |
1066
|
|
|
hosts_ordering=hosts_ordering, |
1067
|
|
|
schedule_id=schedule_id, |
1068
|
|
|
schedule_periods=schedule_periods, |
1069
|
|
|
comment=comment, |
1070
|
|
|
alert_ids=alert_ids, |
1071
|
|
|
observers=observers, |
1072
|
|
|
preferences=preferences, |
1073
|
|
|
) |
1074
|
|
|
|
1075
|
|
|
def modify_permission( |
1076
|
|
|
self, |
1077
|
|
|
permission_id: str, |
1078
|
|
|
*, |
1079
|
|
|
comment: Optional[str] = None, |
1080
|
|
|
name: Optional[str] = None, |
1081
|
|
|
resource_id: Optional[str] = None, |
1082
|
|
|
resource_type: Optional[EntityType] = None, |
1083
|
|
|
subject_id: Optional[str] = None, |
1084
|
|
|
subject_type: Optional[PermissionSubjectType] = None, |
1085
|
|
|
) -> Any: |
1086
|
|
|
"""Modifies an existing permission. |
1087
|
|
|
|
1088
|
|
|
Arguments: |
1089
|
|
|
permission_id: UUID of permission to be modified. |
1090
|
|
|
comment: The comment on the permission. |
1091
|
|
|
name: Permission name, currently the name of a command. |
1092
|
|
|
subject_id: UUID of subject to whom the permission is granted |
1093
|
|
|
subject_type: Type of the subject user, group or role |
1094
|
|
|
resource_id: UUID of entity to which the permission applies |
1095
|
|
|
resource_type: Type of the resource. For Super permissions user, |
1096
|
|
|
group or role |
1097
|
|
|
|
1098
|
|
|
Returns: |
1099
|
|
|
The response. See :py:meth:`send_command` for details. |
1100
|
|
|
""" |
1101
|
|
|
if not permission_id: |
1102
|
|
|
raise RequiredArgument( |
1103
|
|
|
function=self.modify_permission.__name__, |
1104
|
|
|
argument='permission_id', |
1105
|
|
|
) |
1106
|
|
|
|
1107
|
|
|
cmd = XmlCommand("modify_permission") |
1108
|
|
|
cmd.set_attribute("permission_id", permission_id) |
1109
|
|
|
|
1110
|
|
|
if comment: |
1111
|
|
|
cmd.add_element("comment", comment) |
1112
|
|
|
|
1113
|
|
|
if name: |
1114
|
|
|
cmd.add_element("name", name) |
1115
|
|
|
|
1116
|
|
View Code Duplication |
if resource_id or resource_type: |
|
|
|
|
1117
|
|
|
if not resource_id: |
1118
|
|
|
raise RequiredArgument( |
1119
|
|
|
function=self.modify_permission.__name__, |
1120
|
|
|
argument='resource_id', |
1121
|
|
|
) |
1122
|
|
|
|
1123
|
|
|
if not resource_type: |
1124
|
|
|
raise RequiredArgument( |
1125
|
|
|
function=self.modify_permission.__name__, |
1126
|
|
|
argument='resource_type', |
1127
|
|
|
) |
1128
|
|
|
|
1129
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
1130
|
|
|
raise InvalidArgumentType( |
1131
|
|
|
function=self.modify_permission.__name__, |
1132
|
|
|
argument='resource_type', |
1133
|
|
|
arg_type=self.types.EntityType.__name__, |
1134
|
|
|
) |
1135
|
|
|
|
1136
|
|
|
_xmlresource = cmd.add_element( |
1137
|
|
|
"resource", attrs={"id": resource_id} |
1138
|
|
|
) |
1139
|
|
|
_actual_resource_type = resource_type |
1140
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
1141
|
|
|
_actual_resource_type = EntityType.TASK |
1142
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
1143
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
1144
|
|
|
_xmlresource.add_element("type", _actual_resource_type.value) |
1145
|
|
|
|
1146
|
|
|
if subject_id or subject_type: |
1147
|
|
|
if not subject_id: |
1148
|
|
|
raise RequiredArgument( |
1149
|
|
|
function=self.modify_permission.__name__, |
1150
|
|
|
argument='subject_id', |
1151
|
|
|
) |
1152
|
|
|
|
1153
|
|
|
if not isinstance(subject_type, PermissionSubjectType): |
1154
|
|
|
raise InvalidArgumentType( |
1155
|
|
|
function=self.modify_permission.__name__, |
1156
|
|
|
argument='subject_type', |
1157
|
|
|
arg_type=PermissionSubjectType.__name__, |
1158
|
|
|
) |
1159
|
|
|
|
1160
|
|
|
_xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
1161
|
|
|
_xmlsubject.add_element("type", subject_type.value) |
1162
|
|
|
|
1163
|
|
|
return self._send_xml_command(cmd) |
1164
|
|
|
|
1165
|
|
|
def modify_policy_set_nvt_preference( |
1166
|
|
|
self, |
1167
|
|
|
policy_id: str, |
1168
|
|
|
name: str, |
1169
|
|
|
nvt_oid: str, |
1170
|
|
|
*, |
1171
|
|
|
value: Optional[str] = None, |
1172
|
|
|
) -> Any: |
1173
|
|
|
"""Modifies the nvt preferences of an existing policy. |
1174
|
|
|
|
1175
|
|
|
Arguments: |
1176
|
|
|
policy_id: UUID of policy to modify. |
1177
|
|
|
name: Name for preference to change. |
1178
|
|
|
nvt_oid: OID of the NVT associated with preference to modify |
1179
|
|
|
value: New value for the preference. None to delete the preference |
1180
|
|
|
and to use the default instead. |
1181
|
|
|
""" |
1182
|
|
|
self.modify_config_set_nvt_preference( |
1183
|
|
|
config_id=policy_id, name=name, nvt_oid=nvt_oid, value=value |
1184
|
|
|
) |
1185
|
|
|
|
1186
|
|
|
def modify_policy_set_name(self, policy_id: str, name: str) -> Any: |
1187
|
|
|
"""Modifies the name of an existing policy |
1188
|
|
|
|
1189
|
|
|
Arguments: |
1190
|
|
|
config_id: UUID of policy to modify. |
1191
|
|
|
name: New name for the config. |
1192
|
|
|
""" |
1193
|
|
|
self.modify_config_set_name(config_id=policy_id, name=name) |
1194
|
|
|
|
1195
|
|
|
def modify_policy_set_comment( |
1196
|
|
|
self, policy_id: str, comment: Optional[str] = "" |
1197
|
|
|
) -> Any: |
1198
|
|
|
"""Modifies the comment of an existing policy |
1199
|
|
|
|
1200
|
|
|
Arguments: |
1201
|
|
|
policy_id: UUID of policy to modify. |
1202
|
|
|
comment: Comment to set on a config. Default: '' |
1203
|
|
|
""" |
1204
|
|
|
self.modify_config_set_comment(config_id=policy_id, comment=comment) |
1205
|
|
|
|
1206
|
|
|
def modify_policy_set_scanner_preference( |
1207
|
|
|
self, policy_id: str, name: str, *, value: Optional[str] = None |
1208
|
|
|
) -> Any: |
1209
|
|
|
"""Modifies the scanner preferences of an existing policy |
1210
|
|
|
|
1211
|
|
|
Arguments: |
1212
|
|
|
policy_id: UUID of policy to modify. |
1213
|
|
|
name: Name of the scanner preference to change |
1214
|
|
|
value: New value for the preference. None to delete the preference |
1215
|
|
|
and to use the default instead. |
1216
|
|
|
|
1217
|
|
|
""" |
1218
|
|
|
self.modify_config_set_scanner_preference( |
1219
|
|
|
config_id=policy_id, name=name, value=value |
1220
|
|
|
) |
1221
|
|
|
|
1222
|
|
|
def modify_policy_set_nvt_selection( |
1223
|
|
|
self, policy_id: str, family: str, nvt_oids: List[str] |
1224
|
|
|
) -> Any: |
1225
|
|
|
"""Modifies the selected nvts of an existing policy |
1226
|
|
|
|
1227
|
|
|
The manager updates the given family in the config to include only the |
1228
|
|
|
given NVTs. |
1229
|
|
|
|
1230
|
|
|
Arguments: |
1231
|
|
|
policy_id: UUID of policy to modify. |
1232
|
|
|
family: Name of the NVT family to include NVTs from |
1233
|
|
|
nvt_oids: List of NVTs to select for the family. |
1234
|
|
|
""" |
1235
|
|
|
self.modify_config_set_nvt_selection( |
1236
|
|
|
config_id=policy_id, family=family, nvt_oids=nvt_oids |
1237
|
|
|
) |
1238
|
|
|
|
1239
|
|
|
def modify_policy_set_family_selection( |
1240
|
|
|
self, |
1241
|
|
|
policy_id: str, |
1242
|
|
|
families: List[Tuple[str, bool, bool]], |
1243
|
|
|
*, |
1244
|
|
|
auto_add_new_families: Optional[bool] = True, |
1245
|
|
|
) -> Any: |
1246
|
|
|
""" |
1247
|
|
|
Selected the NVTs of a policy at a family level. |
1248
|
|
|
|
1249
|
|
|
Arguments: |
1250
|
|
|
policy_id: UUID of policy to modify. |
1251
|
|
|
families: A list of tuples with the first entry being the name |
1252
|
|
|
of the NVT family selected, second entry a boolean indicating |
1253
|
|
|
whether new NVTs should be added to the family automatically, |
1254
|
|
|
and third entry a boolean indicating whether all nvts from |
1255
|
|
|
the family should be included. |
1256
|
|
|
auto_add_new_families: Whether new families should be added to the |
1257
|
|
|
policy automatically. Default: True. |
1258
|
|
|
""" |
1259
|
|
|
self.modify_config_set_family_selection( |
1260
|
|
|
config_id=policy_id, |
1261
|
|
|
families=families, |
1262
|
|
|
auto_add_new_families=auto_add_new_families, |
1263
|
|
|
) |
1264
|
|
|
|
1265
|
|
|
def modify_tag( |
1266
|
|
|
self, |
1267
|
|
|
tag_id: str, |
1268
|
|
|
*, |
1269
|
|
|
comment: Optional[str] = None, |
1270
|
|
|
name: Optional[str] = None, |
1271
|
|
|
value=None, |
1272
|
|
|
active=None, |
1273
|
|
|
resource_action: Optional[str] = None, |
1274
|
|
|
resource_type: Optional[EntityType] = None, |
1275
|
|
|
resource_filter: Optional[str] = None, |
1276
|
|
|
resource_ids: Optional[List[str]] = None, |
1277
|
|
|
) -> Any: |
1278
|
|
|
"""Modifies an existing tag. |
1279
|
|
|
|
1280
|
|
|
Arguments: |
1281
|
|
|
tag_id: UUID of the tag. |
1282
|
|
|
comment: Comment to add to the tag. |
1283
|
|
|
name: Name of the tag. |
1284
|
|
|
value: Value of the tag. |
1285
|
|
|
active: Whether the tag is active. |
1286
|
|
|
resource_action: Whether to add or remove resources instead of |
1287
|
|
|
overwriting. One of '', 'add', 'set' or 'remove'. |
1288
|
|
|
resource_type: Type of the resources to which to attach the tag. |
1289
|
|
|
Required if resource_filter is set. |
1290
|
|
|
resource_filter: Filter term to select resources the tag is to be |
1291
|
|
|
attached to. |
1292
|
|
|
resource_ids: IDs of the resources to which to attach the tag. |
1293
|
|
|
|
1294
|
|
|
Returns: |
1295
|
|
|
The response. See :py:meth:`send_command` for details. |
1296
|
|
|
""" |
1297
|
|
|
if not tag_id: |
1298
|
|
|
raise RequiredArgument( |
1299
|
|
|
function=self.modify_tag.__name__, argument='tag_id' |
1300
|
|
|
) |
1301
|
|
|
|
1302
|
|
|
cmd = XmlCommand("modify_tag") |
1303
|
|
|
cmd.set_attribute("tag_id", str(tag_id)) |
1304
|
|
|
|
1305
|
|
|
if comment: |
1306
|
|
|
cmd.add_element("comment", comment) |
1307
|
|
|
|
1308
|
|
|
if name: |
1309
|
|
|
cmd.add_element("name", name) |
1310
|
|
|
|
1311
|
|
|
if value: |
1312
|
|
|
cmd.add_element("value", value) |
1313
|
|
|
|
1314
|
|
|
if active is not None: |
1315
|
|
|
cmd.add_element("active", to_bool(active)) |
1316
|
|
|
|
1317
|
|
|
if resource_action or resource_filter or resource_ids or resource_type: |
1318
|
|
|
if resource_filter and not resource_type: |
1319
|
|
|
raise RequiredArgument( |
1320
|
|
|
function=self.modify_tag.__name__, argument='resource_type' |
1321
|
|
|
) |
1322
|
|
|
|
1323
|
|
|
_xmlresources = cmd.add_element("resources") |
1324
|
|
|
if resource_action is not None: |
1325
|
|
|
_xmlresources.set_attribute("action", resource_action) |
1326
|
|
|
|
1327
|
|
|
if resource_filter is not None: |
1328
|
|
|
_xmlresources.set_attribute("filter", resource_filter) |
1329
|
|
|
|
1330
|
|
|
for resource_id in resource_ids or []: |
1331
|
|
|
_xmlresources.add_element( |
1332
|
|
|
"resource", attrs={"id": str(resource_id)} |
1333
|
|
|
) |
1334
|
|
|
|
1335
|
|
|
if resource_type is not None: |
1336
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
1337
|
|
|
raise InvalidArgumentType( |
1338
|
|
|
function=self.modify_tag.__name__, |
1339
|
|
|
argument="resource_type", |
1340
|
|
|
arg_type=EntityType.__name__, |
1341
|
|
|
) |
1342
|
|
|
_actual_resource_type = resource_type |
1343
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
1344
|
|
|
_actual_resource_type = EntityType.TASK |
1345
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
1346
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
1347
|
|
|
_xmlresources.add_element("type", _actual_resource_type.value) |
1348
|
|
|
|
1349
|
|
|
return self._send_xml_command(cmd) |
1350
|
|
|
|
1351
|
|
View Code Duplication |
def modify_tls_certificate( |
|
|
|
|
1352
|
|
|
self, |
1353
|
|
|
tls_certificate_id: str, |
1354
|
|
|
*, |
1355
|
|
|
name: Optional[str] = None, |
1356
|
|
|
comment: Optional[str] = None, |
1357
|
|
|
trust: Optional[bool] = None, |
1358
|
|
|
) -> Any: |
1359
|
|
|
"""Modifies an existing TLS certificate. |
1360
|
|
|
|
1361
|
|
|
Arguments: |
1362
|
|
|
tls_certificate_id: UUID of the TLS certificate to be modified. |
1363
|
|
|
name: Name of the TLS certificate, defaulting to the MD5 fingerprint |
1364
|
|
|
comment: Comment for the TLS certificate. |
1365
|
|
|
trust: Whether the certificate is trusted. |
1366
|
|
|
|
1367
|
|
|
Returns: |
1368
|
|
|
The response. See :py:meth:`send_command` for details. |
1369
|
|
|
""" |
1370
|
|
|
if not tls_certificate_id: |
1371
|
|
|
raise RequiredArgument( |
1372
|
|
|
function=self.modify_tls_certificate.__name__, |
1373
|
|
|
argument='tls_certificate_id', |
1374
|
|
|
) |
1375
|
|
|
|
1376
|
|
|
cmd = XmlCommand("modify_tls_certificate") |
1377
|
|
|
cmd.set_attribute("tls_certificate_id", str(tls_certificate_id)) |
1378
|
|
|
|
1379
|
|
|
if comment: |
1380
|
|
|
cmd.add_element("comment", comment) |
1381
|
|
|
|
1382
|
|
|
if name: |
1383
|
|
|
cmd.add_element("name", name) |
1384
|
|
|
|
1385
|
|
|
if trust: |
1386
|
|
|
cmd.add_element("trust", to_bool(trust)) |
1387
|
|
|
|
1388
|
|
|
return self._send_xml_command(cmd) |
1389
|
|
|
|
1390
|
|
|
def clone_alert(self, alert_id: str) -> Any: |
1391
|
|
|
"""Clone an existing alert |
1392
|
|
|
|
1393
|
|
|
Arguments: |
1394
|
|
|
alert_id: UUID of an existing alert to clone from |
1395
|
|
|
|
1396
|
|
|
Returns: |
1397
|
|
|
The response. See :py:meth:`send_command` for details. |
1398
|
|
|
""" |
1399
|
|
|
if not alert_id: |
1400
|
|
|
raise RequiredArgument( |
1401
|
|
|
function=self.clone_alert.__name__, argument='alert_id' |
1402
|
|
|
) |
1403
|
|
|
|
1404
|
|
|
cmd = XmlCommand("create_alert") |
1405
|
|
|
cmd.add_element("copy", alert_id) |
1406
|
|
|
return self._send_xml_command(cmd) |
1407
|
|
|
|
1408
|
|
|
def clone_ticket(self, ticket_id: str) -> Any: |
1409
|
|
|
"""Clone an existing ticket |
1410
|
|
|
|
1411
|
|
|
Arguments: |
1412
|
|
|
ticket_id: UUID of an existing ticket to clone from |
1413
|
|
|
|
1414
|
|
|
Returns: |
1415
|
|
|
The response. See :py:meth:`send_command` for details. |
1416
|
|
|
""" |
1417
|
|
|
if not ticket_id: |
1418
|
|
|
raise RequiredArgument( |
1419
|
|
|
function=self.clone_ticket.__name__, argument='ticket_id' |
1420
|
|
|
) |
1421
|
|
|
|
1422
|
|
|
cmd = XmlCommand("create_ticket") |
1423
|
|
|
|
1424
|
|
|
_copy = cmd.add_element("copy", ticket_id) |
1425
|
|
|
|
1426
|
|
|
return self._send_xml_command(cmd) |
1427
|
|
|
|
1428
|
|
|
def clone_tls_certificate(self, tls_certificate_id: str) -> Any: |
1429
|
|
|
"""Modifies an existing TLS certificate. |
1430
|
|
|
|
1431
|
|
|
Arguments: |
1432
|
|
|
tls_certificate_id: The UUID of an existing TLS certificate |
1433
|
|
|
|
1434
|
|
|
Returns: |
1435
|
|
|
The response. See :py:meth:`send_command` for details. |
1436
|
|
|
""" |
1437
|
|
|
if not tls_certificate_id: |
1438
|
|
|
raise RequiredArgument( |
1439
|
|
|
function=self.clone_tls_certificate.__name__, |
1440
|
|
|
argument='tls_certificate_id', |
1441
|
|
|
) |
1442
|
|
|
|
1443
|
|
|
cmd = XmlCommand("create_tls_certificate") |
1444
|
|
|
|
1445
|
|
|
cmd.add_element("copy", tls_certificate_id) |
1446
|
|
|
|
1447
|
|
|
return self._send_xml_command(cmd) |
1448
|
|
|
|
1449
|
|
|
def get_configs( |
1450
|
|
|
self, |
1451
|
|
|
*, |
1452
|
|
|
filter: Optional[str] = None, |
1453
|
|
|
filter_id: Optional[str] = None, |
1454
|
|
|
trash: Optional[bool] = None, |
1455
|
|
|
details: Optional[bool] = None, |
1456
|
|
|
families: Optional[bool] = None, |
1457
|
|
|
preferences: Optional[bool] = None, |
1458
|
|
|
tasks: Optional[bool] = None, |
1459
|
|
|
) -> Any: |
1460
|
|
|
"""Request a list of scan configs |
1461
|
|
|
|
1462
|
|
|
Arguments: |
1463
|
|
|
filter: Filter term to use for the query |
1464
|
|
|
filter_id: UUID of an existing filter to use for the query |
1465
|
|
|
trash: Whether to get the trashcan scan configs instead |
1466
|
|
|
details: Whether to get config families, preferences, nvt selectors |
1467
|
|
|
and tasks. |
1468
|
|
|
families: Whether to include the families if no details are |
1469
|
|
|
requested |
1470
|
|
|
preferences: Whether to include the preferences if no details are |
1471
|
|
|
requested |
1472
|
|
|
tasks: Whether to get tasks using this config |
1473
|
|
|
|
1474
|
|
|
Returns: |
1475
|
|
|
The response. See :py:meth:`send_command` for details. |
1476
|
|
|
""" |
1477
|
|
|
return self.__get_configs( |
1478
|
|
|
UsageType.SCAN, |
1479
|
|
|
filter=filter, |
1480
|
|
|
filter_id=filter_id, |
1481
|
|
|
trash=trash, |
1482
|
|
|
details=details, |
1483
|
|
|
families=families, |
1484
|
|
|
preferences=preferences, |
1485
|
|
|
tasks=tasks, |
1486
|
|
|
) |
1487
|
|
|
|
1488
|
|
|
def get_policies( |
1489
|
|
|
self, |
1490
|
|
|
*, |
1491
|
|
|
audits: Optional[bool] = None, |
1492
|
|
|
filter: Optional[str] = None, |
1493
|
|
|
filter_id: Optional[str] = None, |
1494
|
|
|
details: Optional[bool] = None, |
1495
|
|
|
families: Optional[bool] = None, |
1496
|
|
|
preferences: Optional[bool] = None, |
1497
|
|
|
trash: Optional[bool] = None, |
1498
|
|
|
) -> Any: |
1499
|
|
|
"""Request a list of policies |
1500
|
|
|
|
1501
|
|
|
Arguments: |
1502
|
|
|
audits: Whether to get audits using the policy |
1503
|
|
|
filter: Filter term to use for the query |
1504
|
|
|
filter_id: UUID of an existing filter to use for the query |
1505
|
|
|
details: Whether to get families, preferences, nvt selectors |
1506
|
|
|
and tasks. |
1507
|
|
|
families: Whether to include the families if no details are |
1508
|
|
|
requested |
1509
|
|
|
preferences: Whether to include the preferences if no details are |
1510
|
|
|
requested |
1511
|
|
|
trash: Whether to get the trashcan audits instead |
1512
|
|
|
|
1513
|
|
|
Returns: |
1514
|
|
|
The response. See :py:meth:`send_command` for details. |
1515
|
|
|
""" |
1516
|
|
|
return self.__get_configs( |
1517
|
|
|
UsageType.POLICY, |
1518
|
|
|
filter=filter, |
1519
|
|
|
filter_id=filter_id, |
1520
|
|
|
details=details, |
1521
|
|
|
families=families, |
1522
|
|
|
preferences=preferences, |
1523
|
|
|
tasks=audits, |
1524
|
|
|
trash=trash, |
1525
|
|
|
) |
1526
|
|
|
|
1527
|
|
|
def get_config( |
1528
|
|
|
self, config_id: str, *, tasks: Optional[bool] = None |
1529
|
|
|
) -> Any: |
1530
|
|
|
"""Request a single scan config |
1531
|
|
|
|
1532
|
|
|
Arguments: |
1533
|
|
|
config_id: UUID of an existing scan config |
1534
|
|
|
tasks: Whether to get tasks using this config |
1535
|
|
|
|
1536
|
|
|
Returns: |
1537
|
|
|
The response. See :py:meth:`send_command` for details. |
1538
|
|
|
""" |
1539
|
|
|
return self.__get_config( |
1540
|
|
|
config_id=config_id, usage_type=UsageType.SCAN, tasks=tasks |
1541
|
|
|
) |
1542
|
|
|
|
1543
|
|
|
def get_policy( |
1544
|
|
|
self, policy_id: str, *, audits: Optional[bool] = None |
1545
|
|
|
) -> Any: |
1546
|
|
|
"""Request a single policy |
1547
|
|
|
|
1548
|
|
|
Arguments: |
1549
|
|
|
policy_id: UUID of an existing policy |
1550
|
|
|
audits: Whether to get audits using this config |
1551
|
|
|
|
1552
|
|
|
Returns: |
1553
|
|
|
The response. See :py:meth:`send_command` for details. |
1554
|
|
|
""" |
1555
|
|
|
return self.__get_config(policy_id, UsageType.POLICY, tasks=audits) |
1556
|
|
|
|
1557
|
|
|
def get_tasks( |
1558
|
|
|
self, |
1559
|
|
|
*, |
1560
|
|
|
filter: Optional[str] = None, |
1561
|
|
|
filter_id: Optional[str] = None, |
1562
|
|
|
trash: Optional[bool] = None, |
1563
|
|
|
details: Optional[bool] = None, |
1564
|
|
|
schedules_only: Optional[bool] = None, |
1565
|
|
|
) -> Any: |
1566
|
|
|
"""Request a list of tasks |
1567
|
|
|
|
1568
|
|
|
Arguments: |
1569
|
|
|
filter: Filter term to use for the query |
1570
|
|
|
filter_id: UUID of an existing filter to use for the query |
1571
|
|
|
trash: Whether to get the trashcan tasks instead |
1572
|
|
|
details: Whether to include full task details |
1573
|
|
|
schedules_only: Whether to only include id, name and schedule |
1574
|
|
|
details |
1575
|
|
|
|
1576
|
|
|
Returns: |
1577
|
|
|
The response. See :py:meth:`send_command` for details. |
1578
|
|
|
""" |
1579
|
|
|
return self.__get_tasks( |
1580
|
|
|
UsageType.SCAN, |
1581
|
|
|
filter=filter, |
1582
|
|
|
filter_id=filter_id, |
1583
|
|
|
trash=trash, |
1584
|
|
|
details=details, |
1585
|
|
|
schedules_only=schedules_only, |
1586
|
|
|
) |
1587
|
|
|
|
1588
|
|
|
def get_audits( |
1589
|
|
|
self, |
1590
|
|
|
*, |
1591
|
|
|
filter: Optional[str] = None, |
1592
|
|
|
filter_id: Optional[str] = None, |
1593
|
|
|
trash: Optional[bool] = None, |
1594
|
|
|
details: Optional[bool] = None, |
1595
|
|
|
schedules_only: Optional[bool] = None, |
1596
|
|
|
) -> Any: |
1597
|
|
|
"""Request a list of audits |
1598
|
|
|
|
1599
|
|
|
Arguments: |
1600
|
|
|
filter: Filter term to use for the query |
1601
|
|
|
filter_id: UUID of an existing filter to use for the query |
1602
|
|
|
trash: Whether to get the trashcan audits instead |
1603
|
|
|
details: Whether to include full audit details |
1604
|
|
|
schedules_only: Whether to only include id, name and schedule |
1605
|
|
|
details |
1606
|
|
|
|
1607
|
|
|
Returns: |
1608
|
|
|
The response. See :py:meth:`send_command` for details. |
1609
|
|
|
""" |
1610
|
|
|
return self.__get_tasks( |
1611
|
|
|
UsageType.AUDIT, |
1612
|
|
|
filter=filter, |
1613
|
|
|
filter_id=filter_id, |
1614
|
|
|
trash=trash, |
1615
|
|
|
details=details, |
1616
|
|
|
schedules_only=schedules_only, |
1617
|
|
|
) |
1618
|
|
|
|
1619
|
|
|
def get_task(self, task_id: str) -> Any: |
1620
|
|
|
"""Request a single task |
1621
|
|
|
|
1622
|
|
|
Arguments: |
1623
|
|
|
task_id: UUID of an existing task |
1624
|
|
|
|
1625
|
|
|
Returns: |
1626
|
|
|
The response. See :py:meth:`send_command` for details. |
1627
|
|
|
""" |
1628
|
|
|
return self.__get_task(task_id, UsageType.SCAN) |
1629
|
|
|
|
1630
|
|
|
def get_audit(self, audit_id: str) -> Any: |
1631
|
|
|
"""Request a single audit |
1632
|
|
|
|
1633
|
|
|
Arguments: |
1634
|
|
|
audit_id: UUID of an existing audit |
1635
|
|
|
|
1636
|
|
|
Returns: |
1637
|
|
|
The response. See :py:meth:`send_command` for details. |
1638
|
|
|
""" |
1639
|
|
|
return self.__get_task(audit_id, UsageType.AUDIT) |
1640
|
|
|
|
1641
|
|
|
def clone_audit(self, audit_id: str) -> Any: |
1642
|
|
|
"""Clone an existing audit |
1643
|
|
|
|
1644
|
|
|
Arguments: |
1645
|
|
|
audit_id: UUID of existing audit to clone from |
1646
|
|
|
|
1647
|
|
|
Returns: |
1648
|
|
|
The response. See :py:meth:`send_command` for details. |
1649
|
|
|
""" |
1650
|
|
|
if not audit_id: |
1651
|
|
|
raise RequiredArgument( |
1652
|
|
|
function=self.clone_audit.__name__, argument='audit_id' |
1653
|
|
|
) |
1654
|
|
|
|
1655
|
|
|
cmd = XmlCommand("create_task") |
1656
|
|
|
cmd.add_element("copy", audit_id) |
1657
|
|
|
return self._send_xml_command(cmd) |
1658
|
|
|
|
1659
|
|
|
def clone_policy(self, policy_id: str) -> Any: |
1660
|
|
|
"""Clone a policy from an existing one |
1661
|
|
|
|
1662
|
|
|
Arguments: |
1663
|
|
|
policy_id: UUID of the existing policy |
1664
|
|
|
|
1665
|
|
|
Returns: |
1666
|
|
|
The response. See :py:meth:`send_command` for details. |
1667
|
|
|
""" |
1668
|
|
|
if not policy_id: |
1669
|
|
|
raise RequiredArgument( |
1670
|
|
|
function=self.clone_policy.__name__, argument='policy_id' |
1671
|
|
|
) |
1672
|
|
|
|
1673
|
|
|
cmd = XmlCommand("create_config") |
1674
|
|
|
cmd.add_element("copy", policy_id) |
1675
|
|
|
return self._send_xml_command(cmd) |
1676
|
|
|
|
1677
|
|
|
def delete_audit( |
1678
|
|
|
self, audit_id: str, *, ultimate: Optional[bool] = False |
1679
|
|
|
) -> Any: |
1680
|
|
|
"""Deletes an existing audit |
1681
|
|
|
|
1682
|
|
|
Arguments: |
1683
|
|
|
audit_id: UUID of the audit to be deleted. |
1684
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1685
|
|
|
""" |
1686
|
|
|
if not audit_id: |
1687
|
|
|
raise RequiredArgument( |
1688
|
|
|
function=self.delete_audit.__name__, argument='audit_id' |
1689
|
|
|
) |
1690
|
|
|
|
1691
|
|
|
cmd = XmlCommand("delete_task") |
1692
|
|
|
cmd.set_attribute("task_id", audit_id) |
1693
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1694
|
|
|
|
1695
|
|
|
return self._send_xml_command(cmd) |
1696
|
|
|
|
1697
|
|
|
def delete_policy( |
1698
|
|
|
self, policy_id: str, *, ultimate: Optional[bool] = False |
1699
|
|
|
) -> Any: |
1700
|
|
|
"""Deletes an existing policy |
1701
|
|
|
|
1702
|
|
|
Arguments: |
1703
|
|
|
policy_id: UUID of the policy to be deleted. |
1704
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1705
|
|
|
""" |
1706
|
|
|
if not policy_id: |
1707
|
|
|
raise RequiredArgument( |
1708
|
|
|
function=self.delete_policy.__name__, argument='policy_id' |
1709
|
|
|
) |
1710
|
|
|
|
1711
|
|
|
cmd = XmlCommand("delete_config") |
1712
|
|
|
cmd.set_attribute("config_id", policy_id) |
1713
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1714
|
|
|
|
1715
|
|
|
return self._send_xml_command(cmd) |
1716
|
|
|
|
1717
|
|
|
def delete_tls_certificate(self, tls_certificate_id: str) -> Any: |
1718
|
|
|
"""Deletes an existing tls certificate |
1719
|
|
|
|
1720
|
|
|
Arguments: |
1721
|
|
|
tls_certificate_id: UUID of the tls certificate to be deleted. |
1722
|
|
|
""" |
1723
|
|
|
if not tls_certificate_id: |
1724
|
|
|
raise RequiredArgument( |
1725
|
|
|
function=self.delete_tls_certificate.__name__, |
1726
|
|
|
argument='tls_certificate_id', |
1727
|
|
|
) |
1728
|
|
|
|
1729
|
|
|
cmd = XmlCommand("delete_tls_certificate") |
1730
|
|
|
cmd.set_attribute("tls_certificate_id", tls_certificate_id) |
1731
|
|
|
|
1732
|
|
|
return self._send_xml_command(cmd) |
1733
|
|
|
|
1734
|
|
|
def __create_task( |
1735
|
|
|
self, |
1736
|
|
|
name: str, |
1737
|
|
|
config_id: str, |
1738
|
|
|
target_id: str, |
1739
|
|
|
scanner_id: str, |
1740
|
|
|
usage_type: UsageType, |
1741
|
|
|
function: str, |
1742
|
|
|
*, |
1743
|
|
|
alterable: Optional[bool] = None, |
1744
|
|
|
hosts_ordering: Optional[HostsOrdering] = None, |
1745
|
|
|
schedule_id: Optional[str] = None, |
1746
|
|
|
alert_ids: Optional[List[str]] = None, |
1747
|
|
|
comment: Optional[str] = None, |
1748
|
|
|
schedule_periods: Optional[int] = None, |
1749
|
|
|
observers: Optional[List[str]] = None, |
1750
|
|
|
preferences: Optional[dict] = None, |
1751
|
|
|
) -> Any: |
1752
|
|
|
if not name: |
1753
|
|
|
raise RequiredArgument(function=function, argument='name') |
1754
|
|
|
|
1755
|
|
|
if not config_id: |
1756
|
|
|
raise RequiredArgument(function=function, argument='config_id') |
1757
|
|
|
|
1758
|
|
|
if not target_id: |
1759
|
|
|
raise RequiredArgument(function=function, argument='target_id') |
1760
|
|
|
|
1761
|
|
|
if not scanner_id: |
1762
|
|
|
raise RequiredArgument(function=function, argument='scanner_id') |
1763
|
|
|
|
1764
|
|
|
# don't allow to create a container task with create_task |
1765
|
|
|
if target_id == '0': |
1766
|
|
|
raise InvalidArgument(function=function, argument='target_id') |
1767
|
|
|
|
1768
|
|
|
cmd = XmlCommand("create_task") |
1769
|
|
|
cmd.add_element("name", name) |
1770
|
|
|
cmd.add_element("usage_type", usage_type.value) |
1771
|
|
|
cmd.add_element("config", attrs={"id": config_id}) |
1772
|
|
|
cmd.add_element("target", attrs={"id": target_id}) |
1773
|
|
|
cmd.add_element("scanner", attrs={"id": scanner_id}) |
1774
|
|
|
|
1775
|
|
|
if comment: |
1776
|
|
|
cmd.add_element("comment", comment) |
1777
|
|
|
|
1778
|
|
|
if alterable is not None: |
1779
|
|
|
cmd.add_element("alterable", to_bool(alterable)) |
1780
|
|
|
|
1781
|
|
|
if hosts_ordering: |
1782
|
|
|
if not isinstance(hosts_ordering, self.types.HostsOrdering): |
1783
|
|
|
raise InvalidArgumentType( |
1784
|
|
|
function=function, |
1785
|
|
|
argument='hosts_ordering', |
1786
|
|
|
arg_type=HostsOrdering.__name__, |
1787
|
|
|
) |
1788
|
|
|
cmd.add_element("hosts_ordering", hosts_ordering.value) |
1789
|
|
|
|
1790
|
|
|
if alert_ids: |
1791
|
|
|
if isinstance(alert_ids, str): |
1792
|
|
|
deprecation( |
1793
|
|
|
"Please pass a list as alert_ids parameter to {}. " |
1794
|
|
|
"Passing a string is deprecated and will be removed in " |
1795
|
|
|
"future.".format(function) |
1796
|
|
|
) |
1797
|
|
|
|
1798
|
|
|
# if a single id is given as a string wrap it into a list |
1799
|
|
|
alert_ids = [alert_ids] |
1800
|
|
|
if is_list_like(alert_ids): |
1801
|
|
|
# parse all given alert id's |
1802
|
|
|
for alert in alert_ids: |
1803
|
|
|
cmd.add_element("alert", attrs={"id": str(alert)}) |
1804
|
|
|
|
1805
|
|
View Code Duplication |
if schedule_id: |
|
|
|
|
1806
|
|
|
cmd.add_element("schedule", attrs={"id": schedule_id}) |
1807
|
|
|
|
1808
|
|
|
if schedule_periods is not None: |
1809
|
|
|
if ( |
1810
|
|
|
not isinstance(schedule_periods, numbers.Integral) |
1811
|
|
|
or schedule_periods < 0 |
1812
|
|
|
): |
1813
|
|
|
raise InvalidArgument( |
1814
|
|
|
"schedule_periods must be an integer greater or equal " |
1815
|
|
|
"than 0" |
1816
|
|
|
) |
1817
|
|
|
cmd.add_element("schedule_periods", str(schedule_periods)) |
1818
|
|
|
|
1819
|
|
|
if observers is not None: |
1820
|
|
|
if not is_list_like(observers): |
1821
|
|
|
raise InvalidArgumentType( |
1822
|
|
|
function=function, argument='observers', arg_type='list' |
1823
|
|
|
) |
1824
|
|
|
|
1825
|
|
|
# gvmd splits by comma and space |
1826
|
|
|
# gvmd tries to lookup each value as user name and afterwards as |
1827
|
|
|
# user id. So both user name and user id are possible |
1828
|
|
|
cmd.add_element("observers", to_comma_list(observers)) |
1829
|
|
|
|
1830
|
|
View Code Duplication |
if preferences is not None: |
|
|
|
|
1831
|
|
|
if not isinstance(preferences, collections.abc.Mapping): |
1832
|
|
|
raise InvalidArgumentType( |
1833
|
|
|
function=function, |
1834
|
|
|
argument='preferences', |
1835
|
|
|
arg_type=collections.abc.Mapping.__name__, |
1836
|
|
|
) |
1837
|
|
|
|
1838
|
|
|
_xmlprefs = cmd.add_element("preferences") |
1839
|
|
|
for pref_name, pref_value in preferences.items(): |
1840
|
|
|
_xmlpref = _xmlprefs.add_element("preference") |
1841
|
|
|
_xmlpref.add_element("scanner_name", pref_name) |
1842
|
|
|
_xmlpref.add_element("value", str(pref_value)) |
1843
|
|
|
|
1844
|
|
|
return self._send_xml_command(cmd) |
1845
|
|
|
|
1846
|
|
|
def __create_config( |
1847
|
|
|
self, |
1848
|
|
|
config_id: str, |
1849
|
|
|
name: str, |
1850
|
|
|
usage_type: UsageType, |
1851
|
|
|
function: str, |
1852
|
|
|
*, |
1853
|
|
|
comment: Optional[str] = None, |
1854
|
|
|
) -> Any: |
1855
|
|
|
if not name: |
1856
|
|
|
raise RequiredArgument(function=function, argument='name') |
1857
|
|
|
|
1858
|
|
|
if not config_id: |
1859
|
|
|
raise RequiredArgument(function=function, argument='config_id') |
1860
|
|
|
|
1861
|
|
|
cmd = XmlCommand("create_config") |
1862
|
|
|
if comment is not None: |
1863
|
|
|
cmd.add_element("comment", comment) |
1864
|
|
|
cmd.add_element("copy", config_id) |
1865
|
|
|
cmd.add_element("name", name) |
1866
|
|
|
cmd.add_element("usage_type", usage_type.value) |
1867
|
|
|
return self._send_xml_command(cmd) |
1868
|
|
|
|
1869
|
|
|
def __create_config_from_osp_scanner( |
1870
|
|
|
self, |
1871
|
|
|
scanner_id: str, |
1872
|
|
|
name: str, |
1873
|
|
|
usage_type: UsageType, |
1874
|
|
|
function: str, |
1875
|
|
|
*, |
1876
|
|
|
comment: Optional[str] = None, |
1877
|
|
|
) -> Any: |
1878
|
|
|
if not name: |
1879
|
|
|
raise RequiredArgument(function=function, argument='name') |
1880
|
|
|
|
1881
|
|
|
if not scanner_id: |
1882
|
|
|
raise RequiredArgument(function=function, argument='scanner_id') |
1883
|
|
|
|
1884
|
|
|
cmd = XmlCommand("create_config") |
1885
|
|
|
if comment is not None: |
1886
|
|
|
cmd.add_element("comment", comment) |
1887
|
|
|
cmd.add_element("scanner", scanner_id) |
1888
|
|
|
cmd.add_element("name", name) |
1889
|
|
|
cmd.add_element("usage_type", usage_type.value) |
1890
|
|
|
return self._send_xml_command(cmd) |
1891
|
|
|
|
1892
|
|
|
def __get_configs( |
1893
|
|
|
self, |
1894
|
|
|
usage_type: UsageType, |
1895
|
|
|
*, |
1896
|
|
|
filter: Optional[str] = None, |
1897
|
|
|
filter_id: Optional[str] = None, |
1898
|
|
|
trash: Optional[bool] = None, |
1899
|
|
|
details: Optional[bool] = None, |
1900
|
|
|
families: Optional[bool] = None, |
1901
|
|
|
preferences: Optional[bool] = None, |
1902
|
|
|
tasks: Optional[bool] = None, |
1903
|
|
|
) -> Any: |
1904
|
|
|
cmd = XmlCommand("get_configs") |
1905
|
|
|
cmd.set_attribute("usage_type", usage_type.value) |
1906
|
|
|
|
1907
|
|
|
add_filter(cmd, filter, filter_id) |
1908
|
|
|
|
1909
|
|
|
if trash is not None: |
1910
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1911
|
|
|
|
1912
|
|
|
if details is not None: |
1913
|
|
|
cmd.set_attribute("details", to_bool(details)) |
1914
|
|
|
|
1915
|
|
|
if families is not None: |
1916
|
|
|
cmd.set_attribute("families", to_bool(families)) |
1917
|
|
|
|
1918
|
|
|
if preferences is not None: |
1919
|
|
|
cmd.set_attribute("preferences", to_bool(preferences)) |
1920
|
|
|
|
1921
|
|
|
if tasks is not None: |
1922
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
1923
|
|
|
|
1924
|
|
|
return self._send_xml_command(cmd) |
1925
|
|
|
|
1926
|
|
|
def __get_config( |
1927
|
|
|
self, |
1928
|
|
|
config_id: str, |
1929
|
|
|
usage_type: UsageType, |
1930
|
|
|
*, |
1931
|
|
|
tasks: Optional[bool] = None, |
1932
|
|
|
) -> Any: |
1933
|
|
|
if not config_id: |
1934
|
|
|
raise RequiredArgument( |
1935
|
|
|
function=self.get_config.__name__, argument='config_id' |
1936
|
|
|
) |
1937
|
|
|
|
1938
|
|
|
cmd = XmlCommand("get_configs") |
1939
|
|
|
cmd.set_attribute("config_id", config_id) |
1940
|
|
|
|
1941
|
|
|
cmd.set_attribute("usage_type", usage_type.value) |
1942
|
|
|
|
1943
|
|
|
if tasks is not None: |
1944
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
1945
|
|
|
|
1946
|
|
|
# for single entity always request all details |
1947
|
|
|
cmd.set_attribute("details", "1") |
1948
|
|
|
|
1949
|
|
|
return self._send_xml_command(cmd) |
1950
|
|
|
|
1951
|
|
|
def __get_tasks( |
1952
|
|
|
self, |
1953
|
|
|
usage_type: UsageType, |
1954
|
|
|
*, |
1955
|
|
|
filter: Optional[str] = None, |
1956
|
|
|
filter_id: Optional[str] = None, |
1957
|
|
|
trash: Optional[bool] = None, |
1958
|
|
|
details: Optional[bool] = None, |
1959
|
|
|
schedules_only: Optional[bool] = None, |
1960
|
|
|
) -> Any: |
1961
|
|
|
cmd = XmlCommand("get_tasks") |
1962
|
|
|
cmd.set_attribute("usage_type", usage_type.value) |
1963
|
|
|
|
1964
|
|
|
add_filter(cmd, filter, filter_id) |
1965
|
|
|
|
1966
|
|
|
if trash is not None: |
1967
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1968
|
|
|
|
1969
|
|
|
if details is not None: |
1970
|
|
|
cmd.set_attribute("details", to_bool(details)) |
1971
|
|
|
|
1972
|
|
|
if schedules_only is not None: |
1973
|
|
|
cmd.set_attribute("schedules_only", to_bool(schedules_only)) |
1974
|
|
|
|
1975
|
|
|
return self._send_xml_command(cmd) |
1976
|
|
|
|
1977
|
|
|
def __get_task(self, task_id: str, usage_type: UsageType) -> Any: |
1978
|
|
|
if not task_id: |
1979
|
|
|
raise RequiredArgument( |
1980
|
|
|
function=self.get_task.__name__, argument='task_id' |
1981
|
|
|
) |
1982
|
|
|
|
1983
|
|
|
cmd = XmlCommand("get_tasks") |
1984
|
|
|
cmd.set_attribute("task_id", task_id) |
1985
|
|
|
cmd.set_attribute("usage_type", usage_type.value) |
1986
|
|
|
|
1987
|
|
|
# for single entity always request all details |
1988
|
|
|
cmd.set_attribute("details", "1") |
1989
|
|
|
return self._send_xml_command(cmd) |
1990
|
|
|
|
1991
|
|
|
def resume_audit(self, audit_id: str) -> Any: |
1992
|
|
|
"""Resume an existing stopped audit |
1993
|
|
|
|
1994
|
|
|
Arguments: |
1995
|
|
|
audit_id: UUID of the audit to be resumed |
1996
|
|
|
|
1997
|
|
|
Returns: |
1998
|
|
|
The response. See :py:meth:`send_command` for details. |
1999
|
|
|
""" |
2000
|
|
|
if not audit_id: |
2001
|
|
|
raise RequiredArgument( |
2002
|
|
|
function=self.resume_audit.__name__, argument='audit_id' |
2003
|
|
|
) |
2004
|
|
|
|
2005
|
|
|
cmd = XmlCommand("resume_task") |
2006
|
|
|
cmd.set_attribute("task_id", audit_id) |
2007
|
|
|
|
2008
|
|
|
return self._send_xml_command(cmd) |
2009
|
|
|
|
2010
|
|
|
def start_audit(self, audit_id: str) -> Any: |
2011
|
|
|
"""Start an existing audit |
2012
|
|
|
|
2013
|
|
|
Arguments: |
2014
|
|
|
audit_id: UUID of the audit to be started |
2015
|
|
|
|
2016
|
|
|
Returns: |
2017
|
|
|
The response. See :py:meth:`send_command` for details. |
2018
|
|
|
""" |
2019
|
|
|
if not audit_id: |
2020
|
|
|
raise RequiredArgument( |
2021
|
|
|
function=self.start_audit.__name__, argument='audit_id' |
2022
|
|
|
) |
2023
|
|
|
|
2024
|
|
|
cmd = XmlCommand("start_task") |
2025
|
|
|
cmd.set_attribute("task_id", audit_id) |
2026
|
|
|
|
2027
|
|
|
return self._send_xml_command(cmd) |
2028
|
|
|
|
2029
|
|
|
def stop_audit(self, audit_id: str) -> Any: |
2030
|
|
|
"""Stop an existing running audit |
2031
|
|
|
|
2032
|
|
|
Arguments: |
2033
|
|
|
audit_id: UUID of the audit to be stopped |
2034
|
|
|
|
2035
|
|
|
Returns: |
2036
|
|
|
The response. See :py:meth:`send_command` for details. |
2037
|
|
|
""" |
2038
|
|
|
if not audit_id: |
2039
|
|
|
raise RequiredArgument( |
2040
|
|
|
function=self.stop_audit.__name__, argument='audit_id' |
2041
|
|
|
) |
2042
|
|
|
|
2043
|
|
|
cmd = XmlCommand("stop_task") |
2044
|
|
|
cmd.set_attribute("task_id", audit_id) |
2045
|
|
|
|
2046
|
|
|
return self._send_xml_command(cmd) |
2047
|
|
|
|
2048
|
|
|
def get_info_list( |
2049
|
|
|
self, |
2050
|
|
|
info_type: InfoType, |
2051
|
|
|
*, |
2052
|
|
|
filter: Optional[str] = None, |
2053
|
|
|
filter_id: Optional[str] = None, |
2054
|
|
|
name: Optional[str] = None, |
2055
|
|
|
details: Optional[bool] = None, |
2056
|
|
|
) -> Any: |
2057
|
|
|
"""Request a list of security information |
2058
|
|
|
|
2059
|
|
|
Arguments: |
2060
|
|
|
info_type: Type must be either CERT_BUND_ADV, CPE, CVE, |
2061
|
|
|
DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
2062
|
|
|
filter: Filter term to use for the query |
2063
|
|
|
filter_id: UUID of an existing filter to use for the query |
2064
|
|
|
name: Name or identifier of the requested information |
2065
|
|
|
details: Whether to include information about references to this |
2066
|
|
|
information |
2067
|
|
|
|
2068
|
|
|
Returns: |
2069
|
|
|
The response. See :py:meth:`send_command` for details. |
2070
|
|
|
""" |
2071
|
|
|
if not info_type: |
2072
|
|
|
raise RequiredArgument( |
2073
|
|
|
function=self.get_info_list.__name__, argument='info_type' |
2074
|
|
|
) |
2075
|
|
|
|
2076
|
|
|
if not isinstance(info_type, InfoType): |
2077
|
|
|
raise InvalidArgumentType( |
2078
|
|
|
function=self.get_info_list.__name__, |
2079
|
|
|
argument='info_type', |
2080
|
|
|
arg_type=InfoType.__name__, |
2081
|
|
|
) |
2082
|
|
|
|
2083
|
|
|
cmd = XmlCommand("get_info") |
2084
|
|
|
|
2085
|
|
|
cmd.set_attribute("type", info_type.value) |
2086
|
|
|
|
2087
|
|
|
add_filter(cmd, filter, filter_id) |
2088
|
|
|
|
2089
|
|
|
if name: |
2090
|
|
|
cmd.set_attribute("name", name) |
2091
|
|
|
|
2092
|
|
|
if details is not None: |
2093
|
|
|
cmd.set_attribute("details", to_bool(details)) |
2094
|
|
|
|
2095
|
|
|
return self._send_xml_command(cmd) |
2096
|
|
|
|
2097
|
|
|
def get_info(self, info_id: str, info_type: InfoType) -> Any: |
2098
|
|
|
"""Request a single secinfo |
2099
|
|
|
|
2100
|
|
|
Arguments: |
2101
|
|
|
info_id: UUID of an existing secinfo |
2102
|
|
|
info_type: Type must be either CERT_BUND_ADV, CPE, CVE, |
2103
|
|
|
DFN_CERT_ADV, OVALDEF, NVT |
2104
|
|
|
|
2105
|
|
|
Returns: |
2106
|
|
|
The response. See :py:meth:`send_command` for details. |
2107
|
|
|
""" |
2108
|
|
|
if not info_type: |
2109
|
|
|
raise RequiredArgument( |
2110
|
|
|
function=self.get_info.__name__, argument='info_type' |
2111
|
|
|
) |
2112
|
|
|
|
2113
|
|
|
if not isinstance(info_type, InfoType): |
2114
|
|
|
raise InvalidArgumentType( |
2115
|
|
|
function=self.get_info.__name__, |
2116
|
|
|
argument='info_type', |
2117
|
|
|
arg_type=InfoType.__name__, |
2118
|
|
|
) |
2119
|
|
|
|
2120
|
|
|
if not info_id: |
2121
|
|
|
raise RequiredArgument( |
2122
|
|
|
function=self.get_info.__name__, argument='info_id' |
2123
|
|
|
) |
2124
|
|
|
|
2125
|
|
|
cmd = XmlCommand("get_info") |
2126
|
|
|
cmd.set_attribute("info_id", info_id) |
2127
|
|
|
|
2128
|
|
|
cmd.set_attribute("type", info_type.value) |
2129
|
|
|
|
2130
|
|
|
# for single entity always request all details |
2131
|
|
|
cmd.set_attribute("details", "1") |
2132
|
|
|
return self._send_xml_command(cmd) |
2133
|
|
|
|
2134
|
|
|
def get_feed(self, feed_type: Optional[FeedType]) -> Any: |
2135
|
|
|
"""Request a single feed |
2136
|
|
|
|
2137
|
|
|
Arguments: |
2138
|
|
|
feed_type: Type of single feed to get: NVT, CERT or SCAP |
2139
|
|
|
|
2140
|
|
|
Returns: |
2141
|
|
|
The response. See :py:meth:`send_command` for details. |
2142
|
|
|
""" |
2143
|
|
|
if not feed_type: |
2144
|
|
|
raise RequiredArgument( |
2145
|
|
|
function=self.get_feed.__name__, argument='feed_type' |
2146
|
|
|
) |
2147
|
|
|
|
2148
|
|
|
if not isinstance(feed_type, FeedType): |
2149
|
|
|
raise InvalidArgumentType( |
2150
|
|
|
function=self.get_feed.__name__, |
2151
|
|
|
argument='feed_type', |
2152
|
|
|
arg_type=FeedType.__name__, |
2153
|
|
|
) |
2154
|
|
|
|
2155
|
|
|
cmd = XmlCommand("get_feeds") |
2156
|
|
|
cmd.set_attribute("type", feed_type.value) |
2157
|
|
|
|
2158
|
|
|
return self._send_xml_command(cmd) |
2159
|
|
|
|
2160
|
|
|
def create_credential( |
2161
|
|
|
self, |
2162
|
|
|
name: str, |
2163
|
|
|
credential_type: CredentialType, |
2164
|
|
|
*, |
2165
|
|
|
comment: Optional[str] = None, |
2166
|
|
|
allow_insecure: Optional[bool] = None, |
2167
|
|
|
certificate: Optional[str] = None, |
2168
|
|
|
key_phrase: Optional[str] = None, |
2169
|
|
|
private_key: Optional[str] = None, |
2170
|
|
|
login: Optional[str] = None, |
2171
|
|
|
password: Optional[str] = None, |
2172
|
|
|
auth_algorithm: Optional[SnmpAuthAlgorithm] = None, |
2173
|
|
|
community: Optional[str] = None, |
2174
|
|
|
privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None, |
2175
|
|
|
privacy_password: Optional[str] = None, |
2176
|
|
|
public_key: Optional[str] = None, |
2177
|
|
|
) -> Any: |
2178
|
|
|
"""Create a new credential |
2179
|
|
|
|
2180
|
|
|
Create a new credential e.g. to be used in the method of an alert. |
2181
|
|
|
|
2182
|
|
|
Currently the following credential types are supported: |
2183
|
|
|
|
2184
|
|
|
- Username + Password |
2185
|
|
|
- Username + SSH-Key |
2186
|
|
|
- Client Certificates |
2187
|
|
|
- SNMPv1 or SNMPv2c protocol |
2188
|
|
|
- S/MIME Certificate |
2189
|
|
|
- OpenPGP Key |
2190
|
|
|
- Password only |
2191
|
|
|
|
2192
|
|
|
Arguments: |
2193
|
|
|
name: Name of the new credential |
2194
|
|
|
credential_type: The credential type. |
2195
|
|
|
comment: Comment for the credential |
2196
|
|
|
allow_insecure: Whether to allow insecure use of the credential |
2197
|
|
|
certificate: Certificate for the credential. |
2198
|
|
|
Required for client-certificate and smime credential types. |
2199
|
|
|
key_phrase: Key passphrase for the private key. |
2200
|
|
|
Used for the username+ssh-key credential type. |
2201
|
|
|
private_key: Private key to use for login. Required |
2202
|
|
|
for usk credential type. Also used for the cc credential type. |
2203
|
|
|
The supported key types (dsa, rsa, ecdsa, ...) and formats (PEM, |
2204
|
|
|
PKC#12, OpenSSL, ...) depend on your installed GnuTLS version. |
2205
|
|
|
login: Username for the credential. Required for username+password, |
2206
|
|
|
username+ssh-key and snmp credential type. |
2207
|
|
|
password: Password for the credential. Used for username+password |
2208
|
|
|
and snmp credential types. |
2209
|
|
|
community: The SNMP community |
2210
|
|
|
auth_algorithm: The SNMP authentication algorithm. Required for snmp |
2211
|
|
|
credential type. |
2212
|
|
|
privacy_algorithm: The SNMP privacy algorithm |
2213
|
|
|
privacy_password: The SNMP privacy password |
2214
|
|
|
public_key: PGP public key in *armor* plain text format. Required |
2215
|
|
|
for pgp credential type. |
2216
|
|
|
|
2217
|
|
|
Examples: |
2218
|
|
|
Creating a Username + Password credential |
2219
|
|
|
|
2220
|
|
|
.. code-block:: python |
2221
|
|
|
|
2222
|
|
|
gmp.create_credential( |
2223
|
|
|
name='UP Credential', |
2224
|
|
|
credential_type=CredentialType.USERNAME_PASSWORD, |
2225
|
|
|
login='foo', |
2226
|
|
|
password='bar', |
2227
|
|
|
) |
2228
|
|
|
|
2229
|
|
|
Creating a Username + SSH Key credential |
2230
|
|
|
|
2231
|
|
|
.. code-block:: python |
2232
|
|
|
|
2233
|
|
|
with open('path/to/private-ssh-key') as f: |
2234
|
|
|
key = f.read() |
2235
|
|
|
|
2236
|
|
|
gmp.create_credential( |
2237
|
|
|
name='USK Credential', |
2238
|
|
|
credential_type=CredentialType.USERNAME_SSH_KEY, |
2239
|
|
|
login='foo', |
2240
|
|
|
key_phrase='foobar', |
2241
|
|
|
private_key=key, |
2242
|
|
|
) |
2243
|
|
|
|
2244
|
|
|
Creating a PGP credential |
2245
|
|
|
|
2246
|
|
|
.. note:: |
2247
|
|
|
|
2248
|
|
|
A compatible public pgp key file can be exported with GnuPG via |
2249
|
|
|
:: |
2250
|
|
|
|
2251
|
|
|
$ gpg --armor --export [email protected] > alice.asc |
2252
|
|
|
|
2253
|
|
|
.. code-block:: python |
2254
|
|
|
|
2255
|
|
|
with open('path/to/pgp.key.asc') as f: |
2256
|
|
|
key = f.read() |
2257
|
|
|
|
2258
|
|
|
gmp.create_credential( |
2259
|
|
|
name='PGP Credential', |
2260
|
|
|
credential_type=CredentialType.PGP_ENCRYPTION_KEY, |
2261
|
|
|
public_key=key, |
2262
|
|
|
) |
2263
|
|
|
|
2264
|
|
|
Creating a S/MIME credential |
2265
|
|
|
|
2266
|
|
|
.. code-block:: python |
2267
|
|
|
|
2268
|
|
|
with open('path/to/smime-cert') as f: |
2269
|
|
|
cert = f.read() |
2270
|
|
|
|
2271
|
|
|
gmp.create_credential( |
2272
|
|
|
name='SMIME Credential', |
2273
|
|
|
credential_type=CredentialType.SMIME_CERTIFICATE, |
2274
|
|
|
certificate=cert, |
2275
|
|
|
) |
2276
|
|
|
|
2277
|
|
|
Creating a Password-Only credential |
2278
|
|
|
|
2279
|
|
|
.. code-block:: python |
2280
|
|
|
|
2281
|
|
|
gmp.create_credential( |
2282
|
|
|
name='Password-Only Credential', |
2283
|
|
|
credential_type=CredentialType.PASSWORD_ONLY, |
2284
|
|
|
password='foo', |
2285
|
|
|
) |
2286
|
|
|
Returns: |
2287
|
|
|
The response. See :py:meth:`send_command` for details. |
2288
|
|
|
""" |
2289
|
|
|
if not name: |
2290
|
|
|
raise RequiredArgument( |
2291
|
|
|
function=self.create_credential.__name__, argument='name' |
2292
|
|
|
) |
2293
|
|
|
|
2294
|
|
|
if not isinstance(credential_type, self.types.CredentialType): |
2295
|
|
|
raise InvalidArgumentType( |
2296
|
|
|
function=self.create_credential.__name__, |
2297
|
|
|
argument='credential_type', |
2298
|
|
|
arg_type=CredentialType.__name__, |
2299
|
|
|
) |
2300
|
|
|
|
2301
|
|
|
cmd = XmlCommand("create_credential") |
2302
|
|
|
cmd.add_element("name", name) |
2303
|
|
|
|
2304
|
|
|
cmd.add_element("type", credential_type.value) |
2305
|
|
|
|
2306
|
|
|
if comment: |
2307
|
|
|
cmd.add_element("comment", comment) |
2308
|
|
|
|
2309
|
|
|
if allow_insecure is not None: |
2310
|
|
|
cmd.add_element("allow_insecure", to_bool(allow_insecure)) |
2311
|
|
|
|
2312
|
|
|
if ( |
2313
|
|
|
credential_type == CredentialType.CLIENT_CERTIFICATE |
2314
|
|
|
or credential_type == CredentialType.SMIME_CERTIFICATE |
2315
|
|
|
): |
2316
|
|
|
if not certificate: |
2317
|
|
|
raise RequiredArgument( |
2318
|
|
|
function=self.create_credential.__name__, |
2319
|
|
|
argument='certificate', |
2320
|
|
|
) |
2321
|
|
|
|
2322
|
|
|
cmd.add_element("certificate", certificate) |
2323
|
|
|
|
2324
|
|
|
if ( |
2325
|
|
|
credential_type == CredentialType.USERNAME_PASSWORD |
2326
|
|
|
or credential_type == CredentialType.USERNAME_SSH_KEY |
2327
|
|
|
or credential_type == CredentialType.SNMP |
2328
|
|
|
): |
2329
|
|
|
if not login: |
2330
|
|
|
raise RequiredArgument( |
2331
|
|
|
function=self.create_credential.__name__, argument='login' |
2332
|
|
|
) |
2333
|
|
|
|
2334
|
|
|
cmd.add_element("login", login) |
2335
|
|
|
|
2336
|
|
|
if credential_type == CredentialType.PASSWORD_ONLY and not password: |
2337
|
|
|
raise RequiredArgument( |
2338
|
|
|
function=self.create_credential.__name__, argument='password' |
2339
|
|
|
) |
2340
|
|
|
|
2341
|
|
|
if ( |
2342
|
|
|
credential_type == CredentialType.USERNAME_PASSWORD |
2343
|
|
|
or credential_type == CredentialType.SNMP |
2344
|
|
|
or credential_type == CredentialType.PASSWORD_ONLY |
2345
|
|
|
) and password: |
2346
|
|
|
cmd.add_element("password", password) |
2347
|
|
|
|
2348
|
|
|
if credential_type == CredentialType.USERNAME_SSH_KEY: |
2349
|
|
|
if not private_key: |
2350
|
|
|
raise RequiredArgument( |
2351
|
|
|
function=self.create_credential.__name__, |
2352
|
|
|
argument='private_key', |
2353
|
|
|
) |
2354
|
|
|
|
2355
|
|
|
_xmlkey = cmd.add_element("key") |
2356
|
|
|
_xmlkey.add_element("private", private_key) |
2357
|
|
|
|
2358
|
|
|
if key_phrase: |
2359
|
|
|
_xmlkey.add_element("phrase", key_phrase) |
2360
|
|
|
|
2361
|
|
|
if credential_type == CredentialType.CLIENT_CERTIFICATE and private_key: |
2362
|
|
|
_xmlkey = cmd.add_element("key") |
2363
|
|
|
_xmlkey.add_element("private", private_key) |
2364
|
|
|
|
2365
|
|
|
if credential_type == CredentialType.SNMP: |
2366
|
|
|
if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm): |
2367
|
|
|
raise InvalidArgumentType( |
2368
|
|
|
function=self.create_credential.__name__, |
2369
|
|
|
argument='auth_algorithm', |
2370
|
|
|
arg_type=SnmpAuthAlgorithm.__name__, |
2371
|
|
|
) |
2372
|
|
|
|
2373
|
|
|
cmd.add_element("auth_algorithm", auth_algorithm.value) |
2374
|
|
|
|
2375
|
|
|
if community: |
2376
|
|
|
cmd.add_element("community", community) |
2377
|
|
|
|
2378
|
|
View Code Duplication |
if privacy_algorithm is not None or privacy_password: |
|
|
|
|
2379
|
|
|
_xmlprivacy = cmd.add_element("privacy") |
2380
|
|
|
|
2381
|
|
|
if privacy_algorithm is not None: |
2382
|
|
|
if not isinstance( |
2383
|
|
|
privacy_algorithm, self.types.SnmpPrivacyAlgorithm |
2384
|
|
|
): |
2385
|
|
|
raise InvalidArgumentType( |
2386
|
|
|
function=self.create_credential.__name__, |
2387
|
|
|
argument='privacy_algorithm', |
2388
|
|
|
arg_type=SnmpPrivacyAlgorithm.__name__, |
2389
|
|
|
) |
2390
|
|
|
|
2391
|
|
|
_xmlprivacy.add_element( |
2392
|
|
|
"algorithm", privacy_algorithm.value |
2393
|
|
|
) |
2394
|
|
|
|
2395
|
|
|
if privacy_password: |
2396
|
|
|
_xmlprivacy.add_element("password", privacy_password) |
2397
|
|
|
|
2398
|
|
|
if credential_type == CredentialType.PGP_ENCRYPTION_KEY: |
2399
|
|
|
if not public_key: |
2400
|
|
|
raise RequiredArgument( |
2401
|
|
|
function=self.create_credential.__name__, |
2402
|
|
|
argument='public_key', |
2403
|
|
|
) |
2404
|
|
|
|
2405
|
|
|
_xmlkey = cmd.add_element("key") |
2406
|
|
|
_xmlkey.add_element("public", public_key) |
2407
|
|
|
|
2408
|
|
|
return self._send_xml_command(cmd) |
2409
|
|
|
|
2410
|
|
|
def modify_credential( |
2411
|
|
|
self, |
2412
|
|
|
credential_id: str, |
2413
|
|
|
*, |
2414
|
|
|
name: Optional[str] = None, |
2415
|
|
|
comment: Optional[str] = None, |
2416
|
|
|
allow_insecure: Optional[bool] = None, |
2417
|
|
|
certificate: Optional[str] = None, |
2418
|
|
|
key_phrase: Optional[str] = None, |
2419
|
|
|
private_key: Optional[str] = None, |
2420
|
|
|
login: Optional[str] = None, |
2421
|
|
|
password: Optional[str] = None, |
2422
|
|
|
auth_algorithm: Optional[SnmpAuthAlgorithm] = None, |
2423
|
|
|
community: Optional[str] = None, |
2424
|
|
|
privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None, |
2425
|
|
|
privacy_password: Optional[str] = None, |
2426
|
|
|
public_key: Optional[str] = None, |
2427
|
|
|
) -> Any: |
2428
|
|
|
"""Modifies an existing credential. |
2429
|
|
|
|
2430
|
|
|
Arguments: |
2431
|
|
|
credential_id: UUID of the credential |
2432
|
|
|
name: Name of the credential |
2433
|
|
|
comment: Comment for the credential |
2434
|
|
|
allow_insecure: Whether to allow insecure use of the credential |
2435
|
|
|
certificate: Certificate for the credential |
2436
|
|
|
key_phrase: Key passphrase for the private key |
2437
|
|
|
private_key: Private key to use for login |
2438
|
|
|
login: Username for the credential |
2439
|
|
|
password: Password for the credential |
2440
|
|
|
auth_algorithm: The authentication algorithm for SNMP |
2441
|
|
|
community: The SNMP community |
2442
|
|
|
privacy_algorithm: The privacy algorithm for SNMP |
2443
|
|
|
privacy_password: The SNMP privacy password |
2444
|
|
|
public_key: PGP public key in *armor* plain text format |
2445
|
|
|
|
2446
|
|
|
Returns: |
2447
|
|
|
The response. See :py:meth:`send_command` for details. |
2448
|
|
|
""" |
2449
|
|
|
if not credential_id: |
2450
|
|
|
raise RequiredArgument( |
2451
|
|
|
function=self.modify_credential.__name__, |
2452
|
|
|
argument='credential_id', |
2453
|
|
|
) |
2454
|
|
|
|
2455
|
|
|
cmd = XmlCommand("modify_credential") |
2456
|
|
|
cmd.set_attribute("credential_id", credential_id) |
2457
|
|
|
|
2458
|
|
|
if comment: |
2459
|
|
|
cmd.add_element("comment", comment) |
2460
|
|
|
|
2461
|
|
|
if name: |
2462
|
|
|
cmd.add_element("name", name) |
2463
|
|
|
|
2464
|
|
|
if allow_insecure is not None: |
2465
|
|
|
cmd.add_element("allow_insecure", to_bool(allow_insecure)) |
2466
|
|
|
|
2467
|
|
|
if certificate: |
2468
|
|
|
cmd.add_element("certificate", certificate) |
2469
|
|
|
|
2470
|
|
|
if key_phrase and private_key: |
2471
|
|
|
_xmlkey = cmd.add_element("key") |
2472
|
|
|
_xmlkey.add_element("phrase", key_phrase) |
2473
|
|
|
_xmlkey.add_element("private", private_key) |
2474
|
|
|
elif (not key_phrase and private_key) or ( |
2475
|
|
|
key_phrase and not private_key |
2476
|
|
|
): |
2477
|
|
|
raise RequiredArgument( |
2478
|
|
|
function=self.modify_credential.__name__, |
2479
|
|
|
argument='key_phrase and private_key', |
2480
|
|
|
) |
2481
|
|
|
|
2482
|
|
|
if login: |
2483
|
|
|
cmd.add_element("login", login) |
2484
|
|
|
|
2485
|
|
|
if password: |
2486
|
|
|
cmd.add_element("password", password) |
2487
|
|
|
|
2488
|
|
|
if auth_algorithm: |
2489
|
|
|
if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm): |
2490
|
|
|
raise InvalidArgumentType( |
2491
|
|
|
function=self.modify_credential.__name__, |
2492
|
|
|
argument='auth_algorithm', |
2493
|
|
|
arg_type=SnmpAuthAlgorithm.__name__, |
2494
|
|
|
) |
2495
|
|
|
cmd.add_element("auth_algorithm", auth_algorithm.value) |
2496
|
|
|
|
2497
|
|
|
if community: |
2498
|
|
|
cmd.add_element("community", community) |
2499
|
|
|
|
2500
|
|
View Code Duplication |
if privacy_algorithm is not None or privacy_password is not None: |
|
|
|
|
2501
|
|
|
_xmlprivacy = cmd.add_element("privacy") |
2502
|
|
|
|
2503
|
|
|
if privacy_algorithm is not None: |
2504
|
|
|
if not isinstance( |
2505
|
|
|
privacy_algorithm, self.types.SnmpPrivacyAlgorithm |
2506
|
|
|
): |
2507
|
|
|
raise InvalidArgumentType( |
2508
|
|
|
function=self.modify_credential.__name__, |
2509
|
|
|
argument='privacy_algorithm', |
2510
|
|
|
arg_type=SnmpPrivacyAlgorithm.__name__, |
2511
|
|
|
) |
2512
|
|
|
|
2513
|
|
|
_xmlprivacy.add_element("algorithm", privacy_algorithm.value) |
2514
|
|
|
|
2515
|
|
|
if privacy_password is not None: |
2516
|
|
|
_xmlprivacy.add_element("password", privacy_password) |
2517
|
|
|
|
2518
|
|
|
if public_key: |
2519
|
|
|
_xmlkey = cmd.add_element("key") |
2520
|
|
|
_xmlkey.add_element("public", public_key) |
2521
|
|
|
|
2522
|
|
|
return self._send_xml_command(cmd) |
2523
|
|
|
|
2524
|
|
|
def create_ticket( |
2525
|
|
|
self, |
2526
|
|
|
*, |
2527
|
|
|
result_id: str, |
2528
|
|
|
assigned_to_user_id: str, |
2529
|
|
|
note: str, |
2530
|
|
|
comment: Optional[str] = None, |
2531
|
|
|
) -> Any: |
2532
|
|
|
"""Create a new ticket |
2533
|
|
|
|
2534
|
|
|
Arguments: |
2535
|
|
|
result_id: UUID of the result the ticket applies to |
2536
|
|
|
assigned_to_user_id: UUID of a user the ticket should be assigned to |
2537
|
|
|
note: A note about opening the ticket |
2538
|
|
|
comment: Comment for the ticket |
2539
|
|
|
|
2540
|
|
|
Returns: |
2541
|
|
|
The response. See :py:meth:`send_command` for details. |
2542
|
|
|
""" |
2543
|
|
|
if not result_id: |
2544
|
|
|
raise RequiredArgument( |
2545
|
|
|
function=self.create_ticket.__name__, argument='result_id' |
2546
|
|
|
) |
2547
|
|
|
|
2548
|
|
|
if not assigned_to_user_id: |
2549
|
|
|
raise RequiredArgument( |
2550
|
|
|
function=self.create_ticket.__name__, |
2551
|
|
|
argument='assigned_to_user_id', |
2552
|
|
|
) |
2553
|
|
|
|
2554
|
|
|
if not note: |
2555
|
|
|
raise RequiredArgument( |
2556
|
|
|
function=self.create_ticket.__name__, argument='note' |
2557
|
|
|
) |
2558
|
|
|
|
2559
|
|
|
cmd = XmlCommand("create_ticket") |
2560
|
|
|
|
2561
|
|
|
_result = cmd.add_element("result") |
2562
|
|
|
_result.set_attribute("id", result_id) |
2563
|
|
|
|
2564
|
|
|
_assigned = cmd.add_element("assigned_to") |
2565
|
|
|
_user = _assigned.add_element("user") |
2566
|
|
|
_user.set_attribute("id", assigned_to_user_id) |
2567
|
|
|
|
2568
|
|
|
_note = cmd.add_element("open_note", note) |
2569
|
|
|
|
2570
|
|
|
if comment: |
2571
|
|
|
cmd.add_element("comment", comment) |
2572
|
|
|
|
2573
|
|
|
return self._send_xml_command(cmd) |
2574
|
|
|
|
2575
|
|
|
def delete_ticket( |
2576
|
|
|
self, ticket_id: str, *, ultimate: Optional[bool] = False |
2577
|
|
|
): |
2578
|
|
|
"""Deletes an existing ticket |
2579
|
|
|
|
2580
|
|
|
Arguments: |
2581
|
|
|
ticket_id: UUID of the ticket to be deleted. |
2582
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
2583
|
|
|
""" |
2584
|
|
|
if not ticket_id: |
2585
|
|
|
raise RequiredArgument( |
2586
|
|
|
function=self.delete_ticket.__name__, argument='ticket_id' |
2587
|
|
|
) |
2588
|
|
|
|
2589
|
|
|
cmd = XmlCommand("delete_ticket") |
2590
|
|
|
cmd.set_attribute("ticket_id", ticket_id) |
2591
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
2592
|
|
|
|
2593
|
|
|
return self._send_xml_command(cmd) |
2594
|
|
|
|
2595
|
|
View Code Duplication |
def get_tickets( |
|
|
|
|
2596
|
|
|
self, |
2597
|
|
|
*, |
2598
|
|
|
trash: Optional[bool] = None, |
2599
|
|
|
filter: Optional[str] = None, |
2600
|
|
|
filter_id: Optional[str] = None, |
2601
|
|
|
) -> Any: |
2602
|
|
|
"""Request a list of tickets |
2603
|
|
|
|
2604
|
|
|
Arguments: |
2605
|
|
|
filter: Filter term to use for the query |
2606
|
|
|
filter_id: UUID of an existing filter to use for the query |
2607
|
|
|
trash: True to request the tickets in the trashcan |
2608
|
|
|
|
2609
|
|
|
Returns: |
2610
|
|
|
The response. See :py:meth:`send_command` for details. |
2611
|
|
|
""" |
2612
|
|
|
cmd = XmlCommand("get_tickets") |
2613
|
|
|
|
2614
|
|
|
add_filter(cmd, filter, filter_id) |
2615
|
|
|
|
2616
|
|
|
if trash is not None: |
2617
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
2618
|
|
|
|
2619
|
|
|
return self._send_xml_command(cmd) |
2620
|
|
|
|
2621
|
|
|
def get_ticket(self, ticket_id: str) -> Any: |
2622
|
|
|
"""Request a single ticket |
2623
|
|
|
|
2624
|
|
|
Arguments: |
2625
|
|
|
ticket_id: UUID of an existing ticket |
2626
|
|
|
|
2627
|
|
|
Returns: |
2628
|
|
|
The response. See :py:meth:`send_command` for details. |
2629
|
|
|
""" |
2630
|
|
|
if not ticket_id: |
2631
|
|
|
raise RequiredArgument( |
2632
|
|
|
function=self.get_ticket.__name__, argument='ticket_id' |
2633
|
|
|
) |
2634
|
|
|
|
2635
|
|
|
cmd = XmlCommand("get_tickets") |
2636
|
|
|
cmd.set_attribute("ticket_id", ticket_id) |
2637
|
|
|
return self._send_xml_command(cmd) |
2638
|
|
|
|
2639
|
|
|
def get_vulnerabilities( |
2640
|
|
|
self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
2641
|
|
|
) -> Any: |
2642
|
|
|
"""Request a list of vulnerabilities |
2643
|
|
|
|
2644
|
|
|
Arguments: |
2645
|
|
|
filter: Filter term to use for the query |
2646
|
|
|
filter_id: UUID of an existing filter to use for the query |
2647
|
|
|
Returns: |
2648
|
|
|
The response. See :py:meth:`send_command` for details. |
2649
|
|
|
""" |
2650
|
|
|
cmd = XmlCommand("get_vulns") |
2651
|
|
|
|
2652
|
|
|
add_filter(cmd, filter, filter_id) |
2653
|
|
|
|
2654
|
|
|
return self._send_xml_command(cmd) |
2655
|
|
|
|
2656
|
|
|
def get_vulnerability(self, vulnerability_id: str) -> Any: |
2657
|
|
|
"""Request a single vulnerability |
2658
|
|
|
|
2659
|
|
|
Arguments: |
2660
|
|
|
vulnerability_id: ID of an existing vulnerability |
2661
|
|
|
|
2662
|
|
|
Returns: |
2663
|
|
|
The response. See :py:meth:`send_command` for details. |
2664
|
|
|
""" |
2665
|
|
|
if not vulnerability_id: |
2666
|
|
|
raise RequiredArgument( |
2667
|
|
|
function=self.get_vulnerability.__name__, |
2668
|
|
|
argument='vulnerability_id', |
2669
|
|
|
) |
2670
|
|
|
|
2671
|
|
|
cmd = XmlCommand("get_vulns") |
2672
|
|
|
cmd.set_attribute("vuln_id", vulnerability_id) |
2673
|
|
|
return self._send_xml_command(cmd) |
2674
|
|
|
|
2675
|
|
|
def modify_ticket( |
2676
|
|
|
self, |
2677
|
|
|
ticket_id: str, |
2678
|
|
|
*, |
2679
|
|
|
status: Optional[TicketStatus] = None, |
2680
|
|
|
note: Optional[str] = None, |
2681
|
|
|
assigned_to_user_id: Optional[str] = None, |
2682
|
|
|
comment: Optional[str] = None, |
2683
|
|
|
) -> Any: |
2684
|
|
|
"""Modify a single ticket |
2685
|
|
|
|
2686
|
|
|
Arguments: |
2687
|
|
|
ticket_id: UUID of an existing ticket |
2688
|
|
|
status: New status for the ticket |
2689
|
|
|
note: Note for the status change. Required if status is set. |
2690
|
|
|
assigned_to_user_id: UUID of the user the ticket should be assigned |
2691
|
|
|
to |
2692
|
|
|
comment: Comment for the ticket |
2693
|
|
|
|
2694
|
|
|
Returns: |
2695
|
|
|
The response. See :py:meth:`send_command` for details. |
2696
|
|
|
""" |
2697
|
|
|
if not ticket_id: |
2698
|
|
|
raise RequiredArgument( |
2699
|
|
|
function=self.modify_ticket.__name__, argument='ticket_id' |
2700
|
|
|
) |
2701
|
|
|
|
2702
|
|
|
if status and not note: |
2703
|
|
|
raise RequiredArgument( |
2704
|
|
|
function=self.modify_ticket.__name__, argument='note' |
2705
|
|
|
) |
2706
|
|
|
|
2707
|
|
|
if note and not status: |
2708
|
|
|
raise RequiredArgument( |
2709
|
|
|
function=self.modify_ticket.__name__, argument='status' |
2710
|
|
|
) |
2711
|
|
|
|
2712
|
|
|
cmd = XmlCommand("modify_ticket") |
2713
|
|
|
cmd.set_attribute("ticket_id", ticket_id) |
2714
|
|
|
|
2715
|
|
|
if assigned_to_user_id: |
2716
|
|
|
_assigned = cmd.add_element("assigned_to") |
2717
|
|
|
_user = _assigned.add_element("user") |
2718
|
|
|
_user.set_attribute("id", assigned_to_user_id) |
2719
|
|
|
|
2720
|
|
|
if status: |
2721
|
|
|
if not isinstance(status, self.types.TicketStatus): |
2722
|
|
|
raise InvalidArgumentType( |
2723
|
|
|
function=self.modify_ticket.__name__, |
2724
|
|
|
argument='status', |
2725
|
|
|
arg_type=TicketStatus.__name__, |
2726
|
|
|
) |
2727
|
|
|
|
2728
|
|
|
cmd.add_element('status', status.value) |
2729
|
|
|
cmd.add_element('{}_note'.format(status.name.lower()), note) |
2730
|
|
|
|
2731
|
|
|
if comment: |
2732
|
|
|
cmd.add_element("comment", comment) |
2733
|
|
|
|
2734
|
|
|
return self._send_xml_command(cmd) |
2735
|
|
|
|
2736
|
|
View Code Duplication |
def create_filter( |
|
|
|
|
2737
|
|
|
self, |
2738
|
|
|
name: str, |
2739
|
|
|
*, |
2740
|
|
|
filter_type: Optional[FilterType] = None, |
2741
|
|
|
comment: Optional[str] = None, |
2742
|
|
|
term: Optional[str] = None, |
2743
|
|
|
) -> Any: |
2744
|
|
|
"""Create a new filter |
2745
|
|
|
|
2746
|
|
|
Arguments: |
2747
|
|
|
name: Name of the new filter |
2748
|
|
|
filter_type: Filter for entity type |
2749
|
|
|
comment: Comment for the filter |
2750
|
|
|
term: Filter term e.g. 'name=foo' |
2751
|
|
|
|
2752
|
|
|
Returns: |
2753
|
|
|
The response. See :py:meth:`send_command` for details. |
2754
|
|
|
""" |
2755
|
|
|
if not name: |
2756
|
|
|
raise RequiredArgument( |
2757
|
|
|
function=self.create_filter.__name__, argument="name" |
2758
|
|
|
) |
2759
|
|
|
|
2760
|
|
|
cmd = XmlCommand("create_filter") |
2761
|
|
|
_xmlname = cmd.add_element("name", name) |
2762
|
|
|
|
2763
|
|
|
if comment: |
2764
|
|
|
cmd.add_element("comment", comment) |
2765
|
|
|
|
2766
|
|
|
if term: |
2767
|
|
|
cmd.add_element("term", term) |
2768
|
|
|
|
2769
|
|
|
if filter_type: |
2770
|
|
|
if not isinstance(filter_type, self.types.FilterType): |
2771
|
|
|
raise InvalidArgumentType( |
2772
|
|
|
function=self.create_filter.__name__, |
2773
|
|
|
argument="filter_type", |
2774
|
|
|
arg_type=self.types.FilterType.__name__, |
2775
|
|
|
) |
2776
|
|
|
|
2777
|
|
|
cmd.add_element("type", filter_type.value) |
2778
|
|
|
|
2779
|
|
|
return self._send_xml_command(cmd) |
2780
|
|
|
|
2781
|
|
View Code Duplication |
def modify_filter( |
|
|
|
|
2782
|
|
|
self, |
2783
|
|
|
filter_id: str, |
2784
|
|
|
*, |
2785
|
|
|
comment: Optional[str] = None, |
2786
|
|
|
name: Optional[str] = None, |
2787
|
|
|
term: Optional[str] = None, |
2788
|
|
|
filter_type: Optional[FilterType] = None, |
2789
|
|
|
) -> Any: |
2790
|
|
|
"""Modifies an existing filter. |
2791
|
|
|
|
2792
|
|
|
Arguments: |
2793
|
|
|
filter_id: UUID of the filter to be modified |
2794
|
|
|
comment: Comment on filter. |
2795
|
|
|
name: Name of filter. |
2796
|
|
|
term: Filter term. |
2797
|
|
|
filter_type: Resource type filter applies to. |
2798
|
|
|
|
2799
|
|
|
Returns: |
2800
|
|
|
The response. See :py:meth:`send_command` for details. |
2801
|
|
|
""" |
2802
|
|
|
if not filter_id: |
2803
|
|
|
raise RequiredArgument( |
2804
|
|
|
function=self.modify_filter.__name__, argument='filter_id' |
2805
|
|
|
) |
2806
|
|
|
|
2807
|
|
|
cmd = XmlCommand("modify_filter") |
2808
|
|
|
cmd.set_attribute("filter_id", filter_id) |
2809
|
|
|
|
2810
|
|
|
if comment: |
2811
|
|
|
cmd.add_element("comment", comment) |
2812
|
|
|
|
2813
|
|
|
if name: |
2814
|
|
|
cmd.add_element("name", name) |
2815
|
|
|
|
2816
|
|
|
if term: |
2817
|
|
|
cmd.add_element("term", term) |
2818
|
|
|
|
2819
|
|
|
if filter_type: |
2820
|
|
|
if not isinstance(filter_type, self.types.FilterType): |
2821
|
|
|
raise InvalidArgumentType( |
2822
|
|
|
function=self.modify_filter.__name__, |
2823
|
|
|
argument='filter_type', |
2824
|
|
|
arg_type=FilterType.__name__, |
2825
|
|
|
) |
2826
|
|
|
cmd.add_element("type", filter_type.value) |
2827
|
|
|
|
2828
|
|
|
return self._send_xml_command(cmd) |
2829
|
|
|
|
2830
|
|
|
def create_schedule( |
2831
|
|
|
self, |
2832
|
|
|
name: str, |
2833
|
|
|
icalendar: str, |
2834
|
|
|
timezone: str, |
2835
|
|
|
*, |
2836
|
|
|
comment: Optional[str] = None, |
2837
|
|
|
) -> Any: |
2838
|
|
|
"""Create a new schedule based in `iCalendar`_ data. |
2839
|
|
|
|
2840
|
|
|
Example: |
2841
|
|
|
Requires https://pypi.org/project/icalendar/ |
2842
|
|
|
|
2843
|
|
|
.. code-block:: python |
2844
|
|
|
|
2845
|
|
|
import pytz |
2846
|
|
|
|
2847
|
|
|
from datetime import datetime |
2848
|
|
|
|
2849
|
|
|
from icalendar import Calendar, Event |
2850
|
|
|
|
2851
|
|
|
cal = Calendar() |
2852
|
|
|
|
2853
|
|
|
cal.add('prodid', '-//Foo Bar//') |
2854
|
|
|
cal.add('version', '2.0') |
2855
|
|
|
|
2856
|
|
|
event = Event() |
2857
|
|
|
event.add('dtstamp', datetime.now(tz=pytz.UTC)) |
2858
|
|
|
event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc)) |
2859
|
|
|
|
2860
|
|
|
cal.add_component(event) |
2861
|
|
|
|
2862
|
|
|
gmp.create_schedule( |
2863
|
|
|
name="My Schedule", |
2864
|
|
|
icalendar=cal.to_ical(), |
2865
|
|
|
timezone='UTC' |
2866
|
|
|
) |
2867
|
|
|
|
2868
|
|
|
|
2869
|
|
|
Arguments: |
2870
|
|
|
name: Name of the new schedule |
2871
|
|
|
icalendar: `iCalendar`_ (RFC 5545) based data. |
2872
|
|
|
timezone: Timezone to use for the icalender events e.g |
2873
|
|
|
Europe/Berlin. If the datetime values in the icalendar data are |
2874
|
|
|
missing timezone information this timezone gets applied. |
2875
|
|
|
Otherwise the datetime values from the icalendar data are |
2876
|
|
|
displayed in this timezone |
2877
|
|
|
comment: Comment on schedule. |
2878
|
|
|
|
2879
|
|
|
Returns: |
2880
|
|
|
The response. See :py:meth:`send_command` for details. |
2881
|
|
|
|
2882
|
|
|
.. _iCalendar: |
2883
|
|
|
https://tools.ietf.org/html/rfc5545 |
2884
|
|
|
""" |
2885
|
|
|
if not name: |
2886
|
|
|
raise RequiredArgument( |
2887
|
|
|
function=self.create_schedule.__name__, argument='name' |
2888
|
|
|
) |
2889
|
|
|
if not icalendar: |
2890
|
|
|
raise RequiredArgument( |
2891
|
|
|
function=self.create_schedule.__name__, argument='icalendar' |
2892
|
|
|
) |
2893
|
|
|
if not timezone: |
2894
|
|
|
raise RequiredArgument( |
2895
|
|
|
function=self.create_schedule.__name__, argument='timezone' |
2896
|
|
|
) |
2897
|
|
|
|
2898
|
|
|
cmd = XmlCommand("create_schedule") |
2899
|
|
|
|
2900
|
|
|
cmd.add_element("name", name) |
2901
|
|
|
cmd.add_element("icalendar", icalendar) |
2902
|
|
|
cmd.add_element("timezone", timezone) |
2903
|
|
|
|
2904
|
|
|
if comment: |
2905
|
|
|
cmd.add_element("comment", comment) |
2906
|
|
|
|
2907
|
|
|
return self._send_xml_command(cmd) |
2908
|
|
|
|
2909
|
|
|
def modify_schedule( |
2910
|
|
|
self, |
2911
|
|
|
schedule_id: str, |
2912
|
|
|
*, |
2913
|
|
|
name: Optional[str] = None, |
2914
|
|
|
icalendar: Optional[str] = None, |
2915
|
|
|
timezone: Optional[str] = None, |
2916
|
|
|
comment: Optional[str] = None, |
2917
|
|
|
) -> Any: |
2918
|
|
|
"""Modifies an existing schedule |
2919
|
|
|
|
2920
|
|
|
Arguments: |
2921
|
|
|
schedule_id: UUID of the schedule to be modified |
2922
|
|
|
name: Name of the schedule |
2923
|
|
|
icalendar: `iCalendar`_ (RFC 5545) based data. |
2924
|
|
|
timezone: Timezone to use for the icalender events e.g |
2925
|
|
|
Europe/Berlin. If the datetime values in the icalendar data are |
2926
|
|
|
missing timezone information this timezone gets applied. |
2927
|
|
|
Otherwise the datetime values from the icalendar data are |
2928
|
|
|
displayed in this timezone |
2929
|
|
|
commenhedule. |
2930
|
|
|
|
2931
|
|
|
Returns: |
2932
|
|
|
The response. See :py:meth:`send_command` for details. |
2933
|
|
|
|
2934
|
|
|
.. _iCalendar: |
2935
|
|
|
https://tools.ietf.org/html/rfc5545 |
2936
|
|
|
""" |
2937
|
|
|
if not schedule_id: |
2938
|
|
|
raise RequiredArgument( |
2939
|
|
|
function=self.modify_schedule.__name__, argument='schedule_id' |
2940
|
|
|
) |
2941
|
|
|
|
2942
|
|
|
cmd = XmlCommand("modify_schedule") |
2943
|
|
|
cmd.set_attribute("schedule_id", schedule_id) |
2944
|
|
|
|
2945
|
|
|
if name: |
2946
|
|
|
cmd.add_element("name", name) |
2947
|
|
|
|
2948
|
|
|
if icalendar: |
2949
|
|
|
cmd.add_element("icalendar", icalendar) |
2950
|
|
|
|
2951
|
|
|
if timezone: |
2952
|
|
|
cmd.add_element("timezone", timezone) |
2953
|
|
|
|
2954
|
|
|
if comment: |
2955
|
|
|
cmd.add_element("comment", comment) |
2956
|
|
|
|
2957
|
|
|
return self._send_xml_command(cmd) |
2958
|
|
|
|
2959
|
|
|
def clone_config(self, config_id: str) -> Any: |
2960
|
|
|
"""Clone a scan config from an existing one |
2961
|
|
|
|
2962
|
|
|
Arguments: |
2963
|
|
|
config_id: UUID of the existing scan config |
2964
|
|
|
|
2965
|
|
|
Returns: |
2966
|
|
|
The response. See :py:meth:`send_command` for details. |
2967
|
|
|
""" |
2968
|
|
|
if not config_id: |
2969
|
|
|
raise RequiredArgument( |
2970
|
|
|
function=self.clone_config.__name__, argument='config_id' |
2971
|
|
|
) |
2972
|
|
|
|
2973
|
|
|
cmd = XmlCommand("create_config") |
2974
|
|
|
cmd.add_element("copy", config_id) |
2975
|
|
|
return self._send_xml_command(cmd) |
2976
|
|
|
|
2977
|
|
|
def import_config(self, config: str) -> Any: |
2978
|
|
|
"""Import a scan config from XML |
2979
|
|
|
|
2980
|
|
|
Arguments: |
2981
|
|
|
config: Scan Config XML as string to import. This XML must |
2982
|
|
|
contain a :code:`<get_configs_response>` root element. |
2983
|
|
|
|
2984
|
|
|
Returns: |
2985
|
|
|
The response. See :py:meth:`send_command` for details. |
2986
|
|
|
""" |
2987
|
|
|
if not config: |
2988
|
|
|
raise RequiredArgument( |
2989
|
|
|
function=self.import_config.__name__, argument='config' |
2990
|
|
|
) |
2991
|
|
|
|
2992
|
|
|
cmd = XmlCommand("create_config") |
2993
|
|
|
|
2994
|
|
|
try: |
2995
|
|
|
cmd.append_xml_str(config) |
2996
|
|
|
except etree.XMLSyntaxError as e: |
2997
|
|
|
raise InvalidArgument( |
2998
|
|
|
function=self.import_config.__name__, argument='config' |
2999
|
|
|
) from e |
3000
|
|
|
|
3001
|
|
|
return self._send_xml_command(cmd) |
3002
|
|
|
|
3003
|
|
|
def clone_credential(self, credential_id: str) -> Any: |
3004
|
|
|
"""Clone an existing credential |
3005
|
|
|
|
3006
|
|
|
Arguments: |
3007
|
|
|
credential_id: UUID of an existing credential to clone from |
3008
|
|
|
|
3009
|
|
|
Returns: |
3010
|
|
|
The response. See :py:meth:`send_command` for details. |
3011
|
|
|
""" |
3012
|
|
|
if not credential_id: |
3013
|
|
|
raise RequiredArgument( |
3014
|
|
|
function=self.clone_credential.__name__, |
3015
|
|
|
argument='credential_id', |
3016
|
|
|
) |
3017
|
|
|
|
3018
|
|
|
cmd = XmlCommand("create_credential") |
3019
|
|
|
cmd.add_element("copy", credential_id) |
3020
|
|
|
return self._send_xml_command(cmd) |
3021
|
|
|
|
3022
|
|
|
def clone_filter(self, filter_id: str) -> Any: |
3023
|
|
|
"""Clone an existing filter |
3024
|
|
|
|
3025
|
|
|
Arguments: |
3026
|
|
|
filter_id: UUID of an existing filter to clone from |
3027
|
|
|
|
3028
|
|
|
Returns: |
3029
|
|
|
The response. See :py:meth:`send_command` for details. |
3030
|
|
|
""" |
3031
|
|
|
if not filter_id: |
3032
|
|
|
raise RequiredArgument( |
3033
|
|
|
function=self.clone_filter.__name__, argument='filter_id' |
3034
|
|
|
) |
3035
|
|
|
|
3036
|
|
|
cmd = XmlCommand("create_filter") |
3037
|
|
|
cmd.add_element("copy", filter_id) |
3038
|
|
|
return self._send_xml_command(cmd) |
3039
|
|
|
|
3040
|
|
|
def create_group( |
3041
|
|
|
self, |
3042
|
|
|
name: str, |
3043
|
|
|
*, |
3044
|
|
|
comment: Optional[str] = None, |
3045
|
|
|
special: Optional[bool] = False, |
3046
|
|
|
users: Optional[List[str]] = None, |
3047
|
|
|
) -> Any: |
3048
|
|
|
"""Create a new group |
3049
|
|
|
|
3050
|
|
|
Arguments: |
3051
|
|
|
name: Name of the new group |
3052
|
|
|
comment: Comment for the group |
3053
|
|
|
special: Create permission giving members full access to each |
3054
|
|
|
other's entities |
3055
|
|
|
users: List of user names to be in the group |
3056
|
|
|
|
3057
|
|
|
Returns: |
3058
|
|
|
The response. See :py:meth:`send_command` for details. |
3059
|
|
|
""" |
3060
|
|
|
if not name: |
3061
|
|
|
raise RequiredArgument( |
3062
|
|
|
function=self.create_group.__name__, argument='name' |
3063
|
|
|
) |
3064
|
|
|
|
3065
|
|
|
cmd = XmlCommand("create_group") |
3066
|
|
|
cmd.add_element("name", name) |
3067
|
|
|
|
3068
|
|
|
if comment: |
3069
|
|
|
cmd.add_element("comment", comment) |
3070
|
|
|
|
3071
|
|
|
if special: |
3072
|
|
|
_xmlspecial = cmd.add_element("specials") |
3073
|
|
|
_xmlspecial.add_element("full") |
3074
|
|
|
|
3075
|
|
|
if users: |
3076
|
|
|
cmd.add_element("users", to_comma_list(users)) |
3077
|
|
|
|
3078
|
|
|
return self._send_xml_command(cmd) |
3079
|
|
|
|
3080
|
|
|
def clone_group(self, group_id: str) -> Any: |
3081
|
|
|
"""Clone an existing group |
3082
|
|
|
|
3083
|
|
|
Arguments: |
3084
|
|
|
group_id: UUID of an existing group to clone from |
3085
|
|
|
|
3086
|
|
|
Returns: |
3087
|
|
|
The response. See :py:meth:`send_command` for details. |
3088
|
|
|
""" |
3089
|
|
|
if not group_id: |
3090
|
|
|
raise RequiredArgument( |
3091
|
|
|
function=self.clone_group.__name__, argument='group_id' |
3092
|
|
|
) |
3093
|
|
|
|
3094
|
|
|
cmd = XmlCommand("create_group") |
3095
|
|
|
cmd.add_element("copy", group_id) |
3096
|
|
|
return self._send_xml_command(cmd) |
3097
|
|
|
|
3098
|
|
|
def create_host(self, name: str, *, comment: Optional[str] = None) -> Any: |
3099
|
|
|
"""Create a new host asset |
3100
|
|
|
|
3101
|
|
|
Arguments: |
3102
|
|
|
name: Name for the new host asset |
3103
|
|
|
comment: Comment for the new host asset |
3104
|
|
|
|
3105
|
|
|
Returns: |
3106
|
|
|
The response. See :py:meth:`send_command` for details. |
3107
|
|
|
""" |
3108
|
|
|
if not name: |
3109
|
|
|
raise RequiredArgument( |
3110
|
|
|
function=self.create_host.__name__, argument='name' |
3111
|
|
|
) |
3112
|
|
|
|
3113
|
|
|
cmd = XmlCommand("create_asset") |
3114
|
|
|
asset = cmd.add_element("asset") |
3115
|
|
|
asset.add_element("type", "host") # ignored for gmp7, required for gmp8 |
3116
|
|
|
asset.add_element("name", name) |
3117
|
|
|
|
3118
|
|
|
if comment: |
3119
|
|
|
asset.add_element("comment", comment) |
3120
|
|
|
|
3121
|
|
|
return self._send_xml_command(cmd) |
3122
|
|
|
|
3123
|
|
View Code Duplication |
def create_note( |
|
|
|
|
3124
|
|
|
self, |
3125
|
|
|
text: str, |
3126
|
|
|
nvt_oid: str, |
3127
|
|
|
*, |
3128
|
|
|
days_active: Optional[int] = None, |
3129
|
|
|
hosts: Optional[List[str]] = None, |
3130
|
|
|
port: Optional[int] = None, |
3131
|
|
|
result_id: Optional[str] = None, |
3132
|
|
|
severity: Optional[Severity] = None, |
3133
|
|
|
task_id: Optional[str] = None, |
3134
|
|
|
threat: Optional[SeverityLevel] = None, |
3135
|
|
|
) -> Any: |
3136
|
|
|
"""Create a new note |
3137
|
|
|
|
3138
|
|
|
Arguments: |
3139
|
|
|
text: Text of the new note |
3140
|
|
|
nvt_id: OID of the nvt to which note applies |
3141
|
|
|
days_active: Days note will be active. -1 on |
3142
|
|
|
always, 0 off |
3143
|
|
|
hosts: A list of hosts addresses |
3144
|
|
|
port: Port to which the note applies |
3145
|
|
|
result_id: UUID of a result to which note applies |
3146
|
|
|
severity: Severity to which note applies |
3147
|
|
|
task_id: UUID of task to which note applies |
3148
|
|
|
threat: Severity level to which note applies. Will be converted to |
3149
|
|
|
severity. |
3150
|
|
|
|
3151
|
|
|
Returns: |
3152
|
|
|
The response. See :py:meth:`send_command` for details. |
3153
|
|
|
""" |
3154
|
|
|
if not text: |
3155
|
|
|
raise RequiredArgument( |
3156
|
|
|
function=self.create_note.__name__, argument='text' |
3157
|
|
|
) |
3158
|
|
|
|
3159
|
|
|
if not nvt_oid: |
3160
|
|
|
raise RequiredArgument( |
3161
|
|
|
function=self.create_note.__name__, argument='nvt_oid' |
3162
|
|
|
) |
3163
|
|
|
|
3164
|
|
|
cmd = XmlCommand("create_note") |
3165
|
|
|
cmd.add_element("text", text) |
3166
|
|
|
cmd.add_element("nvt", attrs={"oid": nvt_oid}) |
3167
|
|
|
|
3168
|
|
|
if days_active is not None: |
3169
|
|
|
cmd.add_element("active", str(days_active)) |
3170
|
|
|
|
3171
|
|
|
if hosts: |
3172
|
|
|
cmd.add_element("hosts", to_comma_list(hosts)) |
3173
|
|
|
|
3174
|
|
|
if port: |
3175
|
|
|
cmd.add_element("port", str(port)) |
3176
|
|
|
|
3177
|
|
|
if result_id: |
3178
|
|
|
cmd.add_element("result", attrs={"id": result_id}) |
3179
|
|
|
|
3180
|
|
|
if severity: |
3181
|
|
|
cmd.add_element("severity", str(severity)) |
3182
|
|
|
|
3183
|
|
|
if task_id: |
3184
|
|
|
cmd.add_element("task", attrs={"id": task_id}) |
3185
|
|
|
|
3186
|
|
|
if threat is not None: |
3187
|
|
|
if not isinstance(threat, SeverityLevel): |
3188
|
|
|
raise InvalidArgumentType( |
3189
|
|
|
function="create_note", |
3190
|
|
|
argument="threat", |
3191
|
|
|
arg_type=SeverityLevel.__name__, |
3192
|
|
|
) |
3193
|
|
|
|
3194
|
|
|
cmd.add_element("threat", threat.value) |
3195
|
|
|
|
3196
|
|
|
return self._send_xml_command(cmd) |
3197
|
|
|
|
3198
|
|
|
def clone_note(self, note_id: str) -> Any: |
3199
|
|
|
"""Clone an existing note |
3200
|
|
|
|
3201
|
|
|
Arguments: |
3202
|
|
|
note_id: UUID of an existing note to clone from |
3203
|
|
|
|
3204
|
|
|
Returns: |
3205
|
|
|
The response. See :py:meth:`send_command` for details. |
3206
|
|
|
""" |
3207
|
|
|
if not note_id: |
3208
|
|
|
raise RequiredArgument( |
3209
|
|
|
function=self.clone_note.__name__, argument='note_id' |
3210
|
|
|
) |
3211
|
|
|
|
3212
|
|
|
cmd = XmlCommand("create_note") |
3213
|
|
|
cmd.add_element("copy", note_id) |
3214
|
|
|
return self._send_xml_command(cmd) |
3215
|
|
|
|
3216
|
|
View Code Duplication |
def create_override( |
|
|
|
|
3217
|
|
|
self, |
3218
|
|
|
text: str, |
3219
|
|
|
nvt_oid: str, |
3220
|
|
|
*, |
3221
|
|
|
days_active: Optional[int] = None, |
3222
|
|
|
hosts: Optional[List[str]] = None, |
3223
|
|
|
port: Optional[int] = None, |
3224
|
|
|
result_id: Optional[str] = None, |
3225
|
|
|
severity: Optional[Severity] = None, |
3226
|
|
|
new_severity: Optional[Severity] = None, |
3227
|
|
|
task_id: Optional[str] = None, |
3228
|
|
|
threat: Optional[SeverityLevel] = None, |
3229
|
|
|
new_threat: Optional[SeverityLevel] = None, |
3230
|
|
|
) -> Any: |
3231
|
|
|
"""Create a new override |
3232
|
|
|
|
3233
|
|
|
Arguments: |
3234
|
|
|
text: Text of the new override |
3235
|
|
|
nvt_id: OID of the nvt to which override applies |
3236
|
|
|
days_active: Days override will be active. -1 on always, 0 off |
3237
|
|
|
hosts: A list of host addresses |
3238
|
|
|
port: Port to which the override applies |
3239
|
|
|
result_id: UUID of a result to which override applies |
3240
|
|
|
severity: Severity to which override applies |
3241
|
|
|
new_severity: New severity for result |
3242
|
|
|
task_id: UUID of task to which override applies |
3243
|
|
|
threat: Severity level to which override applies. Will be converted |
3244
|
|
|
to severity. |
3245
|
|
|
new_threat: New severity level for results. Will be converted to |
3246
|
|
|
new_severity. |
3247
|
|
|
|
3248
|
|
|
Returns: |
3249
|
|
|
The response. See :py:meth:`send_command` for details. |
3250
|
|
|
""" |
3251
|
|
|
if not text: |
3252
|
|
|
raise RequiredArgument( |
3253
|
|
|
function=self.create_override.__name__, argument='text' |
3254
|
|
|
) |
3255
|
|
|
|
3256
|
|
|
if not nvt_oid: |
3257
|
|
|
raise RequiredArgument( |
3258
|
|
|
function=self.create_override.__name__, argument='nvt_oid' |
3259
|
|
|
) |
3260
|
|
|
|
3261
|
|
|
cmd = XmlCommand("create_override") |
3262
|
|
|
cmd.add_element("text", text) |
3263
|
|
|
cmd.add_element("nvt", attrs={"oid": nvt_oid}) |
3264
|
|
|
|
3265
|
|
|
if days_active is not None: |
3266
|
|
|
cmd.add_element("active", str(days_active)) |
3267
|
|
|
|
3268
|
|
|
if hosts: |
3269
|
|
|
cmd.add_element("hosts", to_comma_list(hosts)) |
3270
|
|
|
|
3271
|
|
|
if port: |
3272
|
|
|
cmd.add_element("port", str(port)) |
3273
|
|
|
|
3274
|
|
|
if result_id: |
3275
|
|
|
cmd.add_element("result", attrs={"id": result_id}) |
3276
|
|
|
|
3277
|
|
|
if severity: |
3278
|
|
|
cmd.add_element("severity", str(severity)) |
3279
|
|
|
|
3280
|
|
|
if new_severity: |
3281
|
|
|
cmd.add_element("new_severity", str(new_severity)) |
3282
|
|
|
|
3283
|
|
|
if task_id: |
3284
|
|
|
cmd.add_element("task", attrs={"id": task_id}) |
3285
|
|
|
|
3286
|
|
|
if threat is not None: |
3287
|
|
|
if not isinstance(threat, SeverityLevel): |
3288
|
|
|
raise InvalidArgumentType( |
3289
|
|
|
function=self.create_override.__name__, |
3290
|
|
|
argument="threat", |
3291
|
|
|
arg_type=SeverityLevel.__name__, |
3292
|
|
|
) |
3293
|
|
|
|
3294
|
|
|
cmd.add_element("threat", threat.value) |
3295
|
|
|
|
3296
|
|
|
if new_threat is not None: |
3297
|
|
|
if not isinstance(new_threat, SeverityLevel): |
3298
|
|
|
raise InvalidArgumentType( |
3299
|
|
|
function=self.create_override.__name__, |
3300
|
|
|
argument="new_threat", |
3301
|
|
|
arg_type=SeverityLevel.__name__, |
3302
|
|
|
) |
3303
|
|
|
|
3304
|
|
|
cmd.add_element("new_threat", new_threat.value) |
3305
|
|
|
|
3306
|
|
|
return self._send_xml_command(cmd) |
3307
|
|
|
|
3308
|
|
|
def clone_override(self, override_id: str) -> Any: |
3309
|
|
|
"""Clone an existing override |
3310
|
|
|
|
3311
|
|
|
Arguments: |
3312
|
|
|
override_id: UUID of an existing override to clone from |
3313
|
|
|
|
3314
|
|
|
Returns: |
3315
|
|
|
The response. See :py:meth:`send_command` for details. |
3316
|
|
|
""" |
3317
|
|
|
if not override_id: |
3318
|
|
|
raise RequiredArgument( |
3319
|
|
|
function=self.clone_override.__name__, argument='override_id' |
3320
|
|
|
) |
3321
|
|
|
|
3322
|
|
|
cmd = XmlCommand("create_override") |
3323
|
|
|
cmd.add_element("copy", override_id) |
3324
|
|
|
return self._send_xml_command(cmd) |
3325
|
|
|
|
3326
|
|
|
def clone_permission(self, permission_id: str) -> Any: |
3327
|
|
|
"""Clone an existing permission |
3328
|
|
|
|
3329
|
|
|
Arguments: |
3330
|
|
|
permission_id: UUID of an existing permission to clone from |
3331
|
|
|
|
3332
|
|
|
Returns: |
3333
|
|
|
The response. See :py:meth:`send_command` for details. |
3334
|
|
|
""" |
3335
|
|
|
if not permission_id: |
3336
|
|
|
raise RequiredArgument( |
3337
|
|
|
function=self.clone_permission.__name__, |
3338
|
|
|
argument='permission_id', |
3339
|
|
|
) |
3340
|
|
|
|
3341
|
|
|
cmd = XmlCommand("create_permission") |
3342
|
|
|
cmd.add_element("copy", permission_id) |
3343
|
|
|
return self._send_xml_command(cmd) |
3344
|
|
|
|
3345
|
|
|
def clone_report_format( |
3346
|
|
|
self, report_format_id: [Union[str, ReportFormatType]] |
3347
|
|
|
) -> Any: |
3348
|
|
|
"""Clone a report format from an existing one |
3349
|
|
|
|
3350
|
|
|
Arguments: |
3351
|
|
|
report_format_id: UUID of the existing report format |
3352
|
|
|
or ReportFormatType (enum) |
3353
|
|
|
|
3354
|
|
|
Returns: |
3355
|
|
|
The response. See :py:meth:`send_command` for details. |
3356
|
|
|
""" |
3357
|
|
|
if not report_format_id: |
3358
|
|
|
raise RequiredArgument( |
3359
|
|
|
function=self.clone_report_format.__name__, |
3360
|
|
|
argument='report_format_id', |
3361
|
|
|
) |
3362
|
|
|
|
3363
|
|
|
cmd = XmlCommand("create_report_format") |
3364
|
|
|
|
3365
|
|
|
if isinstance(report_format_id, ReportFormatType): |
3366
|
|
|
report_format_id = report_format_id.value |
3367
|
|
|
|
3368
|
|
|
cmd.add_element("copy", report_format_id) |
3369
|
|
|
return self._send_xml_command(cmd) |
3370
|
|
|
|
3371
|
|
|
def import_report_format(self, report_format: str) -> Any: |
3372
|
|
|
"""Import a report format from XML |
3373
|
|
|
|
3374
|
|
|
Arguments: |
3375
|
|
|
report_format: Report format XML as string to import. This XML must |
3376
|
|
|
contain a :code:`<get_report_formats_response>` root element. |
3377
|
|
|
|
3378
|
|
|
Returns: |
3379
|
|
|
The response. See :py:meth:`send_command` for details. |
3380
|
|
|
""" |
3381
|
|
|
if not report_format: |
3382
|
|
|
raise RequiredArgument( |
3383
|
|
|
function=self.import_report_format.__name__, |
3384
|
|
|
argument='report_format', |
3385
|
|
|
) |
3386
|
|
|
|
3387
|
|
|
cmd = XmlCommand("create_report_format") |
3388
|
|
|
|
3389
|
|
|
try: |
3390
|
|
|
cmd.append_xml_str(report_format) |
3391
|
|
|
except etree.XMLSyntaxError as e: |
3392
|
|
|
raise InvalidArgument( |
3393
|
|
|
function=self.import_report_format.__name__, |
3394
|
|
|
argument='report_format', |
3395
|
|
|
) from e |
3396
|
|
|
|
3397
|
|
|
return self._send_xml_command(cmd) |
3398
|
|
|
|
3399
|
|
|
def create_role( |
3400
|
|
|
self, |
3401
|
|
|
name: str, |
3402
|
|
|
*, |
3403
|
|
|
comment: Optional[str] = None, |
3404
|
|
|
users: Optional[List[str]] = None, |
3405
|
|
|
) -> Any: |
3406
|
|
|
"""Create a new role |
3407
|
|
|
|
3408
|
|
|
Arguments: |
3409
|
|
|
name: Name of the role |
3410
|
|
|
comment: Comment for the role |
3411
|
|
|
users: List of user names to add to the role |
3412
|
|
|
|
3413
|
|
|
Returns: |
3414
|
|
|
The response. See :py:meth:`send_command` for details. |
3415
|
|
|
""" |
3416
|
|
|
|
3417
|
|
|
if not name: |
3418
|
|
|
raise RequiredArgument( |
3419
|
|
|
function=self.create_role.__name__, argument='name' |
3420
|
|
|
) |
3421
|
|
|
|
3422
|
|
|
cmd = XmlCommand("create_role") |
3423
|
|
|
cmd.add_element("name", name) |
3424
|
|
|
|
3425
|
|
|
if comment: |
3426
|
|
|
cmd.add_element("comment", comment) |
3427
|
|
|
|
3428
|
|
|
if users: |
3429
|
|
|
cmd.add_element("users", to_comma_list(users)) |
3430
|
|
|
|
3431
|
|
|
return self._send_xml_command(cmd) |
3432
|
|
|
|
3433
|
|
|
def clone_role(self, role_id: str) -> Any: |
3434
|
|
|
"""Clone an existing role |
3435
|
|
|
|
3436
|
|
|
Arguments: |
3437
|
|
|
role_id: UUID of an existing role to clone from |
3438
|
|
|
|
3439
|
|
|
Returns: |
3440
|
|
|
The response. See :py:meth:`send_command` for details. |
3441
|
|
|
""" |
3442
|
|
|
if not role_id: |
3443
|
|
|
raise RequiredArgument( |
3444
|
|
|
function=self.clone_role.__name__, argument='role_id' |
3445
|
|
|
) |
3446
|
|
|
|
3447
|
|
|
cmd = XmlCommand("create_role") |
3448
|
|
|
cmd.add_element("copy", role_id) |
3449
|
|
|
return self._send_xml_command(cmd) |
3450
|
|
|
|
3451
|
|
|
def create_scanner( |
3452
|
|
|
self, |
3453
|
|
|
name: str, |
3454
|
|
|
host: str, |
3455
|
|
|
port: int, |
3456
|
|
|
scanner_type: ScannerType, |
3457
|
|
|
credential_id: str, |
3458
|
|
|
*, |
3459
|
|
|
ca_pub: Optional[str] = None, |
3460
|
|
|
comment: Optional[str] = None, |
3461
|
|
|
) -> Any: |
3462
|
|
|
"""Create a new scanner |
3463
|
|
|
|
3464
|
|
|
Arguments: |
3465
|
|
|
name: Name of the scanner |
3466
|
|
|
host: The host of the scanner |
3467
|
|
|
port: The port of the scanner |
3468
|
|
|
scanner_type: Type of the scanner. |
3469
|
|
|
credential_id: UUID of client certificate credential for the |
3470
|
|
|
scanner |
3471
|
|
|
ca_pub: Certificate of CA to verify scanner certificate |
3472
|
|
|
comment: Comment for the scanner |
3473
|
|
|
Returns: |
3474
|
|
|
The response. See :py:meth:`send_command` for details. |
3475
|
|
|
""" |
3476
|
|
|
if not name: |
3477
|
|
|
raise RequiredArgument( |
3478
|
|
|
function=self.create_scanner.__name__, argument='name' |
3479
|
|
|
) |
3480
|
|
|
|
3481
|
|
|
if not host: |
3482
|
|
|
raise RequiredArgument( |
3483
|
|
|
function=self.create_scanner.__name__, argument='host' |
3484
|
|
|
) |
3485
|
|
|
|
3486
|
|
|
if not port: |
3487
|
|
|
raise RequiredArgument( |
3488
|
|
|
function=self.create_scanner.__name__, argument='port' |
3489
|
|
|
) |
3490
|
|
|
|
3491
|
|
|
if not scanner_type: |
3492
|
|
|
raise RequiredArgument( |
3493
|
|
|
function=self.create_scanner.__name__, argument='scanner_type' |
3494
|
|
|
) |
3495
|
|
|
|
3496
|
|
|
if not credential_id: |
3497
|
|
|
raise RequiredArgument( |
3498
|
|
|
function=self.create_scanner.__name__, argument='credential_id' |
3499
|
|
|
) |
3500
|
|
|
|
3501
|
|
|
if not isinstance(scanner_type, self.types.ScannerType): |
3502
|
|
|
raise InvalidArgumentType( |
3503
|
|
|
function=self.create_scanner.__name__, |
3504
|
|
|
argument='scanner_type', |
3505
|
|
|
arg_type=self.types.ScannerType.__name__, |
3506
|
|
|
) |
3507
|
|
|
|
3508
|
|
|
cmd = XmlCommand("create_scanner") |
3509
|
|
|
cmd.add_element("name", name) |
3510
|
|
|
cmd.add_element("host", host) |
3511
|
|
|
cmd.add_element("port", str(port)) |
3512
|
|
|
cmd.add_element("type", scanner_type.value) |
3513
|
|
|
|
3514
|
|
|
if ca_pub: |
3515
|
|
|
cmd.add_element("ca_pub", ca_pub) |
3516
|
|
|
|
3517
|
|
|
cmd.add_element("credential", attrs={"id": str(credential_id)}) |
3518
|
|
|
|
3519
|
|
|
if comment: |
3520
|
|
|
cmd.add_element("comment", comment) |
3521
|
|
|
|
3522
|
|
|
return self._send_xml_command(cmd) |
3523
|
|
|
|
3524
|
|
|
def clone_scanner(self, scanner_id: str) -> Any: |
3525
|
|
|
"""Clone an existing scanner |
3526
|
|
|
|
3527
|
|
|
Arguments: |
3528
|
|
|
scanner_id: UUID of an existing scanner to clone from |
3529
|
|
|
|
3530
|
|
|
Returns: |
3531
|
|
|
The response. See :py:meth:`send_command` for details. |
3532
|
|
|
""" |
3533
|
|
|
if not scanner_id: |
3534
|
|
|
raise RequiredArgument( |
3535
|
|
|
function=self.clone_scanner.__name__, argument='scanner_id' |
3536
|
|
|
) |
3537
|
|
|
|
3538
|
|
|
cmd = XmlCommand("create_scanner") |
3539
|
|
|
cmd.add_element("copy", scanner_id) |
3540
|
|
|
return self._send_xml_command(cmd) |
3541
|
|
|
|
3542
|
|
|
def clone_schedule(self, schedule_id: str) -> Any: |
3543
|
|
|
"""Clone an existing schedule |
3544
|
|
|
|
3545
|
|
|
Arguments: |
3546
|
|
|
schedule_id: UUID of an existing schedule to clone from |
3547
|
|
|
|
3548
|
|
|
Returns: |
3549
|
|
|
The response. See :py:meth:`send_command` for details. |
3550
|
|
|
""" |
3551
|
|
|
if not schedule_id: |
3552
|
|
|
raise RequiredArgument( |
3553
|
|
|
function=self.clone_schedule.__name__, argument='schedule_id' |
3554
|
|
|
) |
3555
|
|
|
|
3556
|
|
|
cmd = XmlCommand("create_schedule") |
3557
|
|
|
cmd.add_element("copy", schedule_id) |
3558
|
|
|
return self._send_xml_command(cmd) |
3559
|
|
|
|
3560
|
|
|
def clone_tag(self, tag_id: str) -> Any: |
3561
|
|
|
"""Clone an existing tag |
3562
|
|
|
|
3563
|
|
|
Arguments: |
3564
|
|
|
tag_id: UUID of an existing tag to clone from |
3565
|
|
|
|
3566
|
|
|
Returns: |
3567
|
|
|
The response. See :py:meth:`send_command` for details. |
3568
|
|
|
""" |
3569
|
|
|
if not tag_id: |
3570
|
|
|
raise RequiredArgument( |
3571
|
|
|
function=self.clone_tag.__name__, argument='tag_id' |
3572
|
|
|
) |
3573
|
|
|
|
3574
|
|
|
cmd = XmlCommand("create_tag") |
3575
|
|
|
cmd.add_element("copy", tag_id) |
3576
|
|
|
return self._send_xml_command(cmd) |
3577
|
|
|
|
3578
|
|
|
def create_user( |
3579
|
|
|
self, |
3580
|
|
|
name: str, |
3581
|
|
|
*, |
3582
|
|
|
password: Optional[str] = None, |
3583
|
|
|
hosts: Optional[List[str]] = None, |
3584
|
|
|
hosts_allow: Optional[bool] = False, |
3585
|
|
|
ifaces: Optional[List[str]] = None, |
3586
|
|
|
ifaces_allow: Optional[bool] = False, |
3587
|
|
|
role_ids: Optional[List[str]] = None, |
3588
|
|
|
) -> Any: |
3589
|
|
|
"""Create a new user |
3590
|
|
|
|
3591
|
|
|
Arguments: |
3592
|
|
|
name: Name of the user |
3593
|
|
|
password: Password of the user |
3594
|
|
|
hosts: A list of host addresses (IPs, DNS names) |
3595
|
|
|
hosts_allow: If True allow only access to passed hosts otherwise |
3596
|
|
|
deny access. Default is False for deny hosts. |
3597
|
|
|
ifaces: A list of interface names |
3598
|
|
|
ifaces_allow: If True allow only access to passed interfaces |
3599
|
|
|
otherwise deny access. Default is False for deny interfaces. |
3600
|
|
|
role_ids: A list of role UUIDs for the user |
3601
|
|
|
|
3602
|
|
|
Returns: |
3603
|
|
|
The response. See :py:meth:`send_command` for details. |
3604
|
|
|
""" |
3605
|
|
|
if not name: |
3606
|
|
|
raise RequiredArgument( |
3607
|
|
|
function=self.create_user.__name__, argument='name' |
3608
|
|
|
) |
3609
|
|
|
|
3610
|
|
|
cmd = XmlCommand("create_user") |
3611
|
|
|
cmd.add_element("name", name) |
3612
|
|
|
|
3613
|
|
|
if password: |
3614
|
|
|
cmd.add_element("password", password) |
3615
|
|
|
|
3616
|
|
|
if hosts: |
3617
|
|
|
cmd.add_element( |
3618
|
|
|
"hosts", |
3619
|
|
|
to_comma_list(hosts), |
3620
|
|
|
attrs={"allow": to_bool(hosts_allow)}, |
3621
|
|
|
) |
3622
|
|
|
|
3623
|
|
|
if ifaces: |
3624
|
|
|
cmd.add_element( |
3625
|
|
|
"ifaces", |
3626
|
|
|
to_comma_list(ifaces), |
3627
|
|
|
attrs={"allow": to_bool(ifaces_allow)}, |
3628
|
|
|
) |
3629
|
|
|
|
3630
|
|
|
if role_ids: |
3631
|
|
|
for role in role_ids: |
3632
|
|
|
cmd.add_element("role", attrs={"id": role}) |
3633
|
|
|
|
3634
|
|
|
return self._send_xml_command(cmd) |
3635
|
|
|
|
3636
|
|
|
def clone_user(self, user_id: str) -> Any: |
3637
|
|
|
"""Clone an existing user |
3638
|
|
|
|
3639
|
|
|
Arguments: |
3640
|
|
|
user_id: UUID of existing user to clone from |
3641
|
|
|
|
3642
|
|
|
Returns: |
3643
|
|
|
The response. See :py:meth:`send_command` for details. |
3644
|
|
|
""" |
3645
|
|
|
if not user_id: |
3646
|
|
|
raise RequiredArgument( |
3647
|
|
|
function=self.clone_user.__name__, argument='user_id' |
3648
|
|
|
) |
3649
|
|
|
|
3650
|
|
|
cmd = XmlCommand("create_user") |
3651
|
|
|
cmd.add_element("copy", user_id) |
3652
|
|
|
return self._send_xml_command(cmd) |
3653
|
|
|
|
3654
|
|
|
def delete_alert( |
3655
|
|
|
self, alert_id: str, *, ultimate: Optional[bool] = False |
3656
|
|
|
) -> Any: |
3657
|
|
|
"""Deletes an existing alert |
3658
|
|
|
|
3659
|
|
|
Arguments: |
3660
|
|
|
alert_id: UUID of the alert to be deleted. |
3661
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3662
|
|
|
""" |
3663
|
|
|
if not alert_id: |
3664
|
|
|
raise RequiredArgument( |
3665
|
|
|
function=self.delete_alert.__name__, argument='alert_id' |
3666
|
|
|
) |
3667
|
|
|
|
3668
|
|
|
cmd = XmlCommand("delete_alert") |
3669
|
|
|
cmd.set_attribute("alert_id", alert_id) |
3670
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3671
|
|
|
|
3672
|
|
|
return self._send_xml_command(cmd) |
3673
|
|
|
|
3674
|
|
|
def delete_asset( |
3675
|
|
|
self, *, asset_id: Optional[str] = None, report_id: Optional[str] = None |
3676
|
|
|
) -> Any: |
3677
|
|
|
"""Deletes an existing asset |
3678
|
|
|
|
3679
|
|
|
Arguments: |
3680
|
|
|
asset_id: UUID of the single asset to delete. |
3681
|
|
|
report_id: UUID of report from which to get all |
3682
|
|
|
assets to delete. |
3683
|
|
|
""" |
3684
|
|
|
if not asset_id and not report_id: |
3685
|
|
|
raise RequiredArgument( |
3686
|
|
|
function=self.delete_asset.__name__, |
3687
|
|
|
argument='asset_id or report_id', |
3688
|
|
|
) |
3689
|
|
|
|
3690
|
|
|
cmd = XmlCommand("delete_asset") |
3691
|
|
|
if asset_id: |
3692
|
|
|
cmd.set_attribute("asset_id", asset_id) |
3693
|
|
|
else: |
3694
|
|
|
cmd.set_attribute("report_id", report_id) |
3695
|
|
|
|
3696
|
|
|
return self._send_xml_command(cmd) |
3697
|
|
|
|
3698
|
|
|
def delete_config( |
3699
|
|
|
self, config_id: str, *, ultimate: Optional[bool] = False |
3700
|
|
|
) -> Any: |
3701
|
|
|
"""Deletes an existing config |
3702
|
|
|
|
3703
|
|
|
Arguments: |
3704
|
|
|
config_id: UUID of the config to be deleted. |
3705
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3706
|
|
|
""" |
3707
|
|
|
if not config_id: |
3708
|
|
|
raise RequiredArgument( |
3709
|
|
|
function=self.delete_config.__name__, argument='config_id' |
3710
|
|
|
) |
3711
|
|
|
|
3712
|
|
|
cmd = XmlCommand("delete_config") |
3713
|
|
|
cmd.set_attribute("config_id", config_id) |
3714
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3715
|
|
|
|
3716
|
|
|
return self._send_xml_command(cmd) |
3717
|
|
|
|
3718
|
|
|
def delete_credential( |
3719
|
|
|
self, credential_id: str, *, ultimate: Optional[bool] = False |
3720
|
|
|
) -> Any: |
3721
|
|
|
"""Deletes an existing credential |
3722
|
|
|
|
3723
|
|
|
Arguments: |
3724
|
|
|
credential_id: UUID of the credential to be deleted. |
3725
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3726
|
|
|
""" |
3727
|
|
|
if not credential_id: |
3728
|
|
|
raise RequiredArgument( |
3729
|
|
|
function=self.delete_credential.__name__, |
3730
|
|
|
argument='credential_id', |
3731
|
|
|
) |
3732
|
|
|
|
3733
|
|
|
cmd = XmlCommand("delete_credential") |
3734
|
|
|
cmd.set_attribute("credential_id", credential_id) |
3735
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3736
|
|
|
|
3737
|
|
|
return self._send_xml_command(cmd) |
3738
|
|
|
|
3739
|
|
|
def delete_filter( |
3740
|
|
|
self, filter_id: str, *, ultimate: Optional[bool] = False |
3741
|
|
|
) -> Any: |
3742
|
|
|
"""Deletes an existing filter |
3743
|
|
|
|
3744
|
|
|
Arguments: |
3745
|
|
|
filter_id: UUID of the filter to be deleted. |
3746
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3747
|
|
|
""" |
3748
|
|
|
if not filter_id: |
3749
|
|
|
raise RequiredArgument( |
3750
|
|
|
function=self.delete_filter.__name__, argument='filter_id' |
3751
|
|
|
) |
3752
|
|
|
|
3753
|
|
|
cmd = XmlCommand("delete_filter") |
3754
|
|
|
cmd.set_attribute("filter_id", filter_id) |
3755
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3756
|
|
|
|
3757
|
|
|
return self._send_xml_command(cmd) |
3758
|
|
|
|
3759
|
|
|
def delete_group( |
3760
|
|
|
self, group_id: str, *, ultimate: Optional[bool] = False |
3761
|
|
|
) -> Any: |
3762
|
|
|
"""Deletes an existing group |
3763
|
|
|
|
3764
|
|
|
Arguments: |
3765
|
|
|
group_id: UUID of the group to be deleted. |
3766
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3767
|
|
|
""" |
3768
|
|
|
if not group_id: |
3769
|
|
|
raise RequiredArgument( |
3770
|
|
|
function=self.delete_group.__name__, argument='group_id' |
3771
|
|
|
) |
3772
|
|
|
|
3773
|
|
|
cmd = XmlCommand("delete_group") |
3774
|
|
|
cmd.set_attribute("group_id", group_id) |
3775
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3776
|
|
|
|
3777
|
|
|
return self._send_xml_command(cmd) |
3778
|
|
|
|
3779
|
|
|
def delete_note( |
3780
|
|
|
self, note_id: str, *, ultimate: Optional[bool] = False |
3781
|
|
|
) -> Any: |
3782
|
|
|
"""Deletes an existing note |
3783
|
|
|
|
3784
|
|
|
Arguments: |
3785
|
|
|
note_id: UUID of the note to be deleted. |
3786
|
|
|
ultimate: Whether to remove entirely,or to the trashcan. |
3787
|
|
|
""" |
3788
|
|
|
if not note_id: |
3789
|
|
|
raise RequiredArgument( |
3790
|
|
|
function=self.delete_note.__name__, argument='note_id' |
3791
|
|
|
) |
3792
|
|
|
|
3793
|
|
|
cmd = XmlCommand("delete_note") |
3794
|
|
|
cmd.set_attribute("note_id", note_id) |
3795
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3796
|
|
|
|
3797
|
|
|
return self._send_xml_command(cmd) |
3798
|
|
|
|
3799
|
|
|
def delete_override( |
3800
|
|
|
self, override_id: str, *, ultimate: Optional[bool] = False |
3801
|
|
|
) -> Any: |
3802
|
|
|
"""Deletes an existing override |
3803
|
|
|
|
3804
|
|
|
Arguments: |
3805
|
|
|
override_id: UUID of the override to be deleted. |
3806
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3807
|
|
|
""" |
3808
|
|
|
if not override_id: |
3809
|
|
|
raise RequiredArgument( |
3810
|
|
|
function=self.delete_override.__name__, argument='override_id' |
3811
|
|
|
) |
3812
|
|
|
|
3813
|
|
|
cmd = XmlCommand("delete_override") |
3814
|
|
|
cmd.set_attribute("override_id", override_id) |
3815
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3816
|
|
|
|
3817
|
|
|
return self._send_xml_command(cmd) |
3818
|
|
|
|
3819
|
|
|
def delete_permission( |
3820
|
|
|
self, permission_id: str, *, ultimate: Optional[bool] = False |
3821
|
|
|
) -> Any: |
3822
|
|
|
"""Deletes an existing permission |
3823
|
|
|
|
3824
|
|
|
Arguments: |
3825
|
|
|
permission_id: UUID of the permission to be deleted. |
3826
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3827
|
|
|
""" |
3828
|
|
|
if not permission_id: |
3829
|
|
|
raise RequiredArgument( |
3830
|
|
|
function=self.delete_permission.__name__, |
3831
|
|
|
argument='permission_id', |
3832
|
|
|
) |
3833
|
|
|
|
3834
|
|
|
cmd = XmlCommand("delete_permission") |
3835
|
|
|
cmd.set_attribute("permission_id", permission_id) |
3836
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3837
|
|
|
|
3838
|
|
|
return self._send_xml_command(cmd) |
3839
|
|
|
|
3840
|
|
|
def delete_report_format( |
3841
|
|
|
self, |
3842
|
|
|
report_format_id: Optional[Union[str, ReportFormatType]] = None, |
3843
|
|
|
*, |
3844
|
|
|
ultimate: Optional[bool] = False, |
3845
|
|
|
) -> Any: |
3846
|
|
|
"""Deletes an existing report format |
3847
|
|
|
|
3848
|
|
|
Arguments: |
3849
|
|
|
report_format_id: UUID of the report format to be deleted. |
3850
|
|
|
or ReportFormatType (enum) |
3851
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3852
|
|
|
""" |
3853
|
|
|
if not report_format_id: |
3854
|
|
|
raise RequiredArgument( |
3855
|
|
|
function=self.delete_report_format.__name__, |
3856
|
|
|
argument='report_format_id', |
3857
|
|
|
) |
3858
|
|
|
|
3859
|
|
|
cmd = XmlCommand("delete_report_format") |
3860
|
|
|
|
3861
|
|
|
if isinstance(report_format_id, ReportFormatType): |
3862
|
|
|
report_format_id = report_format_id.value |
3863
|
|
|
|
3864
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
3865
|
|
|
|
3866
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3867
|
|
|
|
3868
|
|
|
return self._send_xml_command(cmd) |
3869
|
|
|
|
3870
|
|
|
def delete_role( |
3871
|
|
|
self, role_id: str, *, ultimate: Optional[bool] = False |
3872
|
|
|
) -> Any: |
3873
|
|
|
"""Deletes an existing role |
3874
|
|
|
|
3875
|
|
|
Arguments: |
3876
|
|
|
role_id: UUID of the role to be deleted. |
3877
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3878
|
|
|
""" |
3879
|
|
|
if not role_id: |
3880
|
|
|
raise RequiredArgument( |
3881
|
|
|
function=self.delete_role.__name__, argument='role_id' |
3882
|
|
|
) |
3883
|
|
|
|
3884
|
|
|
cmd = XmlCommand("delete_role") |
3885
|
|
|
cmd.set_attribute("role_id", role_id) |
3886
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3887
|
|
|
|
3888
|
|
|
return self._send_xml_command(cmd) |
3889
|
|
|
|
3890
|
|
|
def delete_scanner( |
3891
|
|
|
self, scanner_id: str, *, ultimate: Optional[bool] = False |
3892
|
|
|
) -> Any: |
3893
|
|
|
"""Deletes an existing scanner |
3894
|
|
|
|
3895
|
|
|
Arguments: |
3896
|
|
|
scanner_id: UUID of the scanner to be deleted. |
3897
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3898
|
|
|
""" |
3899
|
|
|
if not scanner_id: |
3900
|
|
|
raise RequiredArgument( |
3901
|
|
|
function=self.delete_scanner.__name__, argument='scanner_id' |
3902
|
|
|
) |
3903
|
|
|
|
3904
|
|
|
cmd = XmlCommand("delete_scanner") |
3905
|
|
|
cmd.set_attribute("scanner_id", scanner_id) |
3906
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3907
|
|
|
|
3908
|
|
|
return self._send_xml_command(cmd) |
3909
|
|
|
|
3910
|
|
|
def delete_schedule( |
3911
|
|
|
self, schedule_id: str, *, ultimate: Optional[bool] = False |
3912
|
|
|
) -> Any: |
3913
|
|
|
"""Deletes an existing schedule |
3914
|
|
|
|
3915
|
|
|
Arguments: |
3916
|
|
|
schedule_id: UUID of the schedule to be deleted. |
3917
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3918
|
|
|
""" |
3919
|
|
|
if not schedule_id: |
3920
|
|
|
raise RequiredArgument( |
3921
|
|
|
function=self.delete_schedule.__name__, argument='schedule_id' |
3922
|
|
|
) |
3923
|
|
|
|
3924
|
|
|
cmd = XmlCommand("delete_schedule") |
3925
|
|
|
cmd.set_attribute("schedule_id", schedule_id) |
3926
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3927
|
|
|
|
3928
|
|
|
return self._send_xml_command(cmd) |
3929
|
|
|
|
3930
|
|
|
def delete_tag( |
3931
|
|
|
self, tag_id: str, *, ultimate: Optional[bool] = False |
3932
|
|
|
) -> Any: |
3933
|
|
|
"""Deletes an existing tag |
3934
|
|
|
|
3935
|
|
|
Arguments: |
3936
|
|
|
tag_id: UUID of the tag to be deleted. |
3937
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
3938
|
|
|
""" |
3939
|
|
|
if not tag_id: |
3940
|
|
|
raise RequiredArgument( |
3941
|
|
|
function=self.delete_tag.__name__, argument='tag_id' |
3942
|
|
|
) |
3943
|
|
|
|
3944
|
|
|
cmd = XmlCommand("delete_tag") |
3945
|
|
|
cmd.set_attribute("tag_id", tag_id) |
3946
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
3947
|
|
|
|
3948
|
|
|
return self._send_xml_command(cmd) |
3949
|
|
|
|
3950
|
|
|
def delete_user( |
3951
|
|
|
self, |
3952
|
|
|
user_id: str = None, |
3953
|
|
|
*, |
3954
|
|
|
name: Optional[str] = None, |
3955
|
|
|
inheritor_id: Optional[str] = None, |
3956
|
|
|
inheritor_name: Optional[str] = None, |
3957
|
|
|
) -> Any: |
3958
|
|
|
"""Deletes an existing user |
3959
|
|
|
|
3960
|
|
|
Either user_id or name must be passed. |
3961
|
|
|
|
3962
|
|
|
Arguments: |
3963
|
|
|
user_id: UUID of the task to be deleted. |
3964
|
|
|
name: The name of the user to be deleted. |
3965
|
|
|
inheritor_id: The ID of the inheriting user or "self". Overrides |
3966
|
|
|
inheritor_name. |
3967
|
|
|
inheritor_name: The name of the inheriting user. |
3968
|
|
|
|
3969
|
|
|
""" |
3970
|
|
|
if not user_id and not name: |
3971
|
|
|
raise RequiredArgument( |
3972
|
|
|
function=self.delete_user.__name__, argument='user_id or name' |
3973
|
|
|
) |
3974
|
|
|
|
3975
|
|
|
cmd = XmlCommand("delete_user") |
3976
|
|
|
|
3977
|
|
|
if user_id: |
3978
|
|
|
cmd.set_attribute("user_id", user_id) |
3979
|
|
|
|
3980
|
|
|
if name: |
3981
|
|
|
cmd.set_attribute("name", name) |
3982
|
|
|
|
3983
|
|
|
if inheritor_id: |
3984
|
|
|
cmd.set_attribute("inheritor_id", inheritor_id) |
3985
|
|
|
if inheritor_name: |
3986
|
|
|
cmd.set_attribute("inheritor_name", inheritor_name) |
3987
|
|
|
|
3988
|
|
|
return self._send_xml_command(cmd) |
3989
|
|
|
|
3990
|
|
|
def describe_auth(self) -> Any: |
3991
|
|
|
"""Describe authentication methods |
3992
|
|
|
|
3993
|
|
|
Returns a list of all used authentication methods if such a list is |
3994
|
|
|
available. |
3995
|
|
|
|
3996
|
|
|
Returns: |
3997
|
|
|
The response. See :py:meth:`send_command` for details. |
3998
|
|
|
""" |
3999
|
|
|
return self._send_xml_command(XmlCommand("describe_auth")) |
4000
|
|
|
|
4001
|
|
|
def empty_trashcan(self) -> Any: |
4002
|
|
|
"""Empty the trashcan |
4003
|
|
|
|
4004
|
|
|
Remove all entities from the trashcan. **Attention:** this command can |
4005
|
|
|
not be reverted |
4006
|
|
|
|
4007
|
|
|
Returns: |
4008
|
|
|
The response. See :py:meth:`send_command` for details. |
4009
|
|
|
""" |
4010
|
|
|
return self._send_xml_command(XmlCommand("empty_trashcan")) |
4011
|
|
|
|
4012
|
|
|
def get_alerts( |
4013
|
|
|
self, |
4014
|
|
|
*, |
4015
|
|
|
filter: Optional[str] = None, |
4016
|
|
|
filter_id: Optional[str] = None, |
4017
|
|
|
trash: Optional[bool] = None, |
4018
|
|
|
tasks: Optional[bool] = None, |
4019
|
|
|
) -> Any: |
4020
|
|
|
"""Request a list of alerts |
4021
|
|
|
|
4022
|
|
|
Arguments: |
4023
|
|
|
filter: Filter term to use for the query |
4024
|
|
|
filter_id: UUID of an existing filter to use for the query |
4025
|
|
|
trash: True to request the alerts in the trashcan |
4026
|
|
|
tasks: Whether to include the tasks using the alerts |
4027
|
|
|
Returns: |
4028
|
|
|
The response. See :py:meth:`send_command` for details. |
4029
|
|
|
""" |
4030
|
|
|
cmd = XmlCommand("get_alerts") |
4031
|
|
|
|
4032
|
|
|
add_filter(cmd, filter, filter_id) |
4033
|
|
|
|
4034
|
|
|
if trash is not None: |
4035
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4036
|
|
|
|
4037
|
|
|
if tasks is not None: |
4038
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
4039
|
|
|
|
4040
|
|
|
return self._send_xml_command(cmd) |
4041
|
|
|
|
4042
|
|
|
def get_alert(self, alert_id: str, *, tasks: Optional[bool] = None) -> Any: |
4043
|
|
|
"""Request a single alert |
4044
|
|
|
|
4045
|
|
|
Arguments: |
4046
|
|
|
alert_id: UUID of an existing alert |
4047
|
|
|
|
4048
|
|
|
Returns: |
4049
|
|
|
The response. See :py:meth:`send_command` for details. |
4050
|
|
|
""" |
4051
|
|
|
cmd = XmlCommand("get_alerts") |
4052
|
|
|
|
4053
|
|
|
if not alert_id: |
4054
|
|
|
raise RequiredArgument( |
4055
|
|
|
function=self.get_alert.__name__, argument='alert_id' |
4056
|
|
|
) |
4057
|
|
|
|
4058
|
|
|
cmd.set_attribute("alert_id", alert_id) |
4059
|
|
|
|
4060
|
|
|
if tasks is not None: |
4061
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
4062
|
|
|
|
4063
|
|
|
return self._send_xml_command(cmd) |
4064
|
|
|
|
4065
|
|
|
def get_assets( |
4066
|
|
|
self, |
4067
|
|
|
asset_type: AssetType, |
4068
|
|
|
*, |
4069
|
|
|
filter: Optional[str] = None, |
4070
|
|
|
filter_id: Optional[str] = None, |
4071
|
|
|
) -> Any: |
4072
|
|
|
"""Request a list of assets |
4073
|
|
|
|
4074
|
|
|
Arguments: |
4075
|
|
|
asset_type: Either 'os' or 'host' |
4076
|
|
|
filter: Filter term to use for the query |
4077
|
|
|
filter_id: UUID of an existing filter to use for the query |
4078
|
|
|
|
4079
|
|
|
Returns: |
4080
|
|
|
The response. See :py:meth:`send_command` for details. |
4081
|
|
|
""" |
4082
|
|
|
if not isinstance(asset_type, AssetType): |
4083
|
|
|
raise InvalidArgumentType( |
4084
|
|
|
function=self.get_assets.__name__, |
4085
|
|
|
argument='asset_type', |
4086
|
|
|
arg_type=AssetType.__name__, |
4087
|
|
|
) |
4088
|
|
|
|
4089
|
|
|
cmd = XmlCommand("get_assets") |
4090
|
|
|
|
4091
|
|
|
cmd.set_attribute("type", asset_type.value) |
4092
|
|
|
|
4093
|
|
|
add_filter(cmd, filter, filter_id) |
4094
|
|
|
|
4095
|
|
|
return self._send_xml_command(cmd) |
4096
|
|
|
|
4097
|
|
|
def get_asset(self, asset_id: str, asset_type: AssetType) -> Any: |
4098
|
|
|
"""Request a single asset |
4099
|
|
|
|
4100
|
|
|
Arguments: |
4101
|
|
|
asset_id: UUID of an existing asset |
4102
|
|
|
asset_type: Either 'os' or 'host' |
4103
|
|
|
|
4104
|
|
|
Returns: |
4105
|
|
|
The response. See :py:meth:`send_command` for details. |
4106
|
|
|
""" |
4107
|
|
|
cmd = XmlCommand("get_assets") |
4108
|
|
|
|
4109
|
|
|
if not isinstance(asset_type, AssetType): |
4110
|
|
|
raise InvalidArgumentType( |
4111
|
|
|
function=self.get_asset.__name__, |
4112
|
|
|
argument='asset_type', |
4113
|
|
|
arg_type=AssetType.__name__, |
4114
|
|
|
) |
4115
|
|
|
|
4116
|
|
|
if not asset_id: |
4117
|
|
|
raise RequiredArgument( |
4118
|
|
|
function=self.get_asset.__name__, argument='asset_id' |
4119
|
|
|
) |
4120
|
|
|
|
4121
|
|
|
cmd.set_attribute("asset_id", asset_id) |
4122
|
|
|
cmd.set_attribute("type", asset_type.value) |
4123
|
|
|
|
4124
|
|
|
return self._send_xml_command(cmd) |
4125
|
|
|
|
4126
|
|
View Code Duplication |
def get_credentials( |
|
|
|
|
4127
|
|
|
self, |
4128
|
|
|
*, |
4129
|
|
|
filter: Optional[str] = None, |
4130
|
|
|
filter_id: Optional[str] = None, |
4131
|
|
|
scanners: Optional[bool] = None, |
4132
|
|
|
trash: Optional[bool] = None, |
4133
|
|
|
targets: Optional[bool] = None, |
4134
|
|
|
) -> Any: |
4135
|
|
|
"""Request a list of credentials |
4136
|
|
|
|
4137
|
|
|
Arguments: |
4138
|
|
|
filter: Filter term to use for the query |
4139
|
|
|
filter_id: UUID of an existing filter to use for the query |
4140
|
|
|
scanners: Whether to include a list of scanners using the |
4141
|
|
|
credentials |
4142
|
|
|
trash: Whether to get the trashcan credentials instead |
4143
|
|
|
targets: Whether to include a list of targets using the credentials |
4144
|
|
|
|
4145
|
|
|
Returns: |
4146
|
|
|
The response. See :py:meth:`send_command` for details. |
4147
|
|
|
""" |
4148
|
|
|
cmd = XmlCommand("get_credentials") |
4149
|
|
|
|
4150
|
|
|
add_filter(cmd, filter, filter_id) |
4151
|
|
|
|
4152
|
|
|
if scanners is not None: |
4153
|
|
|
cmd.set_attribute("scanners", to_bool(scanners)) |
4154
|
|
|
|
4155
|
|
|
if trash is not None: |
4156
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4157
|
|
|
|
4158
|
|
|
if targets is not None: |
4159
|
|
|
cmd.set_attribute("targets", to_bool(targets)) |
4160
|
|
|
|
4161
|
|
|
return self._send_xml_command(cmd) |
4162
|
|
|
|
4163
|
|
|
def get_credential( |
4164
|
|
|
self, |
4165
|
|
|
credential_id: str, |
4166
|
|
|
*, |
4167
|
|
|
scanners: Optional[bool] = None, |
4168
|
|
|
targets: Optional[bool] = None, |
4169
|
|
|
credential_format: Optional[CredentialFormat] = None, |
4170
|
|
|
) -> Any: |
4171
|
|
|
"""Request a single credential |
4172
|
|
|
|
4173
|
|
|
Arguments: |
4174
|
|
|
credential_id: UUID of an existing credential |
4175
|
|
|
scanners: Whether to include a list of scanners using the |
4176
|
|
|
credentials |
4177
|
|
|
targets: Whether to include a list of targets using the credentials |
4178
|
|
|
credential_format: One of "key", "rpm", "deb", "exe" or "pem" |
4179
|
|
|
|
4180
|
|
|
Returns: |
4181
|
|
|
The response. See :py:meth:`send_command` for details. |
4182
|
|
|
""" |
4183
|
|
|
if not credential_id: |
4184
|
|
|
raise RequiredArgument( |
4185
|
|
|
function=self.get_credential.__name__, argument='credential_id' |
4186
|
|
|
) |
4187
|
|
|
|
4188
|
|
|
cmd = XmlCommand("get_credentials") |
4189
|
|
|
cmd.set_attribute("credential_id", credential_id) |
4190
|
|
|
|
4191
|
|
|
if credential_format: |
4192
|
|
|
if not isinstance(credential_format, CredentialFormat): |
4193
|
|
|
raise InvalidArgumentType( |
4194
|
|
|
function=self.get_credential.__name__, |
4195
|
|
|
argument='credential_format', |
4196
|
|
|
arg_type=CredentialFormat.__name__, |
4197
|
|
|
) |
4198
|
|
|
|
4199
|
|
|
cmd.set_attribute("format", credential_format.value) |
4200
|
|
|
|
4201
|
|
|
if scanners is not None: |
4202
|
|
|
cmd.set_attribute("scanners", to_bool(scanners)) |
4203
|
|
|
|
4204
|
|
|
if targets is not None: |
4205
|
|
|
cmd.set_attribute("targets", to_bool(targets)) |
4206
|
|
|
|
4207
|
|
|
return self._send_xml_command(cmd) |
4208
|
|
|
|
4209
|
|
|
def get_feeds(self) -> Any: |
4210
|
|
|
"""Request the list of feeds |
4211
|
|
|
|
4212
|
|
|
Returns: |
4213
|
|
|
The response. See :py:meth:`send_command` for details. |
4214
|
|
|
""" |
4215
|
|
|
return self._send_xml_command(XmlCommand("get_feeds")) |
4216
|
|
|
|
4217
|
|
|
def get_filters( |
4218
|
|
|
self, |
4219
|
|
|
*, |
4220
|
|
|
filter: Optional[str] = None, |
4221
|
|
|
filter_id: Optional[str] = None, |
4222
|
|
|
trash: Optional[bool] = None, |
4223
|
|
|
alerts: Optional[bool] = None, |
4224
|
|
|
) -> Any: |
4225
|
|
|
"""Request a list of filters |
4226
|
|
|
|
4227
|
|
|
Arguments: |
4228
|
|
|
filter: Filter term to use for the query |
4229
|
|
|
filter_id: UUID of an existing filter to use for the query |
4230
|
|
|
trash: Whether to get the trashcan filters instead |
4231
|
|
|
alerts: Whether to include list of alerts that use the filter. |
4232
|
|
|
|
4233
|
|
|
Returns: |
4234
|
|
|
The response. See :py:meth:`send_command` for details. |
4235
|
|
|
""" |
4236
|
|
|
cmd = XmlCommand("get_filters") |
4237
|
|
|
|
4238
|
|
|
add_filter(cmd, filter, filter_id) |
4239
|
|
|
|
4240
|
|
|
if trash is not None: |
4241
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4242
|
|
|
|
4243
|
|
|
if alerts is not None: |
4244
|
|
|
cmd.set_attribute("alerts", to_bool(alerts)) |
4245
|
|
|
|
4246
|
|
|
return self._send_xml_command(cmd) |
4247
|
|
|
|
4248
|
|
|
def get_filter( |
4249
|
|
|
self, filter_id: str, *, alerts: Optional[bool] = None |
4250
|
|
|
) -> Any: |
4251
|
|
|
"""Request a single filter |
4252
|
|
|
|
4253
|
|
|
Arguments: |
4254
|
|
|
filter_id: UUID of an existing filter |
4255
|
|
|
alerts: Whether to include list of alerts that use the filter. |
4256
|
|
|
|
4257
|
|
|
Returns: |
4258
|
|
|
The response. See :py:meth:`send_command` for details. |
4259
|
|
|
""" |
4260
|
|
|
cmd = XmlCommand("get_filters") |
4261
|
|
|
|
4262
|
|
|
if not filter_id: |
4263
|
|
|
raise RequiredArgument( |
4264
|
|
|
function=self.get_filter.__name__, argument='filter_id' |
4265
|
|
|
) |
4266
|
|
|
|
4267
|
|
|
cmd.set_attribute("filter_id", filter_id) |
4268
|
|
|
|
4269
|
|
|
if alerts is not None: |
4270
|
|
|
cmd.set_attribute("alerts", to_bool(alerts)) |
4271
|
|
|
|
4272
|
|
|
return self._send_xml_command(cmd) |
4273
|
|
|
|
4274
|
|
View Code Duplication |
def get_groups( |
|
|
|
|
4275
|
|
|
self, |
4276
|
|
|
*, |
4277
|
|
|
filter: Optional[str] = None, |
4278
|
|
|
filter_id: Optional[str] = None, |
4279
|
|
|
trash: Optional[bool] = None, |
4280
|
|
|
) -> Any: |
4281
|
|
|
"""Request a list of groups |
4282
|
|
|
|
4283
|
|
|
Arguments: |
4284
|
|
|
filter: Filter term to use for the query |
4285
|
|
|
filter_id: UUID of an existing filter to use for the query |
4286
|
|
|
trash: Whether to get the trashcan groups instead |
4287
|
|
|
|
4288
|
|
|
Returns: |
4289
|
|
|
The response. See :py:meth:`send_command` for details. |
4290
|
|
|
""" |
4291
|
|
|
cmd = XmlCommand("get_groups") |
4292
|
|
|
|
4293
|
|
|
add_filter(cmd, filter, filter_id) |
4294
|
|
|
|
4295
|
|
|
if trash is not None: |
4296
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4297
|
|
|
|
4298
|
|
|
return self._send_xml_command(cmd) |
4299
|
|
|
|
4300
|
|
|
def get_group(self, group_id: str) -> Any: |
4301
|
|
|
"""Request a single group |
4302
|
|
|
|
4303
|
|
|
Arguments: |
4304
|
|
|
group_id: UUID of an existing group |
4305
|
|
|
|
4306
|
|
|
Returns: |
4307
|
|
|
The response. See :py:meth:`send_command` for details. |
4308
|
|
|
""" |
4309
|
|
|
cmd = XmlCommand("get_groups") |
4310
|
|
|
|
4311
|
|
|
if not group_id: |
4312
|
|
|
raise RequiredArgument( |
4313
|
|
|
function=self.get_group.__name__, argument='group_id' |
4314
|
|
|
) |
4315
|
|
|
|
4316
|
|
|
cmd.set_attribute("group_id", group_id) |
4317
|
|
|
return self._send_xml_command(cmd) |
4318
|
|
|
|
4319
|
|
View Code Duplication |
def get_notes( |
|
|
|
|
4320
|
|
|
self, |
4321
|
|
|
*, |
4322
|
|
|
filter: Optional[str] = None, |
4323
|
|
|
filter_id: Optional[str] = None, |
4324
|
|
|
details: Optional[bool] = None, |
4325
|
|
|
result: Optional[bool] = None, |
4326
|
|
|
) -> Any: |
4327
|
|
|
"""Request a list of notes |
4328
|
|
|
|
4329
|
|
|
Arguments: |
4330
|
|
|
filter: Filter term to use for the query |
4331
|
|
|
filter_id: UUID of an existing filter to use for the query |
4332
|
|
|
details: Add info about connected results and tasks |
4333
|
|
|
result: Return the details of possible connected results. |
4334
|
|
|
|
4335
|
|
|
Returns: |
4336
|
|
|
The response. See :py:meth:`send_command` for details. |
4337
|
|
|
""" |
4338
|
|
|
cmd = XmlCommand("get_notes") |
4339
|
|
|
|
4340
|
|
|
add_filter(cmd, filter, filter_id) |
4341
|
|
|
|
4342
|
|
|
if details is not None: |
4343
|
|
|
cmd.set_attribute("details", to_bool(details)) |
4344
|
|
|
|
4345
|
|
|
if result is not None: |
4346
|
|
|
cmd.set_attribute("result", to_bool(result)) |
4347
|
|
|
|
4348
|
|
|
return self._send_xml_command(cmd) |
4349
|
|
|
|
4350
|
|
|
def get_note(self, note_id: str) -> Any: |
4351
|
|
|
"""Request a single note |
4352
|
|
|
|
4353
|
|
|
Arguments: |
4354
|
|
|
note_id: UUID of an existing note |
4355
|
|
|
|
4356
|
|
|
Returns: |
4357
|
|
|
The response. See :py:meth:`send_command` for details. |
4358
|
|
|
""" |
4359
|
|
|
if not note_id: |
4360
|
|
|
raise RequiredArgument( |
4361
|
|
|
function=self.get_note.__name__, argument='note_id' |
4362
|
|
|
) |
4363
|
|
|
|
4364
|
|
|
cmd = XmlCommand("get_notes") |
4365
|
|
|
cmd.set_attribute("note_id", note_id) |
4366
|
|
|
|
4367
|
|
|
# for single entity always request all details |
4368
|
|
|
cmd.set_attribute("details", "1") |
4369
|
|
|
return self._send_xml_command(cmd) |
4370
|
|
|
|
4371
|
|
|
def get_nvts( |
4372
|
|
|
self, |
4373
|
|
|
*, |
4374
|
|
|
details: Optional[bool] = None, |
4375
|
|
|
preferences: Optional[bool] = None, |
4376
|
|
|
preference_count: Optional[bool] = None, |
4377
|
|
|
timeout: Optional[bool] = None, |
4378
|
|
|
config_id: Optional[str] = None, |
4379
|
|
|
preferences_config_id: Optional[str] = None, |
4380
|
|
|
family: Optional[str] = None, |
4381
|
|
|
sort_order: Optional[str] = None, |
4382
|
|
|
sort_field: Optional[str] = None, |
4383
|
|
|
): |
4384
|
|
|
"""Request a list of nvts |
4385
|
|
|
|
4386
|
|
|
Arguments: |
4387
|
|
|
details: Whether to include full details |
4388
|
|
|
preferences: Whether to include nvt preferences |
4389
|
|
|
preference_count: Whether to include preference count |
4390
|
|
|
timeout: Whether to include the special timeout preference |
4391
|
|
|
config_id: UUID of scan config to which to limit the NVT listing |
4392
|
|
|
preferences_config_id: UUID of scan config to use for preference |
4393
|
|
|
values |
4394
|
|
|
family: Family to which to limit NVT listing |
4395
|
|
|
sort_order: Sort order |
4396
|
|
|
sort_field: Sort field |
4397
|
|
|
|
4398
|
|
|
Returns: |
4399
|
|
|
The response. See :py:meth:`send_command` for details. |
4400
|
|
|
""" |
4401
|
|
|
cmd = XmlCommand("get_nvts") |
4402
|
|
|
|
4403
|
|
|
if details is not None: |
4404
|
|
|
cmd.set_attribute("details", to_bool(details)) |
4405
|
|
|
|
4406
|
|
|
if preferences is not None: |
4407
|
|
|
cmd.set_attribute("preferences", to_bool(preferences)) |
4408
|
|
|
|
4409
|
|
|
if preference_count is not None: |
4410
|
|
|
cmd.set_attribute("preference_count", to_bool(preference_count)) |
4411
|
|
|
|
4412
|
|
|
if timeout is not None: |
4413
|
|
|
cmd.set_attribute("timeout", to_bool(timeout)) |
4414
|
|
|
|
4415
|
|
|
if config_id: |
4416
|
|
|
cmd.set_attribute("config_id", config_id) |
4417
|
|
|
|
4418
|
|
|
if preferences_config_id: |
4419
|
|
|
cmd.set_attribute("preferences_config_id", preferences_config_id) |
4420
|
|
|
|
4421
|
|
|
if family: |
4422
|
|
|
cmd.set_attribute("family", family) |
4423
|
|
|
|
4424
|
|
|
if sort_order: |
4425
|
|
|
cmd.set_attribute("sort_order", sort_order) |
4426
|
|
|
|
4427
|
|
|
if sort_field: |
4428
|
|
|
cmd.set_attribute("sort_field", sort_field) |
4429
|
|
|
|
4430
|
|
|
return self._send_xml_command(cmd) |
4431
|
|
|
|
4432
|
|
|
def get_nvt(self, nvt_oid: str): |
4433
|
|
|
"""Request a single nvt |
4434
|
|
|
|
4435
|
|
|
Arguments: |
4436
|
|
|
nvt_oid: OID of an existing nvt |
4437
|
|
|
|
4438
|
|
|
Returns: |
4439
|
|
|
The response. See :py:meth:`send_command` for details. |
4440
|
|
|
""" |
4441
|
|
|
cmd = XmlCommand("get_nvts") |
4442
|
|
|
|
4443
|
|
|
if not nvt_oid: |
4444
|
|
|
raise RequiredArgument( |
4445
|
|
|
function=self.get_nvt.__name__, argument='nvt_oid' |
4446
|
|
|
) |
4447
|
|
|
|
4448
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
4449
|
|
|
|
4450
|
|
|
# for single entity always request all details |
4451
|
|
|
cmd.set_attribute("details", "1") |
4452
|
|
|
cmd.set_attribute("preferences", "1") |
4453
|
|
|
cmd.set_attribute("preference_count", "1") |
4454
|
|
|
return self._send_xml_command(cmd) |
4455
|
|
|
|
4456
|
|
|
def get_nvt_families(self, *, sort_order: Optional[str] = None): |
4457
|
|
|
"""Request a list of nvt families |
4458
|
|
|
|
4459
|
|
|
Arguments: |
4460
|
|
|
sort_order: Sort order |
4461
|
|
|
|
4462
|
|
|
Returns: |
4463
|
|
|
The response. See :py:meth:`send_command` for details. |
4464
|
|
|
""" |
4465
|
|
|
cmd = XmlCommand("get_nvt_families") |
4466
|
|
|
|
4467
|
|
|
if sort_order: |
4468
|
|
|
cmd.set_attribute("sort_order", sort_order) |
4469
|
|
|
|
4470
|
|
|
return self._send_xml_command(cmd) |
4471
|
|
|
|
4472
|
|
View Code Duplication |
def get_overrides( |
|
|
|
|
4473
|
|
|
self, |
4474
|
|
|
*, |
4475
|
|
|
filter: Optional[str] = None, |
4476
|
|
|
filter_id: Optional[str] = None, |
4477
|
|
|
details: Optional[bool] = None, |
4478
|
|
|
result: Optional[bool] = None, |
4479
|
|
|
) -> Any: |
4480
|
|
|
"""Request a list of overrides |
4481
|
|
|
|
4482
|
|
|
Arguments: |
4483
|
|
|
filter: Filter term to use for the query |
4484
|
|
|
filter_id: UUID of an existing filter to use for the query |
4485
|
|
|
details: Whether to include full details |
4486
|
|
|
result: Whether to include results using the override |
4487
|
|
|
|
4488
|
|
|
Returns: |
4489
|
|
|
The response. See :py:meth:`send_command` for details. |
4490
|
|
|
""" |
4491
|
|
|
cmd = XmlCommand("get_overrides") |
4492
|
|
|
|
4493
|
|
|
add_filter(cmd, filter, filter_id) |
4494
|
|
|
|
4495
|
|
|
if details is not None: |
4496
|
|
|
cmd.set_attribute("details", to_bool(details)) |
4497
|
|
|
|
4498
|
|
|
if result is not None: |
4499
|
|
|
cmd.set_attribute("result", to_bool(result)) |
4500
|
|
|
|
4501
|
|
|
return self._send_xml_command(cmd) |
4502
|
|
|
|
4503
|
|
|
def get_override(self, override_id: str) -> Any: |
4504
|
|
|
"""Request a single override |
4505
|
|
|
|
4506
|
|
|
Arguments: |
4507
|
|
|
override_id: UUID of an existing override |
4508
|
|
|
|
4509
|
|
|
Returns: |
4510
|
|
|
The response. See :py:meth:`send_command` for details. |
4511
|
|
|
""" |
4512
|
|
|
cmd = XmlCommand("get_overrides") |
4513
|
|
|
|
4514
|
|
|
if not override_id: |
4515
|
|
|
raise RequiredArgument( |
4516
|
|
|
function=self.get_override.__name__, argument='override_id' |
4517
|
|
|
) |
4518
|
|
|
|
4519
|
|
|
cmd.set_attribute("override_id", override_id) |
4520
|
|
|
|
4521
|
|
|
# for single entity always request all details |
4522
|
|
|
cmd.set_attribute("details", "1") |
4523
|
|
|
return self._send_xml_command(cmd) |
4524
|
|
|
|
4525
|
|
View Code Duplication |
def get_permissions( |
|
|
|
|
4526
|
|
|
self, |
4527
|
|
|
*, |
4528
|
|
|
filter: Optional[str] = None, |
4529
|
|
|
filter_id: Optional[str] = None, |
4530
|
|
|
trash: Optional[bool] = None, |
4531
|
|
|
) -> Any: |
4532
|
|
|
"""Request a list of permissions |
4533
|
|
|
|
4534
|
|
|
Arguments: |
4535
|
|
|
filter: Filter term to use for the query |
4536
|
|
|
filter_id: UUID of an existing filter to use for the query |
4537
|
|
|
trash: Whether to get permissions in the trashcan instead |
4538
|
|
|
|
4539
|
|
|
Returns: |
4540
|
|
|
The response. See :py:meth:`send_command` for details. |
4541
|
|
|
""" |
4542
|
|
|
cmd = XmlCommand("get_permissions") |
4543
|
|
|
|
4544
|
|
|
add_filter(cmd, filter, filter_id) |
4545
|
|
|
|
4546
|
|
|
if trash is not None: |
4547
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4548
|
|
|
|
4549
|
|
|
return self._send_xml_command(cmd) |
4550
|
|
|
|
4551
|
|
|
def get_permission(self, permission_id: str) -> Any: |
4552
|
|
|
"""Request a single permission |
4553
|
|
|
|
4554
|
|
|
Arguments: |
4555
|
|
|
permission_id: UUID of an existing permission |
4556
|
|
|
|
4557
|
|
|
Returns: |
4558
|
|
|
The response. See :py:meth:`send_command` for details. |
4559
|
|
|
""" |
4560
|
|
|
cmd = XmlCommand("get_permissions") |
4561
|
|
|
|
4562
|
|
|
if not permission_id: |
4563
|
|
|
raise RequiredArgument( |
4564
|
|
|
function=self.get_permission.__name__, argument='permission_id' |
4565
|
|
|
) |
4566
|
|
|
|
4567
|
|
|
cmd.set_attribute("permission_id", permission_id) |
4568
|
|
|
return self._send_xml_command(cmd) |
4569
|
|
|
|
4570
|
|
|
def get_preferences( |
4571
|
|
|
self, *, nvt_oid: Optional[str] = None, config_id: Optional[str] = None |
4572
|
|
|
) -> Any: |
4573
|
|
|
"""Request a list of preferences |
4574
|
|
|
|
4575
|
|
|
When the command includes a config_id attribute, the preference element |
4576
|
|
|
includes the preference name, type and value, and the NVT to which the |
4577
|
|
|
preference applies. Otherwise, the preference element includes just the |
4578
|
|
|
name and value, with the NVT and type built into the name. |
4579
|
|
|
|
4580
|
|
|
Arguments: |
4581
|
|
|
nvt_oid: OID of nvt |
4582
|
|
|
config_id: UUID of scan config of which to show preference values |
4583
|
|
|
|
4584
|
|
|
Returns: |
4585
|
|
|
The response. See :py:meth:`send_command` for details. |
4586
|
|
|
""" |
4587
|
|
|
cmd = XmlCommand("get_preferences") |
4588
|
|
|
|
4589
|
|
|
if nvt_oid: |
4590
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
4591
|
|
|
|
4592
|
|
|
if config_id: |
4593
|
|
|
cmd.set_attribute("config_id", config_id) |
4594
|
|
|
|
4595
|
|
|
return self._send_xml_command(cmd) |
4596
|
|
|
|
4597
|
|
|
def get_preference( |
4598
|
|
|
self, |
4599
|
|
|
name: str, |
4600
|
|
|
*, |
4601
|
|
|
nvt_oid: Optional[str] = None, |
4602
|
|
|
config_id: Optional[str] = None, |
4603
|
|
|
) -> Any: |
4604
|
|
|
"""Request a nvt preference |
4605
|
|
|
|
4606
|
|
|
Arguments: |
4607
|
|
|
name: name of a particular preference |
4608
|
|
|
nvt_oid: OID of nvt |
4609
|
|
|
config_id: UUID of scan config of which to show preference values |
4610
|
|
|
|
4611
|
|
|
Returns: |
4612
|
|
|
The response. See :py:meth:`send_command` for details. |
4613
|
|
|
""" |
4614
|
|
|
cmd = XmlCommand("get_preferences") |
4615
|
|
|
|
4616
|
|
|
if not name: |
4617
|
|
|
raise RequiredArgument( |
4618
|
|
|
function=self.get_preference.__name__, argument='name' |
4619
|
|
|
) |
4620
|
|
|
|
4621
|
|
|
cmd.set_attribute("preference", name) |
4622
|
|
|
|
4623
|
|
|
if nvt_oid: |
4624
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
4625
|
|
|
|
4626
|
|
|
if config_id: |
4627
|
|
|
cmd.set_attribute("config_id", config_id) |
4628
|
|
|
|
4629
|
|
|
return self._send_xml_command(cmd) |
4630
|
|
|
|
4631
|
|
|
def get_report_formats( |
4632
|
|
|
self, |
4633
|
|
|
*, |
4634
|
|
|
filter: Optional[str] = None, |
4635
|
|
|
filter_id: Optional[str] = None, |
4636
|
|
|
trash: Optional[bool] = None, |
4637
|
|
|
alerts: Optional[bool] = None, |
4638
|
|
|
params: Optional[bool] = None, |
4639
|
|
|
details: Optional[bool] = None, |
4640
|
|
|
) -> Any: |
4641
|
|
|
"""Request a list of report formats |
4642
|
|
|
|
4643
|
|
|
Arguments: |
4644
|
|
|
filter: Filter term to use for the query |
4645
|
|
|
filter_id: UUID of an existing filter to use for the query |
4646
|
|
|
trash: Whether to get the trashcan report formats instead |
4647
|
|
|
alerts: Whether to include alerts that use the report format |
4648
|
|
|
params: Whether to include report format parameters |
4649
|
|
|
details: Include report format file, signature and parameters |
4650
|
|
|
|
4651
|
|
|
Returns: |
4652
|
|
|
The response. See :py:meth:`send_command` for details. |
4653
|
|
|
""" |
4654
|
|
|
cmd = XmlCommand("get_report_formats") |
4655
|
|
|
|
4656
|
|
|
add_filter(cmd, filter, filter_id) |
4657
|
|
|
|
4658
|
|
|
if details is not None: |
4659
|
|
|
cmd.set_attribute("details", to_bool(details)) |
4660
|
|
|
|
4661
|
|
|
if alerts is not None: |
4662
|
|
|
cmd.set_attribute("alerts", to_bool(alerts)) |
4663
|
|
|
|
4664
|
|
|
if params is not None: |
4665
|
|
|
cmd.set_attribute("params", to_bool(params)) |
4666
|
|
|
|
4667
|
|
|
if trash is not None: |
4668
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4669
|
|
|
|
4670
|
|
|
return self._send_xml_command(cmd) |
4671
|
|
|
|
4672
|
|
View Code Duplication |
def get_report_format( |
|
|
|
|
4673
|
|
|
self, report_format_id: Union[str, ReportFormatType] |
4674
|
|
|
) -> Any: |
4675
|
|
|
"""Request a single report format |
4676
|
|
|
|
4677
|
|
|
Arguments: |
4678
|
|
|
report_format_id: UUID of an existing report format |
4679
|
|
|
or ReportFormatType (enum) |
4680
|
|
|
|
4681
|
|
|
Returns: |
4682
|
|
|
The response. See :py:meth:`send_command` for details. |
4683
|
|
|
""" |
4684
|
|
|
cmd = XmlCommand("get_report_formats") |
4685
|
|
|
|
4686
|
|
|
if not report_format_id: |
4687
|
|
|
raise RequiredArgument( |
4688
|
|
|
function=self.get_report_format.__name__, |
4689
|
|
|
argument='report_format_id', |
4690
|
|
|
) |
4691
|
|
|
|
4692
|
|
|
if isinstance(report_format_id, ReportFormatType): |
4693
|
|
|
report_format_id = report_format_id.value |
4694
|
|
|
|
4695
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
4696
|
|
|
|
4697
|
|
|
# for single entity always request all details |
4698
|
|
|
cmd.set_attribute("details", "1") |
4699
|
|
|
return self._send_xml_command(cmd) |
4700
|
|
|
|
4701
|
|
View Code Duplication |
def get_roles( |
|
|
|
|
4702
|
|
|
self, |
4703
|
|
|
*, |
4704
|
|
|
filter: Optional[str] = None, |
4705
|
|
|
filter_id: Optional[str] = None, |
4706
|
|
|
trash: Optional[bool] = None, |
4707
|
|
|
) -> Any: |
4708
|
|
|
"""Request a list of roles |
4709
|
|
|
|
4710
|
|
|
Arguments: |
4711
|
|
|
filter: Filter term to use for the query |
4712
|
|
|
filter_id: UUID of an existing filter to use for the query |
4713
|
|
|
trash: Whether to get the trashcan roles instead |
4714
|
|
|
|
4715
|
|
|
Returns: |
4716
|
|
|
The response. See :py:meth:`send_command` for details. |
4717
|
|
|
""" |
4718
|
|
|
cmd = XmlCommand("get_roles") |
4719
|
|
|
|
4720
|
|
|
add_filter(cmd, filter, filter_id) |
4721
|
|
|
|
4722
|
|
|
if trash is not None: |
4723
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4724
|
|
|
|
4725
|
|
|
return self._send_xml_command(cmd) |
4726
|
|
|
|
4727
|
|
|
def get_role(self, role_id: str) -> Any: |
4728
|
|
|
"""Request a single role |
4729
|
|
|
|
4730
|
|
|
Arguments: |
4731
|
|
|
role_id: UUID of an existing role |
4732
|
|
|
|
4733
|
|
|
Returns: |
4734
|
|
|
The response. See :py:meth:`send_command` for details. |
4735
|
|
|
""" |
4736
|
|
|
if not role_id: |
4737
|
|
|
raise RequiredArgument( |
4738
|
|
|
function=self.get_role.__name__, argument='role_id' |
4739
|
|
|
) |
4740
|
|
|
|
4741
|
|
|
cmd = XmlCommand("get_roles") |
4742
|
|
|
cmd.set_attribute("role_id", role_id) |
4743
|
|
|
return self._send_xml_command(cmd) |
4744
|
|
|
|
4745
|
|
View Code Duplication |
def get_scanners( |
|
|
|
|
4746
|
|
|
self, |
4747
|
|
|
*, |
4748
|
|
|
filter: Optional[str] = None, |
4749
|
|
|
filter_id: Optional[str] = None, |
4750
|
|
|
trash: Optional[bool] = None, |
4751
|
|
|
details: Optional[bool] = None, |
4752
|
|
|
) -> Any: |
4753
|
|
|
"""Request a list of scanners |
4754
|
|
|
|
4755
|
|
|
Arguments: |
4756
|
|
|
filter: Filter term to use for the query |
4757
|
|
|
filter_id: UUID of an existing filter to use for the query |
4758
|
|
|
trash: Whether to get the trashcan scanners instead |
4759
|
|
|
details: Whether to include extra details like tasks using this |
4760
|
|
|
scanner |
4761
|
|
|
|
4762
|
|
|
Returns: |
4763
|
|
|
The response. See :py:meth:`send_command` for details. |
4764
|
|
|
""" |
4765
|
|
|
cmd = XmlCommand("get_scanners") |
4766
|
|
|
|
4767
|
|
|
add_filter(cmd, filter, filter_id) |
4768
|
|
|
|
4769
|
|
|
if trash is not None: |
4770
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4771
|
|
|
|
4772
|
|
|
if details is not None: |
4773
|
|
|
cmd.set_attribute("details", to_bool(details)) |
4774
|
|
|
|
4775
|
|
|
return self._send_xml_command(cmd) |
4776
|
|
|
|
4777
|
|
|
def get_scanner(self, scanner_id: str) -> Any: |
4778
|
|
|
"""Request a single scanner |
4779
|
|
|
|
4780
|
|
|
Arguments: |
4781
|
|
|
scanner_id: UUID of an existing scanner |
4782
|
|
|
|
4783
|
|
|
Returns: |
4784
|
|
|
The response. See :py:meth:`send_command` for details. |
4785
|
|
|
""" |
4786
|
|
|
cmd = XmlCommand("get_scanners") |
4787
|
|
|
|
4788
|
|
|
if not scanner_id: |
4789
|
|
|
raise RequiredArgument( |
4790
|
|
|
function=self.get_scanner.__name__, argument='scanner_id' |
4791
|
|
|
) |
4792
|
|
|
|
4793
|
|
|
cmd.set_attribute("scanner_id", scanner_id) |
4794
|
|
|
|
4795
|
|
|
# for single entity always request all details |
4796
|
|
|
cmd.set_attribute("details", "1") |
4797
|
|
|
return self._send_xml_command(cmd) |
4798
|
|
|
|
4799
|
|
|
def get_schedules( |
4800
|
|
|
self, |
4801
|
|
|
*, |
4802
|
|
|
filter: Optional[str] = None, |
4803
|
|
|
filter_id: Optional[str] = None, |
4804
|
|
|
trash: Optional[bool] = None, |
4805
|
|
|
tasks: Optional[bool] = None, |
4806
|
|
|
) -> Any: |
4807
|
|
|
"""Request a list of schedules |
4808
|
|
|
|
4809
|
|
|
Arguments: |
4810
|
|
|
filter: Filter term to use for the query |
4811
|
|
|
filter_id: UUID of an existing filter to use for the query |
4812
|
|
|
trash: Whether to get the trashcan schedules instead |
4813
|
|
|
tasks: Whether to include tasks using the schedules |
4814
|
|
|
|
4815
|
|
|
Returns: |
4816
|
|
|
The response. See :py:meth:`send_command` for details. |
4817
|
|
|
""" |
4818
|
|
|
cmd = XmlCommand("get_schedules") |
4819
|
|
|
|
4820
|
|
|
add_filter(cmd, filter, filter_id) |
4821
|
|
|
|
4822
|
|
|
if trash is not None: |
4823
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4824
|
|
|
|
4825
|
|
|
if tasks is not None: |
4826
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
4827
|
|
|
|
4828
|
|
|
return self._send_xml_command(cmd) |
4829
|
|
|
|
4830
|
|
|
def get_schedule( |
4831
|
|
|
self, schedule_id: str, *, tasks: Optional[bool] = None |
4832
|
|
|
) -> Any: |
4833
|
|
|
"""Request a single schedule |
4834
|
|
|
|
4835
|
|
|
Arguments: |
4836
|
|
|
schedule_id: UUID of an existing schedule |
4837
|
|
|
tasks: Whether to include tasks using the schedules |
4838
|
|
|
|
4839
|
|
|
Returns: |
4840
|
|
|
The response. See :py:meth:`send_command` for details. |
4841
|
|
|
""" |
4842
|
|
|
cmd = XmlCommand("get_schedules") |
4843
|
|
|
|
4844
|
|
|
if not schedule_id: |
4845
|
|
|
raise RequiredArgument( |
4846
|
|
|
function=self.get_schedule.__name__, argument='schedule_id' |
4847
|
|
|
) |
4848
|
|
|
|
4849
|
|
|
cmd.set_attribute("schedule_id", schedule_id) |
4850
|
|
|
|
4851
|
|
|
if tasks is not None: |
4852
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
4853
|
|
|
|
4854
|
|
|
return self._send_xml_command(cmd) |
4855
|
|
|
|
4856
|
|
|
def get_settings(self, *, filter: Optional[str] = None) -> Any: |
4857
|
|
|
"""Request a list of user settings |
4858
|
|
|
|
4859
|
|
|
Arguments: |
4860
|
|
|
filter: Filter term to use for the query |
4861
|
|
|
|
4862
|
|
|
Returns: |
4863
|
|
|
The response. See :py:meth:`send_command` for details. |
4864
|
|
|
""" |
4865
|
|
|
cmd = XmlCommand("get_settings") |
4866
|
|
|
|
4867
|
|
|
if filter: |
4868
|
|
|
cmd.set_attribute("filter", filter) |
4869
|
|
|
|
4870
|
|
|
return self._send_xml_command(cmd) |
4871
|
|
|
|
4872
|
|
|
def get_setting(self, setting_id: str) -> Any: |
4873
|
|
|
"""Request a single setting |
4874
|
|
|
|
4875
|
|
|
Arguments: |
4876
|
|
|
setting_id: UUID of an existing setting |
4877
|
|
|
|
4878
|
|
|
Returns: |
4879
|
|
|
The response. See :py:meth:`send_command` for details. |
4880
|
|
|
""" |
4881
|
|
|
cmd = XmlCommand("get_settings") |
4882
|
|
|
|
4883
|
|
|
if not setting_id: |
4884
|
|
|
raise RequiredArgument( |
4885
|
|
|
function=self.get_setting.__name__, argument='setting_id' |
4886
|
|
|
) |
4887
|
|
|
|
4888
|
|
|
cmd.set_attribute("setting_id", setting_id) |
4889
|
|
|
return self._send_xml_command(cmd) |
4890
|
|
|
|
4891
|
|
|
def get_system_reports( |
4892
|
|
|
self, |
4893
|
|
|
*, |
4894
|
|
|
name: Optional[str] = None, |
4895
|
|
|
duration: Optional[int] = None, |
4896
|
|
|
start_time: Optional[str] = None, |
4897
|
|
|
end_time: Optional[str] = None, |
4898
|
|
|
brief: Optional[bool] = None, |
4899
|
|
|
slave_id: Optional[str] = None, |
4900
|
|
|
) -> Any: |
4901
|
|
|
"""Request a list of system reports |
4902
|
|
|
|
4903
|
|
|
Arguments: |
4904
|
|
|
name: A string describing the required system report |
4905
|
|
|
duration: The number of seconds into the past that the system report |
4906
|
|
|
should include |
4907
|
|
|
start_time: The start of the time interval the system report should |
4908
|
|
|
include in ISO time format |
4909
|
|
|
end_time: The end of the time interval the system report should |
4910
|
|
|
include in ISO time format |
4911
|
|
|
brief: Whether to include the actual system reports |
4912
|
|
|
slave_id: UUID of GMP scanner from which to get the system reports |
4913
|
|
|
|
4914
|
|
|
Returns: |
4915
|
|
|
The response. See :py:meth:`send_command` for details. |
4916
|
|
|
""" |
4917
|
|
|
cmd = XmlCommand("get_system_reports") |
4918
|
|
|
|
4919
|
|
|
if name: |
4920
|
|
|
cmd.set_attribute("name", name) |
4921
|
|
|
|
4922
|
|
|
if duration is not None: |
4923
|
|
|
if not isinstance(duration, numbers.Integral): |
4924
|
|
|
raise InvalidArgument("duration needs to be an integer number") |
4925
|
|
|
|
4926
|
|
|
cmd.set_attribute("duration", str(duration)) |
4927
|
|
|
|
4928
|
|
|
if start_time: |
4929
|
|
|
cmd.set_attribute("start_time", str(start_time)) |
4930
|
|
|
|
4931
|
|
|
if end_time: |
4932
|
|
|
cmd.set_attribute("end_time", str(end_time)) |
4933
|
|
|
|
4934
|
|
|
if brief is not None: |
4935
|
|
|
cmd.set_attribute("brief", to_bool(brief)) |
4936
|
|
|
|
4937
|
|
|
if slave_id: |
4938
|
|
|
cmd.set_attribute("slave_id", slave_id) |
4939
|
|
|
|
4940
|
|
|
return self._send_xml_command(cmd) |
4941
|
|
|
|
4942
|
|
|
def get_tags( |
4943
|
|
|
self, |
4944
|
|
|
*, |
4945
|
|
|
filter: Optional[str] = None, |
4946
|
|
|
filter_id: Optional[str] = None, |
4947
|
|
|
trash: Optional[bool] = None, |
4948
|
|
|
names_only: Optional[bool] = None, |
4949
|
|
|
) -> Any: |
4950
|
|
|
"""Request a list of tags |
4951
|
|
|
|
4952
|
|
|
Arguments: |
4953
|
|
|
filter: Filter term to use for the query |
4954
|
|
|
filter_id: UUID of an existing filter to use for the query |
4955
|
|
|
trash: Whether to get tags from the trashcan instead |
4956
|
|
|
names_only: Whether to get only distinct tag names |
4957
|
|
|
|
4958
|
|
|
Returns: |
4959
|
|
|
The response. See :py:meth:`send_command` for details. |
4960
|
|
|
""" |
4961
|
|
|
cmd = XmlCommand("get_tags") |
4962
|
|
|
|
4963
|
|
|
add_filter(cmd, filter, filter_id) |
4964
|
|
|
|
4965
|
|
|
if trash is not None: |
4966
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
4967
|
|
|
|
4968
|
|
|
if names_only is not None: |
4969
|
|
|
cmd.set_attribute("names_only", to_bool(names_only)) |
4970
|
|
|
|
4971
|
|
|
return self._send_xml_command(cmd) |
4972
|
|
|
|
4973
|
|
|
def get_tag(self, tag_id: str) -> Any: |
4974
|
|
|
"""Request a single tag |
4975
|
|
|
|
4976
|
|
|
Arguments: |
4977
|
|
|
tag_id: UUID of an existing tag |
4978
|
|
|
|
4979
|
|
|
Returns: |
4980
|
|
|
The response. See :py:meth:`send_command` for details. |
4981
|
|
|
""" |
4982
|
|
|
cmd = XmlCommand("get_tags") |
4983
|
|
|
|
4984
|
|
|
if not tag_id: |
4985
|
|
|
raise RequiredArgument( |
4986
|
|
|
function=self.get_tag.__name__, argument='tag_id' |
4987
|
|
|
) |
4988
|
|
|
|
4989
|
|
|
cmd.set_attribute("tag_id", tag_id) |
4990
|
|
|
return self._send_xml_command(cmd) |
4991
|
|
|
|
4992
|
|
|
def get_users( |
4993
|
|
|
self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
4994
|
|
|
) -> Any: |
4995
|
|
|
"""Request a list of users |
4996
|
|
|
|
4997
|
|
|
Arguments: |
4998
|
|
|
filter: Filter term to use for the query |
4999
|
|
|
filter_id: UUID of an existing filter to use for the query |
5000
|
|
|
|
5001
|
|
|
Returns: |
5002
|
|
|
The response. See :py:meth:`send_command` for details. |
5003
|
|
|
""" |
5004
|
|
|
cmd = XmlCommand("get_users") |
5005
|
|
|
|
5006
|
|
|
add_filter(cmd, filter, filter_id) |
5007
|
|
|
|
5008
|
|
|
return self._send_xml_command(cmd) |
5009
|
|
|
|
5010
|
|
|
def get_user(self, user_id: str) -> Any: |
5011
|
|
|
"""Request a single user |
5012
|
|
|
|
5013
|
|
|
Arguments: |
5014
|
|
|
user_id: UUID of an existing user |
5015
|
|
|
|
5016
|
|
|
Returns: |
5017
|
|
|
The response. See :py:meth:`send_command` for details. |
5018
|
|
|
""" |
5019
|
|
|
cmd = XmlCommand("get_users") |
5020
|
|
|
|
5021
|
|
|
if not user_id: |
5022
|
|
|
raise RequiredArgument( |
5023
|
|
|
function=self.get_user.__name__, argument='user_id' |
5024
|
|
|
) |
5025
|
|
|
|
5026
|
|
|
cmd.set_attribute("user_id", user_id) |
5027
|
|
|
return self._send_xml_command(cmd) |
5028
|
|
|
|
5029
|
|
|
def get_version(self) -> Any: |
5030
|
|
|
"""Get the Greenbone Manager Protocol version used by the remote gvmd |
5031
|
|
|
|
5032
|
|
|
Returns: |
5033
|
|
|
The response. See :py:meth:`send_command` for details. |
5034
|
|
|
""" |
5035
|
|
|
return self._send_xml_command(XmlCommand("get_version")) |
5036
|
|
|
|
5037
|
|
|
def help( |
5038
|
|
|
self, *, format: Optional[str] = None, help_type: Optional[str] = "" |
5039
|
|
|
) -> Any: |
5040
|
|
|
"""Get the help text |
5041
|
|
|
|
5042
|
|
|
Arguments: |
5043
|
|
|
format: One of "html", "rnc", "text" or "xml |
5044
|
|
|
help_type: One of "brief" or "". Default "" |
5045
|
|
|
|
5046
|
|
|
Returns: |
5047
|
|
|
The response. See :py:meth:`send_command` for details. |
5048
|
|
|
""" |
5049
|
|
|
cmd = XmlCommand("help") |
5050
|
|
|
|
5051
|
|
|
if help_type not in ("", "brief"): |
5052
|
|
|
raise InvalidArgument( |
5053
|
|
|
'help_type argument must be an empty string or "brief"' |
5054
|
|
|
) |
5055
|
|
|
|
5056
|
|
|
cmd.set_attribute("type", help_type) |
5057
|
|
|
|
5058
|
|
|
if format: |
5059
|
|
|
if not format.lower() in ("html", "rnc", "text", "xml"): |
5060
|
|
|
raise InvalidArgument( |
5061
|
|
|
"help format Argument must be one of html, rnc, text or " |
5062
|
|
|
"xml" |
5063
|
|
|
) |
5064
|
|
|
|
5065
|
|
|
cmd.set_attribute("format", format) |
5066
|
|
|
|
5067
|
|
|
return self._send_xml_command(cmd) |
5068
|
|
|
|
5069
|
|
|
def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
5070
|
|
|
"""Modifies an existing asset. |
5071
|
|
|
|
5072
|
|
|
Arguments: |
5073
|
|
|
asset_id: UUID of the asset to be modified. |
5074
|
|
|
comment: Comment for the asset. |
5075
|
|
|
|
5076
|
|
|
Returns: |
5077
|
|
|
The response. See :py:meth:`send_command` for details. |
5078
|
|
|
""" |
5079
|
|
|
if not asset_id: |
5080
|
|
|
raise RequiredArgument( |
5081
|
|
|
function=self.modify_asset.__name__, argument='asset_id' |
5082
|
|
|
) |
5083
|
|
|
|
5084
|
|
|
cmd = XmlCommand("modify_asset") |
5085
|
|
|
cmd.set_attribute("asset_id", asset_id) |
5086
|
|
|
cmd.add_element("comment", comment) |
5087
|
|
|
|
5088
|
|
|
return self._send_xml_command(cmd) |
5089
|
|
|
|
5090
|
|
|
def modify_auth(self, group_name: str, auth_conf_settings: dict) -> Any: |
5091
|
|
|
"""Modifies an existing auth. |
5092
|
|
|
|
5093
|
|
|
Arguments: |
5094
|
|
|
group_name: Name of the group to be modified. |
5095
|
|
|
auth_conf_settings: The new auth config. |
5096
|
|
|
|
5097
|
|
|
Returns: |
5098
|
|
|
The response. See :py:meth:`send_command` for details. |
5099
|
|
|
""" |
5100
|
|
|
if not group_name: |
5101
|
|
|
raise RequiredArgument( |
5102
|
|
|
function=self.modify_auth.__name__, argument='group_name' |
5103
|
|
|
) |
5104
|
|
|
if not auth_conf_settings: |
5105
|
|
|
raise RequiredArgument( |
5106
|
|
|
function=self.modify_auth.__name__, |
5107
|
|
|
argument='auth_conf_settings', |
5108
|
|
|
) |
5109
|
|
|
cmd = XmlCommand("modify_auth") |
5110
|
|
|
_xmlgroup = cmd.add_element("group", attrs={"name": str(group_name)}) |
5111
|
|
|
|
5112
|
|
|
for key, value in auth_conf_settings.items(): |
5113
|
|
|
_xmlauthconf = _xmlgroup.add_element("auth_conf_setting") |
5114
|
|
|
_xmlauthconf.add_element("key", key) |
5115
|
|
|
_xmlauthconf.add_element("value", value) |
5116
|
|
|
|
5117
|
|
|
return self._send_xml_command(cmd) |
5118
|
|
|
|
5119
|
|
|
def modify_config_set_nvt_preference( |
5120
|
|
|
self, |
5121
|
|
|
config_id: str, |
5122
|
|
|
name: str, |
5123
|
|
|
nvt_oid: str, |
5124
|
|
|
*, |
5125
|
|
|
value: Optional[str] = None, |
5126
|
|
|
) -> Any: |
5127
|
|
|
"""Modifies the nvt preferences of an existing scan config. |
5128
|
|
|
|
5129
|
|
|
Arguments: |
5130
|
|
|
config_id: UUID of scan config to modify. |
5131
|
|
|
name: Name for nvt preference to change. |
5132
|
|
|
nvt_oid: OID of the NVT associated with preference to modify |
5133
|
|
|
value: New value for the preference. None to delete the preference |
5134
|
|
|
and to use the default instead. |
5135
|
|
|
""" |
5136
|
|
|
if not config_id: |
5137
|
|
|
raise RequiredArgument( |
5138
|
|
|
function=self.modify_config_set_nvt_preference.__name__, |
5139
|
|
|
argument='config_id', |
5140
|
|
|
) |
5141
|
|
|
|
5142
|
|
|
if not nvt_oid: |
5143
|
|
|
raise RequiredArgument( |
5144
|
|
|
function=self.modify_config_set_nvt_preference.__name__, |
5145
|
|
|
argument='nvt_oid', |
5146
|
|
|
) |
5147
|
|
|
|
5148
|
|
|
if not name: |
5149
|
|
|
raise RequiredArgument( |
5150
|
|
|
function=self.modify_config_set_nvt_preference.__name__, |
5151
|
|
|
argument='name', |
5152
|
|
|
) |
5153
|
|
|
|
5154
|
|
|
cmd = XmlCommand("modify_config") |
5155
|
|
|
cmd.set_attribute("config_id", str(config_id)) |
5156
|
|
|
|
5157
|
|
|
_xmlpref = cmd.add_element("preference") |
5158
|
|
|
|
5159
|
|
|
_xmlpref.add_element("nvt", attrs={"oid": nvt_oid}) |
5160
|
|
|
_xmlpref.add_element("name", name) |
5161
|
|
|
|
5162
|
|
|
if value: |
5163
|
|
|
_xmlpref.add_element("value", to_base64(value)) |
5164
|
|
|
|
5165
|
|
|
return self._send_xml_command(cmd) |
5166
|
|
|
|
5167
|
|
|
def modify_config_set_name(self, config_id: str, name: str) -> Any: |
5168
|
|
|
"""Modifies the name of an existing scan config |
5169
|
|
|
|
5170
|
|
|
Arguments: |
5171
|
|
|
config_id: UUID of scan config to modify. |
5172
|
|
|
name: New name for the config. |
5173
|
|
|
""" |
5174
|
|
|
if not config_id: |
5175
|
|
|
raise RequiredArgument( |
5176
|
|
|
function=self.modify_config_set_name.__name__, |
5177
|
|
|
argument='config_id', |
5178
|
|
|
) |
5179
|
|
|
|
5180
|
|
|
if not name: |
5181
|
|
|
raise RequiredArgument( |
5182
|
|
|
function=self.modify_config_set_name.__name__, argument='name' |
5183
|
|
|
) |
5184
|
|
|
|
5185
|
|
|
cmd = XmlCommand("modify_config") |
5186
|
|
|
cmd.set_attribute("config_id", str(config_id)) |
5187
|
|
|
|
5188
|
|
|
cmd.add_element("name", name) |
5189
|
|
|
|
5190
|
|
|
return self._send_xml_command(cmd) |
5191
|
|
|
|
5192
|
|
|
def modify_config_set_comment( |
5193
|
|
|
self, config_id: str, comment: Optional[str] = "" |
5194
|
|
|
) -> Any: |
5195
|
|
|
"""Modifies the comment of an existing scan config |
5196
|
|
|
|
5197
|
|
|
Arguments: |
5198
|
|
|
config_id: UUID of scan config to modify. |
5199
|
|
|
comment: Comment to set on a config. Default: '' |
5200
|
|
|
""" |
5201
|
|
|
if not config_id: |
5202
|
|
|
raise RequiredArgument( |
5203
|
|
|
function=self.modify_config_set_comment.__name__, |
5204
|
|
|
argument='config_id argument', |
5205
|
|
|
) |
5206
|
|
|
|
5207
|
|
|
cmd = XmlCommand("modify_config") |
5208
|
|
|
cmd.set_attribute("config_id", str(config_id)) |
5209
|
|
|
|
5210
|
|
|
cmd.add_element("comment", comment) |
5211
|
|
|
|
5212
|
|
|
return self._send_xml_command(cmd) |
5213
|
|
|
|
5214
|
|
|
def modify_config_set_scanner_preference( |
5215
|
|
|
self, config_id: str, name: str, *, value: Optional[str] = None |
5216
|
|
|
) -> Any: |
5217
|
|
|
"""Modifies the scanner preferences of an existing scan config |
5218
|
|
|
|
5219
|
|
|
Arguments: |
5220
|
|
|
config_id: UUID of scan config to modify. |
5221
|
|
|
name: Name of the scanner preference to change |
5222
|
|
|
value: New value for the preference. None to delete the preference |
5223
|
|
|
and to use the default instead. |
5224
|
|
|
|
5225
|
|
|
""" |
5226
|
|
|
if not config_id: |
5227
|
|
|
raise RequiredArgument( |
5228
|
|
|
function=self.modify_config_set_scanner_preference.__name__, |
5229
|
|
|
argument='config_id', |
5230
|
|
|
) |
5231
|
|
|
|
5232
|
|
|
if not name: |
5233
|
|
|
raise RequiredArgument( |
5234
|
|
|
function=self.modify_config_set_scanner_preference.__name__, |
5235
|
|
|
argument='name argument', |
5236
|
|
|
) |
5237
|
|
|
|
5238
|
|
|
cmd = XmlCommand("modify_config") |
5239
|
|
|
cmd.set_attribute("config_id", str(config_id)) |
5240
|
|
|
|
5241
|
|
|
_xmlpref = cmd.add_element("preference") |
5242
|
|
|
|
5243
|
|
|
_xmlpref.add_element("name", name) |
5244
|
|
|
|
5245
|
|
|
if value: |
5246
|
|
|
_xmlpref.add_element("value", to_base64(value)) |
5247
|
|
|
|
5248
|
|
|
return self._send_xml_command(cmd) |
5249
|
|
|
|
5250
|
|
|
def modify_config_set_nvt_selection( |
5251
|
|
|
self, config_id: str, family: str, nvt_oids: List[str] |
5252
|
|
|
) -> Any: |
5253
|
|
|
"""Modifies the selected nvts of an existing scan config |
5254
|
|
|
|
5255
|
|
|
The manager updates the given family in the config to include only the |
5256
|
|
|
given NVTs. |
5257
|
|
|
|
5258
|
|
|
Arguments: |
5259
|
|
|
config_id: UUID of scan config to modify. |
5260
|
|
|
family: Name of the NVT family to include NVTs from |
5261
|
|
|
nvt_oids: List of NVTs to select for the family. |
5262
|
|
|
""" |
5263
|
|
|
if not config_id: |
5264
|
|
|
raise RequiredArgument( |
5265
|
|
|
function=self.modify_config_set_nvt_selection.__name__, |
5266
|
|
|
argument='config_id', |
5267
|
|
|
) |
5268
|
|
|
|
5269
|
|
|
if not family: |
5270
|
|
|
raise RequiredArgument( |
5271
|
|
|
function=self.modify_config_set_nvt_selection.__name__, |
5272
|
|
|
argument='family argument', |
5273
|
|
|
) |
5274
|
|
|
|
5275
|
|
|
if not is_list_like(nvt_oids): |
5276
|
|
|
raise InvalidArgumentType( |
5277
|
|
|
function=self.modify_config_set_nvt_selection.__name__, |
5278
|
|
|
argument='nvt_oids', |
5279
|
|
|
arg_type='list', |
5280
|
|
|
) |
5281
|
|
|
|
5282
|
|
|
cmd = XmlCommand("modify_config") |
5283
|
|
|
cmd.set_attribute("config_id", str(config_id)) |
5284
|
|
|
|
5285
|
|
|
_xmlnvtsel = cmd.add_element("nvt_selection") |
5286
|
|
|
_xmlnvtsel.add_element("family", family) |
5287
|
|
|
|
5288
|
|
|
for nvt in nvt_oids: |
5289
|
|
|
_xmlnvtsel.add_element("nvt", attrs={"oid": nvt}) |
5290
|
|
|
|
5291
|
|
|
return self._send_xml_command(cmd) |
5292
|
|
|
|
5293
|
|
|
def modify_config_set_family_selection( |
5294
|
|
|
self, |
5295
|
|
|
config_id: str, |
5296
|
|
|
families: List[Tuple[str, bool, bool]], |
5297
|
|
|
*, |
5298
|
|
|
auto_add_new_families: Optional[bool] = True, |
5299
|
|
|
) -> Any: |
5300
|
|
|
""" |
5301
|
|
|
Selected the NVTs of a scan config at a family level. |
5302
|
|
|
|
5303
|
|
|
Arguments: |
5304
|
|
|
config_id: UUID of scan config to modify. |
5305
|
|
|
families: A list of tuples (str, bool, bool): |
5306
|
|
|
str: the name of the NVT family selected, |
5307
|
|
|
bool: add new NVTs to the family automatically, |
5308
|
|
|
bool: include all NVTs from the family |
5309
|
|
|
auto_add_new_families: Whether new families should be added to the |
5310
|
|
|
scan config automatically. Default: True. |
5311
|
|
|
""" |
5312
|
|
|
if not config_id: |
5313
|
|
|
raise RequiredArgument( |
5314
|
|
|
function=self.modify_config_set_family_selection.__name__, |
5315
|
|
|
argument='config_id', |
5316
|
|
|
) |
5317
|
|
|
|
5318
|
|
|
if not is_list_like(families): |
5319
|
|
|
raise InvalidArgumentType( |
5320
|
|
|
function=self.modify_config_set_family_selection.__name__, |
5321
|
|
|
argument='families', |
5322
|
|
|
arg_type='list', |
5323
|
|
|
) |
5324
|
|
|
|
5325
|
|
|
cmd = XmlCommand("modify_config") |
5326
|
|
|
cmd.set_attribute("config_id", str(config_id)) |
5327
|
|
|
|
5328
|
|
|
_xmlfamsel = cmd.add_element("family_selection") |
5329
|
|
|
_xmlfamsel.add_element("growing", to_bool(auto_add_new_families)) |
5330
|
|
|
|
5331
|
|
|
for family in families: |
5332
|
|
|
_xmlfamily = _xmlfamsel.add_element("family") |
5333
|
|
|
_xmlfamily.add_element("name", family[0]) |
5334
|
|
|
|
5335
|
|
|
if len(family) != 3: |
5336
|
|
|
raise InvalidArgument( |
5337
|
|
|
"Family must be a tuple of 3. (str, bool, bool)" |
5338
|
|
|
) |
5339
|
|
|
|
5340
|
|
|
if not isinstance(family[1], bool) or not isinstance( |
5341
|
|
|
family[2], bool |
5342
|
|
|
): |
5343
|
|
|
raise InvalidArgumentType( |
5344
|
|
|
function=self.modify_config_set_family_selection.__name__, |
5345
|
|
|
argument='families', |
5346
|
|
|
arg_type='[tuple(str, bool, bool)]', |
5347
|
|
|
) |
5348
|
|
|
|
5349
|
|
|
_xmlfamily.add_element("all", to_bool(family[2])) |
5350
|
|
|
_xmlfamily.add_element("growing", to_bool(family[1])) |
5351
|
|
|
|
5352
|
|
|
return self._send_xml_command(cmd) |
5353
|
|
|
|
5354
|
|
|
def modify_config( |
5355
|
|
|
self, config_id: str, selection: Optional[str] = None, **kwargs |
5356
|
|
|
) -> Any: |
5357
|
|
|
"""Modifies an existing scan config. |
5358
|
|
|
|
5359
|
|
|
DEPRECATED. Please use *modify_config_set_* methods instead. |
5360
|
|
|
|
5361
|
|
|
modify_config has four modes to operate depending on the selection. |
5362
|
|
|
|
5363
|
|
|
Arguments: |
5364
|
|
|
config_id: UUID of scan config to modify. |
5365
|
|
|
selection: one of 'scan_pref', 'nvt_pref', 'nvt_selection' or |
5366
|
|
|
'family_selection' |
5367
|
|
|
name: New name for preference. |
5368
|
|
|
value: New value for preference. |
5369
|
|
|
nvt_oids: List of NVTs associated with preference to modify. |
5370
|
|
|
family: Name of family to modify. |
5371
|
|
|
|
5372
|
|
|
Returns: |
5373
|
|
|
The response. See :py:meth:`send_command` for details. |
5374
|
|
|
""" |
5375
|
|
|
if not config_id: |
5376
|
|
|
raise RequiredArgument( |
5377
|
|
|
function=self.modify_config.__name__, |
5378
|
|
|
argument='config_id argument', |
5379
|
|
|
) |
5380
|
|
|
|
5381
|
|
|
if selection is None: |
5382
|
|
|
deprecation( |
5383
|
|
|
"Using modify_config to update the comment of a scan config is" |
5384
|
|
|
"deprecated. Please use modify_config_set_comment instead." |
5385
|
|
|
) |
5386
|
|
|
return self.modify_config_set_comment( |
5387
|
|
|
config_id, kwargs.get("comment") |
5388
|
|
|
) |
5389
|
|
|
|
5390
|
|
|
if selection not in ( |
5391
|
|
|
"nvt_pref", |
5392
|
|
|
"scan_pref", |
5393
|
|
|
"family_selection", |
5394
|
|
|
"nvt_selection", |
5395
|
|
|
): |
5396
|
|
|
raise InvalidArgument( |
5397
|
|
|
"selection must be one of nvt_pref, " |
5398
|
|
|
"scan_pref, family_selection or " |
5399
|
|
|
"nvt_selection" |
5400
|
|
|
) |
5401
|
|
|
|
5402
|
|
|
if selection == "nvt_pref": |
5403
|
|
|
deprecation( |
5404
|
|
|
"Using modify_config to update a nvt preference of a scan " |
5405
|
|
|
"config is deprecated. Please use " |
5406
|
|
|
"modify_config_set_nvt_preference instead." |
5407
|
|
|
) |
5408
|
|
|
return self.modify_config_set_nvt_preference(config_id, **kwargs) |
5409
|
|
|
|
5410
|
|
|
if selection == "scan_pref": |
5411
|
|
|
deprecation( |
5412
|
|
|
"Using modify_config to update a scanner preference of a " |
5413
|
|
|
"scan config is deprecated. Please use " |
5414
|
|
|
"modify_config_set_scanner_preference instead." |
5415
|
|
|
) |
5416
|
|
|
return self.modify_config_set_scanner_preference( |
5417
|
|
|
config_id, **kwargs |
5418
|
|
|
) |
5419
|
|
|
|
5420
|
|
|
if selection == "nvt_selection": |
5421
|
|
|
deprecation( |
5422
|
|
|
"Using modify_config to update a nvt selection of a " |
5423
|
|
|
"scan config is deprecated. Please use " |
5424
|
|
|
"modify_config_set_nvt_selection instead." |
5425
|
|
|
) |
5426
|
|
|
return self.modify_config_set_nvt_selection(config_id, **kwargs) |
5427
|
|
|
|
5428
|
|
|
deprecation( |
5429
|
|
|
"Using modify_config to update a family selection of a " |
5430
|
|
|
"scan config is deprecated. Please use " |
5431
|
|
|
"modify_config_set_family_selection instead." |
5432
|
|
|
) |
5433
|
|
|
return self.modify_config_set_family_selection(config_id, **kwargs) |
5434
|
|
|
|
5435
|
|
View Code Duplication |
def modify_group( |
|
|
|
|
5436
|
|
|
self, |
5437
|
|
|
group_id: str, |
5438
|
|
|
*, |
5439
|
|
|
comment: Optional[str] = None, |
5440
|
|
|
name: Optional[str] = None, |
5441
|
|
|
users: Optional[List[str]] = None, |
5442
|
|
|
) -> Any: |
5443
|
|
|
"""Modifies an existing group. |
5444
|
|
|
|
5445
|
|
|
Arguments: |
5446
|
|
|
group_id: UUID of group to modify. |
5447
|
|
|
comment: Comment on group. |
5448
|
|
|
name: Name of group. |
5449
|
|
|
users: List of user names to be in the group |
5450
|
|
|
|
5451
|
|
|
Returns: |
5452
|
|
|
The response. See :py:meth:`send_command` for details. |
5453
|
|
|
""" |
5454
|
|
|
if not group_id: |
5455
|
|
|
raise RequiredArgument( |
5456
|
|
|
function=self.modify_group.__name__, argument='group_id' |
5457
|
|
|
) |
5458
|
|
|
|
5459
|
|
|
cmd = XmlCommand("modify_group") |
5460
|
|
|
cmd.set_attribute("group_id", group_id) |
5461
|
|
|
|
5462
|
|
|
if comment: |
5463
|
|
|
cmd.add_element("comment", comment) |
5464
|
|
|
|
5465
|
|
|
if name: |
5466
|
|
|
cmd.add_element("name", name) |
5467
|
|
|
|
5468
|
|
|
if users: |
5469
|
|
|
cmd.add_element("users", to_comma_list(users)) |
5470
|
|
|
|
5471
|
|
|
return self._send_xml_command(cmd) |
5472
|
|
|
|
5473
|
|
View Code Duplication |
def modify_note( |
|
|
|
|
5474
|
|
|
self, |
5475
|
|
|
note_id: str, |
5476
|
|
|
text: str, |
5477
|
|
|
*, |
5478
|
|
|
days_active: Optional[int] = None, |
5479
|
|
|
hosts: Optional[List[str]] = None, |
5480
|
|
|
port: Optional[int] = None, |
5481
|
|
|
result_id: Optional[str] = None, |
5482
|
|
|
severity: Optional[Severity] = None, |
5483
|
|
|
task_id: Optional[str] = None, |
5484
|
|
|
threat: Optional[SeverityLevel] = None, |
5485
|
|
|
) -> Any: |
5486
|
|
|
"""Modifies an existing note. |
5487
|
|
|
|
5488
|
|
|
Arguments: |
5489
|
|
|
note_id: UUID of note to modify. |
5490
|
|
|
text: The text of the note. |
5491
|
|
|
days_active: Days note will be active. -1 on always, 0 off. |
5492
|
|
|
hosts: A list of hosts addresses |
5493
|
|
|
port: Port to which note applies. |
5494
|
|
|
result_id: Result to which note applies. |
5495
|
|
|
severity: Severity to which note applies. |
5496
|
|
|
task_id: Task to which note applies. |
5497
|
|
|
threat: Threat level to which note applies. Will be converted to |
5498
|
|
|
severity. |
5499
|
|
|
|
5500
|
|
|
Returns: |
5501
|
|
|
The response. See :py:meth:`send_command` for details. |
5502
|
|
|
""" |
5503
|
|
|
if not note_id: |
5504
|
|
|
raise RequiredArgument( |
5505
|
|
|
function=self.modify_note.__name__, argument='note_id' |
5506
|
|
|
) |
5507
|
|
|
|
5508
|
|
|
if not text: |
5509
|
|
|
raise RequiredArgument( |
5510
|
|
|
function=self.modify_note.__name__, argument='text' |
5511
|
|
|
) |
5512
|
|
|
|
5513
|
|
|
cmd = XmlCommand("modify_note") |
5514
|
|
|
cmd.set_attribute("note_id", note_id) |
5515
|
|
|
cmd.add_element("text", text) |
5516
|
|
|
|
5517
|
|
|
if days_active is not None: |
5518
|
|
|
cmd.add_element("active", str(days_active)) |
5519
|
|
|
|
5520
|
|
|
if hosts: |
5521
|
|
|
cmd.add_element("hosts", to_comma_list(hosts)) |
5522
|
|
|
|
5523
|
|
|
if port: |
5524
|
|
|
cmd.add_element("port", str(port)) |
5525
|
|
|
|
5526
|
|
|
if result_id: |
5527
|
|
|
cmd.add_element("result", attrs={"id": result_id}) |
5528
|
|
|
|
5529
|
|
|
if severity: |
5530
|
|
|
cmd.add_element("severity", str(severity)) |
5531
|
|
|
|
5532
|
|
|
if task_id: |
5533
|
|
|
cmd.add_element("task", attrs={"id": task_id}) |
5534
|
|
|
|
5535
|
|
|
if threat is not None: |
5536
|
|
|
|
5537
|
|
|
if not isinstance(threat, SeverityLevel): |
5538
|
|
|
raise InvalidArgumentType( |
5539
|
|
|
function=self.modify_note.__name__, |
5540
|
|
|
argument='threat', |
5541
|
|
|
arg_type=SeverityLevel.__name__, |
5542
|
|
|
) |
5543
|
|
|
|
5544
|
|
|
cmd.add_element("threat", threat.value) |
5545
|
|
|
|
5546
|
|
|
return self._send_xml_command(cmd) |
5547
|
|
|
|
5548
|
|
View Code Duplication |
def modify_override( |
|
|
|
|
5549
|
|
|
self, |
5550
|
|
|
override_id: str, |
5551
|
|
|
text: str, |
5552
|
|
|
*, |
5553
|
|
|
days_active: Optional[int] = None, |
5554
|
|
|
hosts: Optional[List[str]] = None, |
5555
|
|
|
port: Optional[int] = None, |
5556
|
|
|
result_id: Optional[str] = None, |
5557
|
|
|
severity: Optional[Severity] = None, |
5558
|
|
|
new_severity: Optional[Severity] = None, |
5559
|
|
|
task_id: Optional[str] = None, |
5560
|
|
|
threat: Optional[SeverityLevel] = None, |
5561
|
|
|
new_threat: Optional[SeverityLevel] = None, |
5562
|
|
|
) -> Any: |
5563
|
|
|
"""Modifies an existing override. |
5564
|
|
|
|
5565
|
|
|
Arguments: |
5566
|
|
|
override_id: UUID of override to modify. |
5567
|
|
|
text: The text of the override. |
5568
|
|
|
days_active: Days override will be active. -1 on always, |
5569
|
|
|
0 off. |
5570
|
|
|
hosts: A list of host addresses |
5571
|
|
|
port: Port to which override applies. |
5572
|
|
|
result_id: Result to which override applies. |
5573
|
|
|
severity: Severity to which override applies. |
5574
|
|
|
new_severity: New severity score for result. |
5575
|
|
|
task_id: Task to which override applies. |
5576
|
|
|
threat: Threat level to which override applies. |
5577
|
|
|
Will be converted to severity. |
5578
|
|
|
new_threat: New threat level for results. Will be converted to |
5579
|
|
|
new_severity. |
5580
|
|
|
|
5581
|
|
|
Returns: |
5582
|
|
|
The response. See :py:meth:`send_command` for details. |
5583
|
|
|
""" |
5584
|
|
|
if not override_id: |
5585
|
|
|
raise RequiredArgument( |
5586
|
|
|
function=self.modify_override.__name__, argument='override_id' |
5587
|
|
|
) |
5588
|
|
|
if not text: |
5589
|
|
|
raise RequiredArgument( |
5590
|
|
|
function=self.modify_override.__name__, argument='text' |
5591
|
|
|
) |
5592
|
|
|
|
5593
|
|
|
cmd = XmlCommand("modify_override") |
5594
|
|
|
cmd.set_attribute("override_id", override_id) |
5595
|
|
|
cmd.add_element("text", text) |
5596
|
|
|
|
5597
|
|
|
if days_active is not None: |
5598
|
|
|
cmd.add_element("active", str(days_active)) |
5599
|
|
|
|
5600
|
|
|
if hosts: |
5601
|
|
|
cmd.add_element("hosts", to_comma_list(hosts)) |
5602
|
|
|
|
5603
|
|
|
if port: |
5604
|
|
|
cmd.add_element("port", str(port)) |
5605
|
|
|
|
5606
|
|
|
if result_id: |
5607
|
|
|
cmd.add_element("result", attrs={"id": result_id}) |
5608
|
|
|
|
5609
|
|
|
if severity: |
5610
|
|
|
cmd.add_element("severity", str(severity)) |
5611
|
|
|
|
5612
|
|
|
if new_severity: |
5613
|
|
|
cmd.add_element("new_severity", str(new_severity)) |
5614
|
|
|
|
5615
|
|
|
if task_id: |
5616
|
|
|
cmd.add_element("task", attrs={"id": task_id}) |
5617
|
|
|
|
5618
|
|
|
if threat is not None: |
5619
|
|
|
if not isinstance(threat, SeverityLevel): |
5620
|
|
|
raise InvalidArgumentType( |
5621
|
|
|
function=self.modify_override.__name__, |
5622
|
|
|
argument='threat', |
5623
|
|
|
arg_type=SeverityLevel.__name__, |
5624
|
|
|
) |
5625
|
|
|
cmd.add_element("threat", threat.value) |
5626
|
|
|
|
5627
|
|
|
if new_threat is not None: |
5628
|
|
|
if not isinstance(new_threat, SeverityLevel): |
5629
|
|
|
raise InvalidArgumentType( |
5630
|
|
|
function=self.modify_override.__name__, |
5631
|
|
|
argument='new_threat', |
5632
|
|
|
arg_type=SeverityLevel.__name__, |
5633
|
|
|
) |
5634
|
|
|
|
5635
|
|
|
cmd.add_element("new_threat", new_threat.value) |
5636
|
|
|
|
5637
|
|
|
return self._send_xml_command(cmd) |
5638
|
|
|
|
5639
|
|
|
def modify_report_format( |
5640
|
|
|
self, |
5641
|
|
|
report_format_id: Optional[Union[str, ReportFormatType]] = None, |
5642
|
|
|
*, |
5643
|
|
|
active: Optional[bool] = None, |
5644
|
|
|
name: Optional[str] = None, |
5645
|
|
|
summary: Optional[str] = None, |
5646
|
|
|
param_name: Optional[str] = None, |
5647
|
|
|
param_value: Optional[str] = None, |
5648
|
|
|
) -> Any: |
5649
|
|
|
"""Modifies an existing report format. |
5650
|
|
|
|
5651
|
|
|
Arguments: |
5652
|
|
|
report_format_id: UUID of report format to modify |
5653
|
|
|
or ReportFormatType (enum) |
5654
|
|
|
active: Whether the report format is active. |
5655
|
|
|
name: The name of the report format. |
5656
|
|
|
summary: A summary of the report format. |
5657
|
|
|
param_name: The name of the param. |
5658
|
|
|
param_value: The value of the param. |
5659
|
|
|
|
5660
|
|
|
Returns: |
5661
|
|
|
The response. See :py:meth:`send_command` for details. |
5662
|
|
|
""" |
5663
|
|
|
if not report_format_id: |
5664
|
|
|
raise RequiredArgument( |
5665
|
|
|
function=self.modify_report_format.__name__, |
5666
|
|
|
argument='report_format_id ', |
5667
|
|
|
) |
5668
|
|
|
|
5669
|
|
|
cmd = XmlCommand("modify_report_format") |
5670
|
|
|
|
5671
|
|
|
if isinstance(report_format_id, ReportFormatType): |
5672
|
|
|
report_format_id = report_format_id.value |
5673
|
|
|
|
5674
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
5675
|
|
|
|
5676
|
|
|
if active is not None: |
5677
|
|
|
cmd.add_element("active", to_bool(active)) |
5678
|
|
|
|
5679
|
|
|
if name: |
5680
|
|
|
cmd.add_element("name", name) |
5681
|
|
|
|
5682
|
|
|
if summary: |
5683
|
|
|
cmd.add_element("summary", summary) |
5684
|
|
|
|
5685
|
|
|
if param_name: |
5686
|
|
|
_xmlparam = cmd.add_element("param") |
5687
|
|
|
_xmlparam.add_element("name", param_name) |
5688
|
|
|
|
5689
|
|
|
if param_value is not None: |
5690
|
|
|
_xmlparam.add_element("value", param_value) |
5691
|
|
|
|
5692
|
|
|
return self._send_xml_command(cmd) |
5693
|
|
|
|
5694
|
|
View Code Duplication |
def modify_role( |
|
|
|
|
5695
|
|
|
self, |
5696
|
|
|
role_id: str, |
5697
|
|
|
*, |
5698
|
|
|
comment: Optional[str] = None, |
5699
|
|
|
name: Optional[str] = None, |
5700
|
|
|
users: Optional[List[str]] = None, |
5701
|
|
|
) -> Any: |
5702
|
|
|
"""Modifies an existing role. |
5703
|
|
|
|
5704
|
|
|
Arguments: |
5705
|
|
|
role_id: UUID of role to modify. |
5706
|
|
|
comment: Name of role. |
5707
|
|
|
name: Comment on role. |
5708
|
|
|
users: List of user names. |
5709
|
|
|
|
5710
|
|
|
Returns: |
5711
|
|
|
The response. See :py:meth:`send_command` for details. |
5712
|
|
|
""" |
5713
|
|
|
if not role_id: |
5714
|
|
|
raise RequiredArgument( |
5715
|
|
|
function=self.modify_role.__name__, argument='role_id argument' |
5716
|
|
|
) |
5717
|
|
|
|
5718
|
|
|
cmd = XmlCommand("modify_role") |
5719
|
|
|
cmd.set_attribute("role_id", role_id) |
5720
|
|
|
|
5721
|
|
|
if comment: |
5722
|
|
|
cmd.add_element("comment", comment) |
5723
|
|
|
|
5724
|
|
|
if name: |
5725
|
|
|
cmd.add_element("name", name) |
5726
|
|
|
|
5727
|
|
|
if users: |
5728
|
|
|
cmd.add_element("users", to_comma_list(users)) |
5729
|
|
|
|
5730
|
|
|
return self._send_xml_command(cmd) |
5731
|
|
|
|
5732
|
|
|
def modify_scanner( |
5733
|
|
|
self, |
5734
|
|
|
scanner_id: str, |
5735
|
|
|
*, |
5736
|
|
|
scanner_type: Optional[ScannerType] = None, |
5737
|
|
|
host: Optional[str] = None, |
5738
|
|
|
port: Optional[int] = None, |
5739
|
|
|
comment: Optional[str] = None, |
5740
|
|
|
name: Optional[str] = None, |
5741
|
|
|
ca_pub: Optional[str] = None, |
5742
|
|
|
credential_id: Optional[str] = None, |
5743
|
|
|
) -> Any: |
5744
|
|
|
"""Modifies an existing scanner. |
5745
|
|
|
|
5746
|
|
|
Arguments: |
5747
|
|
|
scanner_id: UUID of scanner to modify. |
5748
|
|
|
scanner_type: New type of the Scanner. |
5749
|
|
|
host: Host of the scanner. |
5750
|
|
|
port: Port of the scanner. |
5751
|
|
|
comment: Comment on scanner. |
5752
|
|
|
name: Name of scanner. |
5753
|
|
|
ca_pub: Certificate of CA to verify scanner's certificate. |
5754
|
|
|
credential_id: UUID of the client certificate credential for the |
5755
|
|
|
Scanner. |
5756
|
|
|
|
5757
|
|
|
Returns: |
5758
|
|
|
The response. See :py:meth:`send_command` for details. |
5759
|
|
|
""" |
5760
|
|
|
if not scanner_id: |
5761
|
|
|
raise RequiredArgument( |
5762
|
|
|
function=self.modify_scanner.__name__, |
5763
|
|
|
argument='scanner_id argument', |
5764
|
|
|
) |
5765
|
|
|
|
5766
|
|
|
cmd = XmlCommand("modify_scanner") |
5767
|
|
|
cmd.set_attribute("scanner_id", scanner_id) |
5768
|
|
|
|
5769
|
|
|
if scanner_type is not None: |
5770
|
|
|
if not isinstance(scanner_type, self.types.ScannerType): |
5771
|
|
|
raise InvalidArgumentType( |
5772
|
|
|
function=self.modify_scanner.__name__, |
5773
|
|
|
argument='scanner_type', |
5774
|
|
|
arg_type=self.types.ScannerType.__name__, |
5775
|
|
|
) |
5776
|
|
|
|
5777
|
|
|
cmd.add_element("type", scanner_type.value) |
5778
|
|
|
|
5779
|
|
|
if host: |
5780
|
|
|
cmd.add_element("host", host) |
5781
|
|
|
|
5782
|
|
|
if port: |
5783
|
|
|
cmd.add_element("port", str(port)) |
5784
|
|
|
|
5785
|
|
|
if comment: |
5786
|
|
|
cmd.add_element("comment", comment) |
5787
|
|
|
|
5788
|
|
|
if name: |
5789
|
|
|
cmd.add_element("name", name) |
5790
|
|
|
|
5791
|
|
|
if ca_pub: |
5792
|
|
|
cmd.add_element("ca_pub", ca_pub) |
5793
|
|
|
|
5794
|
|
|
if credential_id: |
5795
|
|
|
cmd.add_element("credential", attrs={"id": str(credential_id)}) |
5796
|
|
|
|
5797
|
|
|
return self._send_xml_command(cmd) |
5798
|
|
|
|
5799
|
|
|
def modify_setting( |
5800
|
|
|
self, |
5801
|
|
|
setting_id: Optional[str] = None, |
5802
|
|
|
name: Optional[str] = None, |
5803
|
|
|
value: Optional[str] = None, |
5804
|
|
|
) -> Any: |
5805
|
|
|
"""Modifies an existing setting. |
5806
|
|
|
|
5807
|
|
|
Arguments: |
5808
|
|
|
setting_id: UUID of the setting to be changed. |
5809
|
|
|
name: The name of the setting. Either setting_id or name must be |
5810
|
|
|
passed. |
5811
|
|
|
value: The value of the setting. |
5812
|
|
|
|
5813
|
|
|
Returns: |
5814
|
|
|
The response. See :py:meth:`send_command` for details. |
5815
|
|
|
""" |
5816
|
|
|
if not setting_id and not name: |
5817
|
|
|
raise RequiredArgument( |
5818
|
|
|
function=self.modify_setting.__name__, |
5819
|
|
|
argument='setting_id or name argument', |
5820
|
|
|
) |
5821
|
|
|
|
5822
|
|
|
if value is None: |
5823
|
|
|
raise RequiredArgument( |
5824
|
|
|
function=self.modify_setting.__name__, argument='value argument' |
5825
|
|
|
) |
5826
|
|
|
|
5827
|
|
|
cmd = XmlCommand("modify_setting") |
5828
|
|
|
|
5829
|
|
|
if setting_id: |
5830
|
|
|
cmd.set_attribute("setting_id", setting_id) |
5831
|
|
|
else: |
5832
|
|
|
cmd.add_element("name", name) |
5833
|
|
|
|
5834
|
|
|
cmd.add_element("value", to_base64(value)) |
5835
|
|
|
|
5836
|
|
|
return self._send_xml_command(cmd) |
5837
|
|
|
|
5838
|
|
View Code Duplication |
def modify_user( |
|
|
|
|
5839
|
|
|
self, |
5840
|
|
|
user_id: str = None, |
5841
|
|
|
name: str = None, |
5842
|
|
|
*, |
5843
|
|
|
new_name: Optional[str] = None, |
5844
|
|
|
comment: Optional[str] = None, |
5845
|
|
|
password: Optional[str] = None, |
5846
|
|
|
auth_source: Optional[UserAuthType] = None, |
5847
|
|
|
role_ids: Optional[List[str]] = None, |
5848
|
|
|
hosts: Optional[List[str]] = None, |
5849
|
|
|
hosts_allow: Optional[bool] = False, |
5850
|
|
|
ifaces: Optional[List[str]] = None, |
5851
|
|
|
ifaces_allow: Optional[bool] = False, |
5852
|
|
|
group_ids: Optional[List[str]] = None, |
5853
|
|
|
) -> Any: |
5854
|
|
|
"""Modifies an existing user. Most of the fields need to be supplied |
5855
|
|
|
for changing a single field even if no change is wanted for those. |
5856
|
|
|
Else empty values are inserted for the missing fields instead. |
5857
|
|
|
Arguments: |
5858
|
|
|
user_id: UUID of the user to be modified. Overrides name element |
5859
|
|
|
argument. |
5860
|
|
|
name: The name of the user to be modified. Either user_id or name |
5861
|
|
|
must be passed. |
5862
|
|
|
new_name: The new name for the user. |
5863
|
|
|
comment: Comment on the user. |
5864
|
|
|
password: The password for the user. |
5865
|
|
|
auth_source: Source allowed for authentication for this user. |
5866
|
|
|
roles_id: List of roles UUIDs for the user. |
5867
|
|
|
hosts: User access rules: List of hosts. |
5868
|
|
|
hosts_allow: Defines how the hosts list is to be interpreted. |
5869
|
|
|
If False (default) the list is treated as a deny list. |
5870
|
|
|
All hosts are allowed by default except those provided by |
5871
|
|
|
the hosts parameter. If True the list is treated as a |
5872
|
|
|
allow list. All hosts are denied by default except those |
5873
|
|
|
provided by the hosts parameter. |
5874
|
|
|
ifaces: User access rules: List of ifaces. |
5875
|
|
|
ifaces_allow: Defines how the ifaces list is to be interpreted. |
5876
|
|
|
If False (default) the list is treated as a deny list. |
5877
|
|
|
All ifaces are allowed by default except those provided by |
5878
|
|
|
the ifaces parameter. If True the list is treated as a |
5879
|
|
|
allow list. All ifaces are denied by default except those |
5880
|
|
|
provided by the ifaces parameter. |
5881
|
|
|
group_ids: List of group UUIDs for the user. |
5882
|
|
|
|
5883
|
|
|
Returns: |
5884
|
|
|
The response. See :py:meth:`send_command` for details. |
5885
|
|
|
""" |
5886
|
|
|
if not user_id and not name: |
5887
|
|
|
raise RequiredArgument( |
5888
|
|
|
function=self.modify_user.__name__, argument='user_id or name' |
5889
|
|
|
) |
5890
|
|
|
|
5891
|
|
|
cmd = XmlCommand("modify_user") |
5892
|
|
|
|
5893
|
|
|
if user_id: |
5894
|
|
|
cmd.set_attribute("user_id", user_id) |
5895
|
|
|
else: |
5896
|
|
|
cmd.add_element("name", name) |
5897
|
|
|
|
5898
|
|
|
if new_name: |
5899
|
|
|
cmd.add_element("new_name", new_name) |
5900
|
|
|
|
5901
|
|
|
if role_ids: |
5902
|
|
|
for role in role_ids: |
5903
|
|
|
cmd.add_element("role", attrs={"id": role}) |
5904
|
|
|
|
5905
|
|
|
if hosts: |
5906
|
|
|
cmd.add_element( |
5907
|
|
|
"hosts", |
5908
|
|
|
to_comma_list(hosts), |
5909
|
|
|
attrs={"allow": to_bool(hosts_allow)}, |
5910
|
|
|
) |
5911
|
|
|
|
5912
|
|
|
if ifaces: |
5913
|
|
|
cmd.add_element( |
5914
|
|
|
"ifaces", |
5915
|
|
|
to_comma_list(ifaces), |
5916
|
|
|
attrs={"allow": to_bool(ifaces_allow)}, |
5917
|
|
|
) |
5918
|
|
|
|
5919
|
|
|
if comment: |
5920
|
|
|
cmd.add_element("comment", comment) |
5921
|
|
|
|
5922
|
|
|
if password: |
5923
|
|
|
cmd.add_element("password", password) |
5924
|
|
|
|
5925
|
|
|
if auth_source: |
5926
|
|
|
_xmlauthsrc = cmd.add_element("sources") |
5927
|
|
|
_xmlauthsrc.add_element("source", auth_source.value) |
5928
|
|
|
|
5929
|
|
|
if group_ids: |
5930
|
|
|
_xmlgroups = cmd.add_element("groups") |
5931
|
|
|
for group_id in group_ids: |
5932
|
|
|
_xmlgroups.add_element("group", attrs={"id": group_id}) |
5933
|
|
|
|
5934
|
|
|
return self._send_xml_command(cmd) |
5935
|
|
|
|
5936
|
|
|
def restore(self, entity_id: str) -> Any: |
5937
|
|
|
"""Restore an entity from the trashcan |
5938
|
|
|
|
5939
|
|
|
Arguments: |
5940
|
|
|
entity_id: ID of the entity to be restored from the trashcan |
5941
|
|
|
|
5942
|
|
|
Returns: |
5943
|
|
|
The response. See :py:meth:`send_command` for details. |
5944
|
|
|
""" |
5945
|
|
|
if not entity_id: |
5946
|
|
|
raise RequiredArgument( |
5947
|
|
|
function=self.restore.__name__, argument='entity_id' |
5948
|
|
|
) |
5949
|
|
|
|
5950
|
|
|
cmd = XmlCommand("restore") |
5951
|
|
|
cmd.set_attribute("id", entity_id) |
5952
|
|
|
|
5953
|
|
|
return self._send_xml_command(cmd) |
5954
|
|
|
|
5955
|
|
|
def sync_cert(self) -> Any: |
5956
|
|
|
"""Request a synchronization with the CERT feed service |
5957
|
|
|
|
5958
|
|
|
Returns: |
5959
|
|
|
The response. See :py:meth:`send_command` for details. |
5960
|
|
|
""" |
5961
|
|
|
return self._send_xml_command(XmlCommand("sync_cert")) |
5962
|
|
|
|
5963
|
|
|
def sync_config(self) -> Any: |
5964
|
|
|
"""Request an OSP config synchronization with scanner |
5965
|
|
|
|
5966
|
|
|
Returns: |
5967
|
|
|
The response. See :py:meth:`send_command` for details. |
5968
|
|
|
""" |
5969
|
|
|
return self._send_xml_command(XmlCommand("sync_config")) |
5970
|
|
|
|
5971
|
|
|
def sync_feed(self) -> Any: |
5972
|
|
|
"""Request a synchronization with the NVT feed service |
5973
|
|
|
|
5974
|
|
|
Returns: |
5975
|
|
|
The response. See :py:meth:`send_command` for details. |
5976
|
|
|
""" |
5977
|
|
|
return self._send_xml_command(XmlCommand("sync_feed")) |
5978
|
|
|
|
5979
|
|
|
def sync_scap(self) -> Any: |
5980
|
|
|
"""Request a synchronization with the SCAP feed service |
5981
|
|
|
|
5982
|
|
|
Returns: |
5983
|
|
|
The response. See :py:meth:`send_command` for details. |
5984
|
|
|
""" |
5985
|
|
|
return self._send_xml_command(XmlCommand("sync_scap")) |
5986
|
|
|
|
5987
|
|
|
def test_alert(self, alert_id: str) -> Any: |
5988
|
|
|
"""Run an alert |
5989
|
|
|
|
5990
|
|
|
Invoke a test run of an alert |
5991
|
|
|
|
5992
|
|
|
Arguments: |
5993
|
|
|
alert_id: UUID of the alert to be tested |
5994
|
|
|
|
5995
|
|
|
Returns: |
5996
|
|
|
The response. See :py:meth:`send_command` for details. |
5997
|
|
|
""" |
5998
|
|
|
if not alert_id: |
5999
|
|
|
raise InvalidArgument("test_alert requires an alert_id argument") |
6000
|
|
|
|
6001
|
|
|
cmd = XmlCommand("test_alert") |
6002
|
|
|
cmd.set_attribute("alert_id", alert_id) |
6003
|
|
|
|
6004
|
|
|
return self._send_xml_command(cmd) |
6005
|
|
|
|
6006
|
|
|
def trigger_alert( |
6007
|
|
|
self, |
6008
|
|
|
alert_id: str, |
6009
|
|
|
report_id: str, |
6010
|
|
|
*, |
6011
|
|
|
filter: Optional[str] = None, |
6012
|
|
|
filter_id: Optional[str] = None, |
6013
|
|
|
report_format_id: Optional[Union[str, ReportFormatType]] = None, |
6014
|
|
|
delta_report_id: Optional[str] = None, |
6015
|
|
|
) -> Any: |
6016
|
|
|
"""Run an alert by ignoring its event and conditions |
6017
|
|
|
|
6018
|
|
|
The alert is triggered to run immediately with the provided filtered |
6019
|
|
|
report by ignoring the even and condition settings. |
6020
|
|
|
|
6021
|
|
|
Arguments: |
6022
|
|
|
alert_id: UUID of the alert to be run |
6023
|
|
|
report_id: UUID of the report to be provided to the alert |
6024
|
|
|
filter: Filter term to use to filter results in the report |
6025
|
|
|
filter_id: UUID of filter to use to filter results in the report |
6026
|
|
|
report_format_id: UUID of report format to use |
6027
|
|
|
or ReportFormatType (enum) |
6028
|
|
|
delta_report_id: UUID of an existing report to compare report to. |
6029
|
|
|
|
6030
|
|
|
Returns: |
6031
|
|
|
The response. See :py:meth:`send_command` for details. |
6032
|
|
|
""" |
6033
|
|
|
if not alert_id: |
6034
|
|
|
raise RequiredArgument( |
6035
|
|
|
function=self.trigger_alert.__name__, |
6036
|
|
|
argument='alert_id argument', |
6037
|
|
|
) |
6038
|
|
|
|
6039
|
|
|
if not report_id: |
6040
|
|
|
raise RequiredArgument( |
6041
|
|
|
function=self.trigger_alert.__name__, |
6042
|
|
|
argument='report_id argument', |
6043
|
|
|
) |
6044
|
|
|
|
6045
|
|
|
cmd = XmlCommand("get_reports") |
6046
|
|
|
cmd.set_attribute("report_id", report_id) |
6047
|
|
|
cmd.set_attribute("alert_id", alert_id) |
6048
|
|
|
|
6049
|
|
|
if filter: |
6050
|
|
|
cmd.set_attribute("filter", filter) |
6051
|
|
|
|
6052
|
|
|
if filter_id: |
6053
|
|
|
cmd.set_attribute("filt_id", filter_id) |
6054
|
|
|
|
6055
|
|
|
if report_format_id: |
6056
|
|
|
if isinstance(report_format_id, ReportFormatType): |
6057
|
|
|
report_format_id = report_format_id.value |
6058
|
|
|
|
6059
|
|
|
cmd.set_attribute("format_id", report_format_id) |
6060
|
|
|
|
6061
|
|
|
if delta_report_id: |
6062
|
|
|
cmd.set_attribute("delta_report_id", delta_report_id) |
6063
|
|
|
|
6064
|
|
|
return self._send_xml_command(cmd) |
6065
|
|
|
|
6066
|
|
View Code Duplication |
def verify_report_format( |
|
|
|
|
6067
|
|
|
self, report_format_id: Union[str, ReportFormatType] |
6068
|
|
|
) -> Any: |
6069
|
|
|
"""Verify an existing report format |
6070
|
|
|
|
6071
|
|
|
Verifies the trust level of an existing report format. It will be |
6072
|
|
|
checked whether the signature of the report format currently matches the |
6073
|
|
|
report format. This includes the script and files used to generate |
6074
|
|
|
reports of this format. It is *not* verified if the report format works |
6075
|
|
|
as expected by the user. |
6076
|
|
|
|
6077
|
|
|
Arguments: |
6078
|
|
|
report_format_id: UUID of the report format to be verified |
6079
|
|
|
or ReportFormatType (enum) |
6080
|
|
|
|
6081
|
|
|
Returns: |
6082
|
|
|
The response. See :py:meth:`send_command` for details. |
6083
|
|
|
""" |
6084
|
|
|
if not report_format_id: |
6085
|
|
|
raise RequiredArgument( |
6086
|
|
|
function=self.verify_report_format.__name__, |
6087
|
|
|
argument='report_format_id', |
6088
|
|
|
) |
6089
|
|
|
|
6090
|
|
|
cmd = XmlCommand("verify_report_format") |
6091
|
|
|
|
6092
|
|
|
if isinstance(report_format_id, ReportFormatType): |
6093
|
|
|
report_format_id = report_format_id.value |
6094
|
|
|
|
6095
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
6096
|
|
|
|
6097
|
|
|
return self._send_xml_command(cmd) |
6098
|
|
|
|
6099
|
|
|
def verify_scanner(self, scanner_id: str) -> Any: |
6100
|
|
|
"""Verify an existing scanner |
6101
|
|
|
|
6102
|
|
|
Verifies if it is possible to connect to an existing scanner. It is |
6103
|
|
|
*not* verified if the scanner works as expected by the user. |
6104
|
|
|
|
6105
|
|
|
Arguments: |
6106
|
|
|
scanner_id: UUID of the scanner to be verified |
6107
|
|
|
|
6108
|
|
|
Returns: |
6109
|
|
|
The response. See :py:meth:`send_command` for details. |
6110
|
|
|
""" |
6111
|
|
|
if not scanner_id: |
6112
|
|
|
raise RequiredArgument( |
6113
|
|
|
function=self.verify_scanner.__name__, argument='scanner_id' |
6114
|
|
|
) |
6115
|
|
|
|
6116
|
|
|
cmd = XmlCommand("verify_scanner") |
6117
|
|
|
cmd.set_attribute("scanner_id", scanner_id) |
6118
|
|
|
|
6119
|
|
|
return self._send_xml_command(cmd) |
6120
|
|
|
|