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 logging |
29
|
|
|
from numbers import Integral |
30
|
|
|
|
31
|
|
|
from typing import Any, List, Optional, Callable, Union |
32
|
|
|
from lxml import etree |
33
|
|
|
|
34
|
|
|
from gvm.connections import GvmConnection |
35
|
|
|
from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument |
36
|
|
|
from gvm.protocols.base import GvmProtocol |
37
|
|
|
from gvm.protocols.gmpv208.entities.report_formats import ( |
38
|
|
|
ReportFormatType, |
39
|
|
|
) |
40
|
|
|
from gvm.utils import ( |
41
|
|
|
check_command_status, |
42
|
|
|
to_base64, |
43
|
|
|
to_bool, |
44
|
|
|
to_comma_list, |
45
|
|
|
add_filter, |
46
|
|
|
) |
47
|
|
|
from gvm.xml import XmlCommand |
48
|
|
|
|
49
|
|
|
from . import types |
50
|
|
|
from .types import * # pylint: disable=unused-wildcard-import, wildcard-import |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
PROTOCOL_VERSION = (20, 8) |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
logger = logging.getLogger(__name__) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
class GmpV208Mixin(GvmProtocol): |
60
|
|
|
"""Python interface for Greenbone Management Protocol |
61
|
|
|
|
62
|
|
|
This class implements the `Greenbone Management Protocol version 20.08`_ |
63
|
|
|
|
64
|
|
|
Arguments: |
65
|
|
|
connection: Connection to use to talk with the gvmd daemon. See |
66
|
|
|
:mod:`gvm.connections` for possible connection types. |
67
|
|
|
transform: Optional transform `callable`_ to convert response data. |
68
|
|
|
After each request the callable gets passed the plain response data |
69
|
|
|
which can be used to check the data and/or conversion into different |
70
|
|
|
representations like a xml dom. |
71
|
|
|
|
72
|
|
|
See :mod:`gvm.transforms` for existing transforms. |
73
|
|
|
|
74
|
|
|
.. _Greenbone Management Protocol version 20.08: |
75
|
|
|
https://docs.greenbone.net/API/GMP/gmp-20.08.html |
76
|
|
|
.. _callable: |
77
|
|
|
https://docs.python.org/3/library/functions.html#callable |
78
|
|
|
""" |
79
|
|
|
|
80
|
|
|
types = types |
|
|
|
|
81
|
|
|
|
82
|
|
|
def __init__( |
83
|
|
|
self, |
84
|
|
|
connection: GvmConnection, |
85
|
|
|
*, |
86
|
|
|
transform: Optional[Callable[[str], Any]] = None, |
87
|
|
|
): |
88
|
|
|
super().__init__(connection, transform=transform) |
89
|
|
|
|
90
|
|
|
# Is authenticated on gvmd |
91
|
|
|
self._authenticated = False |
92
|
|
|
|
93
|
|
|
def is_authenticated(self) -> bool: |
94
|
|
|
"""Checks if the user is authenticated |
95
|
|
|
|
96
|
|
|
If the user is authenticated privileged GMP commands like get_tasks |
97
|
|
|
may be send to gvmd. |
98
|
|
|
|
99
|
|
|
Returns: |
100
|
|
|
bool: True if an authenticated connection to gvmd has been |
101
|
|
|
established. |
102
|
|
|
""" |
103
|
|
|
return self._authenticated |
104
|
|
|
|
105
|
|
|
def authenticate(self, username: str, password: str) -> Any: |
106
|
|
|
"""Authenticate to gvmd. |
107
|
|
|
|
108
|
|
|
The generated authenticate command will be send to server. |
109
|
|
|
Afterwards the response is read, transformed and returned. |
110
|
|
|
|
111
|
|
|
Arguments: |
112
|
|
|
username: Username |
113
|
|
|
password: Password |
114
|
|
|
|
115
|
|
|
Returns: |
116
|
|
|
Transformed response from server. |
117
|
|
|
""" |
118
|
|
|
cmd = XmlCommand("authenticate") |
119
|
|
|
|
120
|
|
|
if not username: |
121
|
|
|
raise RequiredArgument( |
122
|
|
|
function=self.authenticate.__name__, argument='username' |
123
|
|
|
) |
124
|
|
|
|
125
|
|
|
if not password: |
126
|
|
|
raise RequiredArgument( |
127
|
|
|
function=self.authenticate.__name__, argument='password' |
128
|
|
|
) |
129
|
|
|
|
130
|
|
|
credentials = cmd.add_element("credentials") |
131
|
|
|
credentials.add_element("username", username) |
132
|
|
|
credentials.add_element("password", password) |
133
|
|
|
|
134
|
|
|
self._send(cmd.to_string()) |
135
|
|
|
response = self._read() |
136
|
|
|
|
137
|
|
|
if check_command_status(response): |
138
|
|
|
self._authenticated = True |
139
|
|
|
|
140
|
|
|
return self._transform(response) |
141
|
|
|
|
142
|
|
|
def create_permission( |
143
|
|
|
self, |
144
|
|
|
name: str, |
145
|
|
|
subject_id: str, |
146
|
|
|
subject_type: PermissionSubjectType, |
147
|
|
|
*, |
148
|
|
|
resource_id: Optional[str] = None, |
149
|
|
|
resource_type: Optional[EntityType] = None, |
150
|
|
|
comment: Optional[str] = None, |
151
|
|
|
) -> Any: |
152
|
|
|
"""Create a new permission |
153
|
|
|
|
154
|
|
|
Arguments: |
155
|
|
|
name: Name of the new permission |
156
|
|
|
subject_id: UUID of subject to whom the permission is granted |
157
|
|
|
subject_type: Type of the subject user, group or role |
158
|
|
|
comment: Comment for the permission |
159
|
|
|
resource_id: UUID of entity to which the permission applies |
160
|
|
|
resource_type: Type of the resource. For Super permissions user, |
161
|
|
|
group or role |
162
|
|
|
|
163
|
|
|
Returns: |
164
|
|
|
The response. See :py:meth:`send_command` for details. |
165
|
|
|
""" |
166
|
|
|
if not name: |
167
|
|
|
raise RequiredArgument( |
168
|
|
|
function=self.create_permission.__name__, argument='name' |
169
|
|
|
) |
170
|
|
|
|
171
|
|
|
if not subject_id: |
172
|
|
|
raise RequiredArgument( |
173
|
|
|
function=self.create_permission.__name__, argument='subject_id' |
174
|
|
|
) |
175
|
|
|
|
176
|
|
|
if not isinstance(subject_type, PermissionSubjectType): |
177
|
|
|
raise InvalidArgumentType( |
178
|
|
|
function=self.create_permission.__name__, |
179
|
|
|
argument='subject_type', |
180
|
|
|
arg_type=PermissionSubjectType.__name__, |
181
|
|
|
) |
182
|
|
|
|
183
|
|
|
cmd = XmlCommand("create_permission") |
184
|
|
|
cmd.add_element("name", name) |
185
|
|
|
|
186
|
|
|
_xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
187
|
|
|
_xmlsubject.add_element("type", subject_type.value) |
188
|
|
|
|
189
|
|
|
if comment: |
190
|
|
|
cmd.add_element("comment", comment) |
191
|
|
|
|
192
|
|
View Code Duplication |
if resource_id or resource_type: |
|
|
|
|
193
|
|
|
if not resource_id: |
194
|
|
|
raise RequiredArgument( |
195
|
|
|
function=self.create_permission.__name__, |
196
|
|
|
argument='resource_id', |
197
|
|
|
) |
198
|
|
|
|
199
|
|
|
if not resource_type: |
200
|
|
|
raise RequiredArgument( |
201
|
|
|
function=self.create_permission.__name__, |
202
|
|
|
argument='resource_type', |
203
|
|
|
) |
204
|
|
|
|
205
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
206
|
|
|
raise InvalidArgumentType( |
207
|
|
|
function=self.create_permission.__name__, |
208
|
|
|
argument='resource_type', |
209
|
|
|
arg_type=self.types.EntityType.__name__, |
210
|
|
|
) |
211
|
|
|
|
212
|
|
|
_xmlresource = cmd.add_element( |
213
|
|
|
"resource", attrs={"id": resource_id} |
214
|
|
|
) |
215
|
|
|
|
216
|
|
|
_actual_resource_type = resource_type |
217
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
218
|
|
|
_actual_resource_type = EntityType.TASK |
219
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
220
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
221
|
|
|
|
222
|
|
|
_xmlresource.add_element("type", _actual_resource_type.value) |
223
|
|
|
|
224
|
|
|
return self._send_xml_command(cmd) |
225
|
|
|
|
226
|
|
|
def create_tag( |
227
|
|
|
self, |
228
|
|
|
name: str, |
229
|
|
|
resource_type: EntityType, |
230
|
|
|
*, |
231
|
|
|
resource_filter: Optional[str] = None, |
232
|
|
|
resource_ids: Optional[List[str]] = None, |
233
|
|
|
value: Optional[str] = None, |
234
|
|
|
comment: Optional[str] = None, |
235
|
|
|
active: Optional[bool] = None, |
236
|
|
|
) -> Any: |
237
|
|
|
"""Create a tag. |
238
|
|
|
|
239
|
|
|
Arguments: |
240
|
|
|
name: Name of the tag. A full tag name consisting of namespace and |
241
|
|
|
predicate e.g. `foo:bar`. |
242
|
|
|
resource_type: Entity type the tag is to be attached to. |
243
|
|
|
resource_filter: Filter term to select resources the tag is to be |
244
|
|
|
attached to. Only one of resource_filter or resource_ids can be |
245
|
|
|
provided. |
246
|
|
|
resource_ids: IDs of the resources the tag is to be attached to. |
247
|
|
|
Only one of resource_filter or resource_ids can be provided. |
248
|
|
|
value: Value associated with the tag. |
249
|
|
|
comment: Comment for the tag. |
250
|
|
|
active: Whether the tag should be active. |
251
|
|
|
|
252
|
|
|
Returns: |
253
|
|
|
The response. See :py:meth:`send_command` for details. |
254
|
|
|
""" |
255
|
|
|
if not name: |
256
|
|
|
raise RequiredArgument( |
257
|
|
|
function=self.create_tag.__name__, argument='name' |
258
|
|
|
) |
259
|
|
|
|
260
|
|
|
if resource_filter and resource_ids: |
261
|
|
|
raise InvalidArgument( |
262
|
|
|
"create_tag accepts either resource_filter or resource_ids " |
263
|
|
|
"argument", |
264
|
|
|
function=self.create_tag.__name__, |
265
|
|
|
) |
266
|
|
|
|
267
|
|
|
if not resource_type: |
268
|
|
|
raise RequiredArgument( |
269
|
|
|
function=self.create_tag.__name__, argument='resource_type' |
270
|
|
|
) |
271
|
|
|
|
272
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
273
|
|
|
raise InvalidArgumentType( |
274
|
|
|
function=self.create_tag.__name__, |
275
|
|
|
argument='resource_type', |
276
|
|
|
arg_type=EntityType.__name__, |
277
|
|
|
) |
278
|
|
|
|
279
|
|
|
cmd = XmlCommand('create_tag') |
280
|
|
|
cmd.add_element('name', name) |
281
|
|
|
|
282
|
|
|
_xmlresources = cmd.add_element("resources") |
283
|
|
|
if resource_filter is not None: |
284
|
|
|
_xmlresources.set_attribute("filter", resource_filter) |
285
|
|
|
|
286
|
|
|
for resource_id in resource_ids or []: |
287
|
|
|
_xmlresources.add_element( |
288
|
|
|
"resource", attrs={"id": str(resource_id)} |
289
|
|
|
) |
290
|
|
|
|
291
|
|
|
_actual_resource_type = resource_type |
292
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
293
|
|
|
_actual_resource_type = EntityType.TASK |
294
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
295
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
296
|
|
|
_xmlresources.add_element("type", _actual_resource_type.value) |
297
|
|
|
|
298
|
|
|
if comment: |
299
|
|
|
cmd.add_element("comment", comment) |
300
|
|
|
|
301
|
|
|
if value: |
302
|
|
|
cmd.add_element("value", value) |
303
|
|
|
|
304
|
|
|
if active is not None: |
305
|
|
|
if active: |
306
|
|
|
cmd.add_element("active", "1") |
307
|
|
|
else: |
308
|
|
|
cmd.add_element("active", "0") |
309
|
|
|
|
310
|
|
|
return self._send_xml_command(cmd) |
311
|
|
|
|
312
|
|
|
def get_aggregates( |
313
|
|
|
self, |
314
|
|
|
resource_type: EntityType, |
315
|
|
|
*, |
316
|
|
|
filter: Optional[str] = None, |
317
|
|
|
filter_id: Optional[str] = None, |
318
|
|
|
sort_criteria: Optional[list] = None, |
319
|
|
|
data_columns: Optional[list] = None, |
320
|
|
|
group_column: Optional[str] = None, |
321
|
|
|
subgroup_column: Optional[str] = None, |
322
|
|
|
text_columns: Optional[list] = None, |
323
|
|
|
first_group: Optional[int] = None, |
324
|
|
|
max_groups: Optional[int] = None, |
325
|
|
|
mode: Optional[int] = None, |
326
|
|
|
**kwargs, |
327
|
|
|
) -> Any: |
328
|
|
|
"""Request aggregated information on a resource / entity type |
329
|
|
|
|
330
|
|
|
Additional arguments can be set via the kwargs parameter for backward |
331
|
|
|
compatibility with older versions of python-gvm, but are not validated. |
332
|
|
|
|
333
|
|
|
Arguments: |
334
|
|
|
resource_type: The entity type to gather data from |
335
|
|
|
filter: Filter term to use for the query |
336
|
|
|
filter_id: UUID of an existing filter to use for the query |
337
|
|
|
sort_criteria: List of sort criteria (dicts that can contain |
338
|
|
|
a field, stat and order) |
339
|
|
|
data_columns: List of fields to aggregate data from |
340
|
|
|
group_column: The field to group the entities by |
341
|
|
|
subgroup_column: The field to further group the entities |
342
|
|
|
inside groups by |
343
|
|
|
text_columns: List of simple text columns which no statistics |
344
|
|
|
are calculated for |
345
|
|
|
first_group: The index of the first aggregate group to return |
346
|
|
|
max_groups: The maximum number of aggregate groups to return, |
347
|
|
|
-1 for all |
348
|
|
|
mode: Special mode for aggregation |
349
|
|
|
|
350
|
|
|
Returns: |
351
|
|
|
The response. See :py:meth:`send_command` for details. |
352
|
|
|
""" |
353
|
|
|
if not resource_type: |
354
|
|
|
raise RequiredArgument( |
355
|
|
|
function=self.get_aggregates.__name__, argument='resource_type' |
356
|
|
|
) |
357
|
|
|
|
358
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
359
|
|
|
raise InvalidArgumentType( |
360
|
|
|
function=self.get_aggregates.__name__, |
361
|
|
|
argument='resource_type', |
362
|
|
|
arg_type=self.types.EntityType.__name__, |
363
|
|
|
) |
364
|
|
|
|
365
|
|
|
cmd = XmlCommand('get_aggregates') |
366
|
|
|
|
367
|
|
|
_actual_resource_type = resource_type |
368
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
369
|
|
|
_actual_resource_type = EntityType.TASK |
370
|
|
|
cmd.set_attribute('usage_type', 'audit') |
371
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
372
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
373
|
|
|
cmd.set_attribute('usage_type', 'policy') |
374
|
|
|
elif resource_type.value == EntityType.SCAN_CONFIG.value: |
375
|
|
|
cmd.set_attribute('usage_type', 'scan') |
376
|
|
|
elif resource_type.value == EntityType.TASK.value: |
377
|
|
|
cmd.set_attribute('usage_type', 'scan') |
378
|
|
|
cmd.set_attribute('type', _actual_resource_type.value) |
379
|
|
|
|
380
|
|
|
add_filter(cmd, filter, filter_id) |
381
|
|
|
|
382
|
|
|
if first_group is not None: |
383
|
|
|
if not isinstance(first_group, int): |
384
|
|
|
raise InvalidArgumentType( |
385
|
|
|
function=self.get_aggregates.__name__, |
386
|
|
|
argument='first_group', |
387
|
|
|
arg_type=int.__name__, |
388
|
|
|
) |
389
|
|
|
cmd.set_attribute('first_group', str(first_group)) |
390
|
|
|
|
391
|
|
|
if max_groups is not None: |
392
|
|
|
if not isinstance(max_groups, int): |
393
|
|
|
raise InvalidArgumentType( |
394
|
|
|
function=self.get_aggregates.__name__, |
395
|
|
|
argument='max_groups', |
396
|
|
|
arg_type=int.__name__, |
397
|
|
|
) |
398
|
|
|
cmd.set_attribute('max_groups', str(max_groups)) |
399
|
|
|
|
400
|
|
|
if sort_criteria is not None: |
401
|
|
|
if not isinstance(sort_criteria, list): |
402
|
|
|
raise InvalidArgumentType( |
403
|
|
|
function=self.get_aggregates.__name__, |
404
|
|
|
argument='sort_criteria', |
405
|
|
|
arg_type=list.__name__, |
406
|
|
|
) |
407
|
|
|
for sort in sort_criteria: |
408
|
|
|
if not isinstance(sort, dict): |
409
|
|
|
raise InvalidArgumentType( |
410
|
|
|
function=self.get_aggregates.__name__, |
411
|
|
|
argument='sort_criteria', |
412
|
|
|
) |
413
|
|
|
|
414
|
|
|
sort_elem = cmd.add_element('sort') |
415
|
|
|
if sort.get('field'): |
416
|
|
|
sort_elem.set_attribute('field', sort.get('field')) |
417
|
|
|
|
418
|
|
|
if sort.get('stat'): |
419
|
|
|
if isinstance(sort['stat'], AggregateStatistic): |
420
|
|
|
sort_elem.set_attribute('stat', sort['stat'].value) |
421
|
|
|
else: |
422
|
|
|
stat = get_aggregate_statistic_from_string(sort['stat']) |
423
|
|
|
sort_elem.set_attribute('stat', stat.value) |
424
|
|
|
|
425
|
|
|
if sort.get('order'): |
426
|
|
|
if isinstance(sort['order'], SortOrder): |
427
|
|
|
sort_elem.set_attribute('order', sort['order'].value) |
428
|
|
|
else: |
429
|
|
|
so = get_sort_order_from_string(sort['order']) |
430
|
|
|
sort_elem.set_attribute('order', so.value) |
431
|
|
|
|
432
|
|
|
if data_columns is not None: |
433
|
|
|
if not isinstance(data_columns, list): |
434
|
|
|
raise InvalidArgumentType( |
435
|
|
|
function=self.get_aggregates.__name__, |
436
|
|
|
argument='data_columns', |
437
|
|
|
arg_type=list.__name__, |
438
|
|
|
) |
439
|
|
|
for column in data_columns: |
440
|
|
|
cmd.add_element('data_column', column) |
441
|
|
|
|
442
|
|
|
if group_column is not None: |
443
|
|
|
cmd.set_attribute('group_column', group_column) |
444
|
|
|
|
445
|
|
|
if subgroup_column is not None: |
446
|
|
|
if not group_column: |
447
|
|
|
raise RequiredArgument( |
448
|
|
|
'{} requires a group_column argument' |
449
|
|
|
' if subgroup_column is given'.format( |
450
|
|
|
self.get_aggregates.__name__ |
451
|
|
|
), |
452
|
|
|
function=self.get_aggregates.__name__, |
453
|
|
|
argument='subgroup_column', |
454
|
|
|
) |
455
|
|
|
cmd.set_attribute('subgroup_column', subgroup_column) |
456
|
|
|
|
457
|
|
|
if text_columns is not None: |
458
|
|
|
if not isinstance(text_columns, list): |
459
|
|
|
raise InvalidArgumentType( |
460
|
|
|
function=self.get_aggregates.__name__, |
461
|
|
|
argument='text_columns', |
462
|
|
|
arg_type=list.__name__, |
463
|
|
|
) |
464
|
|
|
for column in text_columns: |
465
|
|
|
cmd.add_element('text_column', column) |
466
|
|
|
|
467
|
|
|
if mode is not None: |
468
|
|
|
cmd.set_attribute('mode', mode) |
469
|
|
|
|
470
|
|
|
# Add additional keyword args as attributes for backward compatibility. |
471
|
|
|
cmd.set_attributes(kwargs) |
472
|
|
|
|
473
|
|
|
return self._send_xml_command(cmd) |
474
|
|
|
|
475
|
|
|
def modify_permission( |
476
|
|
|
self, |
477
|
|
|
permission_id: str, |
478
|
|
|
*, |
479
|
|
|
comment: Optional[str] = None, |
480
|
|
|
name: Optional[str] = None, |
481
|
|
|
resource_id: Optional[str] = None, |
482
|
|
|
resource_type: Optional[EntityType] = None, |
483
|
|
|
subject_id: Optional[str] = None, |
484
|
|
|
subject_type: Optional[PermissionSubjectType] = None, |
485
|
|
|
) -> Any: |
486
|
|
|
"""Modifies an existing permission. |
487
|
|
|
|
488
|
|
|
Arguments: |
489
|
|
|
permission_id: UUID of permission to be modified. |
490
|
|
|
comment: The comment on the permission. |
491
|
|
|
name: Permission name, currently the name of a command. |
492
|
|
|
subject_id: UUID of subject to whom the permission is granted |
493
|
|
|
subject_type: Type of the subject user, group or role |
494
|
|
|
resource_id: UUID of entity to which the permission applies |
495
|
|
|
resource_type: Type of the resource. For Super permissions user, |
496
|
|
|
group or role |
497
|
|
|
|
498
|
|
|
Returns: |
499
|
|
|
The response. See :py:meth:`send_command` for details. |
500
|
|
|
""" |
501
|
|
|
if not permission_id: |
502
|
|
|
raise RequiredArgument( |
503
|
|
|
function=self.modify_permission.__name__, |
504
|
|
|
argument='permission_id', |
505
|
|
|
) |
506
|
|
|
|
507
|
|
|
cmd = XmlCommand("modify_permission") |
508
|
|
|
cmd.set_attribute("permission_id", permission_id) |
509
|
|
|
|
510
|
|
|
if comment: |
511
|
|
|
cmd.add_element("comment", comment) |
512
|
|
|
|
513
|
|
|
if name: |
514
|
|
|
cmd.add_element("name", name) |
515
|
|
|
|
516
|
|
View Code Duplication |
if resource_id or resource_type: |
|
|
|
|
517
|
|
|
if not resource_id: |
518
|
|
|
raise RequiredArgument( |
519
|
|
|
function=self.modify_permission.__name__, |
520
|
|
|
argument='resource_id', |
521
|
|
|
) |
522
|
|
|
|
523
|
|
|
if not resource_type: |
524
|
|
|
raise RequiredArgument( |
525
|
|
|
function=self.modify_permission.__name__, |
526
|
|
|
argument='resource_type', |
527
|
|
|
) |
528
|
|
|
|
529
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
530
|
|
|
raise InvalidArgumentType( |
531
|
|
|
function=self.modify_permission.__name__, |
532
|
|
|
argument='resource_type', |
533
|
|
|
arg_type=self.types.EntityType.__name__, |
534
|
|
|
) |
535
|
|
|
|
536
|
|
|
_xmlresource = cmd.add_element( |
537
|
|
|
"resource", attrs={"id": resource_id} |
538
|
|
|
) |
539
|
|
|
_actual_resource_type = resource_type |
540
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
541
|
|
|
_actual_resource_type = EntityType.TASK |
542
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
543
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
544
|
|
|
_xmlresource.add_element("type", _actual_resource_type.value) |
545
|
|
|
|
546
|
|
|
if subject_id or subject_type: |
547
|
|
|
if not subject_id: |
548
|
|
|
raise RequiredArgument( |
549
|
|
|
function=self.modify_permission.__name__, |
550
|
|
|
argument='subject_id', |
551
|
|
|
) |
552
|
|
|
|
553
|
|
|
if not isinstance(subject_type, PermissionSubjectType): |
554
|
|
|
raise InvalidArgumentType( |
555
|
|
|
function=self.modify_permission.__name__, |
556
|
|
|
argument='subject_type', |
557
|
|
|
arg_type=PermissionSubjectType.__name__, |
558
|
|
|
) |
559
|
|
|
|
560
|
|
|
_xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
561
|
|
|
_xmlsubject.add_element("type", subject_type.value) |
562
|
|
|
|
563
|
|
|
return self._send_xml_command(cmd) |
564
|
|
|
|
565
|
|
|
def modify_tag( |
566
|
|
|
self, |
567
|
|
|
tag_id: str, |
568
|
|
|
*, |
569
|
|
|
comment: Optional[str] = None, |
570
|
|
|
name: Optional[str] = None, |
571
|
|
|
value=None, |
572
|
|
|
active=None, |
573
|
|
|
resource_action: Optional[str] = None, |
574
|
|
|
resource_type: Optional[EntityType] = None, |
575
|
|
|
resource_filter: Optional[str] = None, |
576
|
|
|
resource_ids: Optional[List[str]] = None, |
577
|
|
|
) -> Any: |
578
|
|
|
"""Modifies an existing tag. |
579
|
|
|
|
580
|
|
|
Arguments: |
581
|
|
|
tag_id: UUID of the tag. |
582
|
|
|
comment: Comment to add to the tag. |
583
|
|
|
name: Name of the tag. |
584
|
|
|
value: Value of the tag. |
585
|
|
|
active: Whether the tag is active. |
586
|
|
|
resource_action: Whether to add or remove resources instead of |
587
|
|
|
overwriting. One of '', 'add', 'set' or 'remove'. |
588
|
|
|
resource_type: Type of the resources to which to attach the tag. |
589
|
|
|
Required if resource_filter is set. |
590
|
|
|
resource_filter: Filter term to select resources the tag is to be |
591
|
|
|
attached to. |
592
|
|
|
resource_ids: IDs of the resources to which to attach the tag. |
593
|
|
|
|
594
|
|
|
Returns: |
595
|
|
|
The response. See :py:meth:`send_command` for details. |
596
|
|
|
""" |
597
|
|
|
if not tag_id: |
598
|
|
|
raise RequiredArgument( |
599
|
|
|
function=self.modify_tag.__name__, argument='tag_id' |
600
|
|
|
) |
601
|
|
|
|
602
|
|
|
cmd = XmlCommand("modify_tag") |
603
|
|
|
cmd.set_attribute("tag_id", str(tag_id)) |
604
|
|
|
|
605
|
|
|
if comment: |
606
|
|
|
cmd.add_element("comment", comment) |
607
|
|
|
|
608
|
|
|
if name: |
609
|
|
|
cmd.add_element("name", name) |
610
|
|
|
|
611
|
|
|
if value: |
612
|
|
|
cmd.add_element("value", value) |
613
|
|
|
|
614
|
|
|
if active is not None: |
615
|
|
|
cmd.add_element("active", to_bool(active)) |
616
|
|
|
|
617
|
|
|
if resource_action or resource_filter or resource_ids or resource_type: |
618
|
|
|
if resource_filter and not resource_type: |
619
|
|
|
raise RequiredArgument( |
620
|
|
|
function=self.modify_tag.__name__, argument='resource_type' |
621
|
|
|
) |
622
|
|
|
|
623
|
|
|
_xmlresources = cmd.add_element("resources") |
624
|
|
|
if resource_action is not None: |
625
|
|
|
_xmlresources.set_attribute("action", resource_action) |
626
|
|
|
|
627
|
|
|
if resource_filter is not None: |
628
|
|
|
_xmlresources.set_attribute("filter", resource_filter) |
629
|
|
|
|
630
|
|
|
for resource_id in resource_ids or []: |
631
|
|
|
_xmlresources.add_element( |
632
|
|
|
"resource", attrs={"id": str(resource_id)} |
633
|
|
|
) |
634
|
|
|
|
635
|
|
|
if resource_type is not None: |
636
|
|
|
if not isinstance(resource_type, self.types.EntityType): |
637
|
|
|
raise InvalidArgumentType( |
638
|
|
|
function=self.modify_tag.__name__, |
639
|
|
|
argument="resource_type", |
640
|
|
|
arg_type=EntityType.__name__, |
641
|
|
|
) |
642
|
|
|
_actual_resource_type = resource_type |
643
|
|
|
if resource_type.value == EntityType.AUDIT.value: |
644
|
|
|
_actual_resource_type = EntityType.TASK |
645
|
|
|
elif resource_type.value == EntityType.POLICY.value: |
646
|
|
|
_actual_resource_type = EntityType.SCAN_CONFIG |
647
|
|
|
_xmlresources.add_element("type", _actual_resource_type.value) |
648
|
|
|
|
649
|
|
|
return self._send_xml_command(cmd) |
650
|
|
|
|
651
|
|
|
def clone_ticket(self, ticket_id: str) -> Any: |
652
|
|
|
"""Clone an existing ticket |
653
|
|
|
|
654
|
|
|
Arguments: |
655
|
|
|
ticket_id: UUID of an existing ticket to clone from |
656
|
|
|
|
657
|
|
|
Returns: |
658
|
|
|
The response. See :py:meth:`send_command` for details. |
659
|
|
|
""" |
660
|
|
|
if not ticket_id: |
661
|
|
|
raise RequiredArgument( |
662
|
|
|
function=self.clone_ticket.__name__, argument='ticket_id' |
663
|
|
|
) |
664
|
|
|
|
665
|
|
|
cmd = XmlCommand("create_ticket") |
666
|
|
|
|
667
|
|
|
_copy = cmd.add_element("copy", ticket_id) |
668
|
|
|
|
669
|
|
|
return self._send_xml_command(cmd) |
670
|
|
|
|
671
|
|
|
def get_feed(self, feed_type: Optional[FeedType]) -> Any: |
672
|
|
|
"""Request a single feed |
673
|
|
|
|
674
|
|
|
Arguments: |
675
|
|
|
feed_type: Type of single feed to get: NVT, CERT or SCAP |
676
|
|
|
|
677
|
|
|
Returns: |
678
|
|
|
The response. See :py:meth:`send_command` for details. |
679
|
|
|
""" |
680
|
|
|
if not feed_type: |
681
|
|
|
raise RequiredArgument( |
682
|
|
|
function=self.get_feed.__name__, argument='feed_type' |
683
|
|
|
) |
684
|
|
|
|
685
|
|
|
if not isinstance(feed_type, FeedType): |
686
|
|
|
raise InvalidArgumentType( |
687
|
|
|
function=self.get_feed.__name__, |
688
|
|
|
argument='feed_type', |
689
|
|
|
arg_type=FeedType.__name__, |
690
|
|
|
) |
691
|
|
|
|
692
|
|
|
cmd = XmlCommand("get_feeds") |
693
|
|
|
cmd.set_attribute("type", feed_type.value) |
694
|
|
|
|
695
|
|
|
return self._send_xml_command(cmd) |
696
|
|
|
|
697
|
|
|
def create_ticket( |
698
|
|
|
self, |
699
|
|
|
*, |
700
|
|
|
result_id: str, |
701
|
|
|
assigned_to_user_id: str, |
702
|
|
|
note: str, |
703
|
|
|
comment: Optional[str] = None, |
704
|
|
|
) -> Any: |
705
|
|
|
"""Create a new ticket |
706
|
|
|
|
707
|
|
|
Arguments: |
708
|
|
|
result_id: UUID of the result the ticket applies to |
709
|
|
|
assigned_to_user_id: UUID of a user the ticket should be assigned to |
710
|
|
|
note: A note about opening the ticket |
711
|
|
|
comment: Comment for the ticket |
712
|
|
|
|
713
|
|
|
Returns: |
714
|
|
|
The response. See :py:meth:`send_command` for details. |
715
|
|
|
""" |
716
|
|
|
if not result_id: |
717
|
|
|
raise RequiredArgument( |
718
|
|
|
function=self.create_ticket.__name__, argument='result_id' |
719
|
|
|
) |
720
|
|
|
|
721
|
|
|
if not assigned_to_user_id: |
722
|
|
|
raise RequiredArgument( |
723
|
|
|
function=self.create_ticket.__name__, |
724
|
|
|
argument='assigned_to_user_id', |
725
|
|
|
) |
726
|
|
|
|
727
|
|
|
if not note: |
728
|
|
|
raise RequiredArgument( |
729
|
|
|
function=self.create_ticket.__name__, argument='note' |
730
|
|
|
) |
731
|
|
|
|
732
|
|
|
cmd = XmlCommand("create_ticket") |
733
|
|
|
|
734
|
|
|
_result = cmd.add_element("result") |
735
|
|
|
_result.set_attribute("id", result_id) |
736
|
|
|
|
737
|
|
|
_assigned = cmd.add_element("assigned_to") |
738
|
|
|
_user = _assigned.add_element("user") |
739
|
|
|
_user.set_attribute("id", assigned_to_user_id) |
740
|
|
|
|
741
|
|
|
_note = cmd.add_element("open_note", note) |
742
|
|
|
|
743
|
|
|
if comment: |
744
|
|
|
cmd.add_element("comment", comment) |
745
|
|
|
|
746
|
|
|
return self._send_xml_command(cmd) |
747
|
|
|
|
748
|
|
|
def delete_ticket( |
749
|
|
|
self, ticket_id: str, *, ultimate: Optional[bool] = False |
750
|
|
|
): |
751
|
|
|
"""Deletes an existing ticket |
752
|
|
|
|
753
|
|
|
Arguments: |
754
|
|
|
ticket_id: UUID of the ticket to be deleted. |
755
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
756
|
|
|
""" |
757
|
|
|
if not ticket_id: |
758
|
|
|
raise RequiredArgument( |
759
|
|
|
function=self.delete_ticket.__name__, argument='ticket_id' |
760
|
|
|
) |
761
|
|
|
|
762
|
|
|
cmd = XmlCommand("delete_ticket") |
763
|
|
|
cmd.set_attribute("ticket_id", ticket_id) |
764
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
765
|
|
|
|
766
|
|
|
return self._send_xml_command(cmd) |
767
|
|
|
|
768
|
|
View Code Duplication |
def get_tickets( |
|
|
|
|
769
|
|
|
self, |
770
|
|
|
*, |
771
|
|
|
trash: Optional[bool] = None, |
772
|
|
|
filter: Optional[str] = None, |
773
|
|
|
filter_id: Optional[str] = None, |
774
|
|
|
) -> Any: |
775
|
|
|
"""Request a list of tickets |
776
|
|
|
|
777
|
|
|
Arguments: |
778
|
|
|
filter: Filter term to use for the query |
779
|
|
|
filter_id: UUID of an existing filter to use for the query |
780
|
|
|
trash: True to request the tickets in the trashcan |
781
|
|
|
|
782
|
|
|
Returns: |
783
|
|
|
The response. See :py:meth:`send_command` for details. |
784
|
|
|
""" |
785
|
|
|
cmd = XmlCommand("get_tickets") |
786
|
|
|
|
787
|
|
|
add_filter(cmd, filter, filter_id) |
788
|
|
|
|
789
|
|
|
if trash is not None: |
790
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
791
|
|
|
|
792
|
|
|
return self._send_xml_command(cmd) |
793
|
|
|
|
794
|
|
|
def get_ticket(self, ticket_id: str) -> Any: |
795
|
|
|
"""Request a single ticket |
796
|
|
|
|
797
|
|
|
Arguments: |
798
|
|
|
ticket_id: UUID of an existing ticket |
799
|
|
|
|
800
|
|
|
Returns: |
801
|
|
|
The response. See :py:meth:`send_command` for details. |
802
|
|
|
""" |
803
|
|
|
if not ticket_id: |
804
|
|
|
raise RequiredArgument( |
805
|
|
|
function=self.get_ticket.__name__, argument='ticket_id' |
806
|
|
|
) |
807
|
|
|
|
808
|
|
|
cmd = XmlCommand("get_tickets") |
809
|
|
|
cmd.set_attribute("ticket_id", ticket_id) |
810
|
|
|
return self._send_xml_command(cmd) |
811
|
|
|
|
812
|
|
|
def get_vulnerabilities( |
813
|
|
|
self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
814
|
|
|
) -> Any: |
815
|
|
|
"""Request a list of vulnerabilities |
816
|
|
|
|
817
|
|
|
Arguments: |
818
|
|
|
filter: Filter term to use for the query |
819
|
|
|
filter_id: UUID of an existing filter to use for the query |
820
|
|
|
Returns: |
821
|
|
|
The response. See :py:meth:`send_command` for details. |
822
|
|
|
""" |
823
|
|
|
cmd = XmlCommand("get_vulns") |
824
|
|
|
|
825
|
|
|
add_filter(cmd, filter, filter_id) |
826
|
|
|
|
827
|
|
|
return self._send_xml_command(cmd) |
828
|
|
|
|
829
|
|
|
def get_vulnerability(self, vulnerability_id: str) -> Any: |
830
|
|
|
"""Request a single vulnerability |
831
|
|
|
|
832
|
|
|
Arguments: |
833
|
|
|
vulnerability_id: ID of an existing vulnerability |
834
|
|
|
|
835
|
|
|
Returns: |
836
|
|
|
The response. See :py:meth:`send_command` for details. |
837
|
|
|
""" |
838
|
|
|
if not vulnerability_id: |
839
|
|
|
raise RequiredArgument( |
840
|
|
|
function=self.get_vulnerability.__name__, |
841
|
|
|
argument='vulnerability_id', |
842
|
|
|
) |
843
|
|
|
|
844
|
|
|
cmd = XmlCommand("get_vulns") |
845
|
|
|
cmd.set_attribute("vuln_id", vulnerability_id) |
846
|
|
|
return self._send_xml_command(cmd) |
847
|
|
|
|
848
|
|
|
def modify_ticket( |
849
|
|
|
self, |
850
|
|
|
ticket_id: str, |
851
|
|
|
*, |
852
|
|
|
status: Optional[TicketStatus] = None, |
853
|
|
|
note: Optional[str] = None, |
854
|
|
|
assigned_to_user_id: Optional[str] = None, |
855
|
|
|
comment: Optional[str] = None, |
856
|
|
|
) -> Any: |
857
|
|
|
"""Modify a single ticket |
858
|
|
|
|
859
|
|
|
Arguments: |
860
|
|
|
ticket_id: UUID of an existing ticket |
861
|
|
|
status: New status for the ticket |
862
|
|
|
note: Note for the status change. Required if status is set. |
863
|
|
|
assigned_to_user_id: UUID of the user the ticket should be assigned |
864
|
|
|
to |
865
|
|
|
comment: Comment for the ticket |
866
|
|
|
|
867
|
|
|
Returns: |
868
|
|
|
The response. See :py:meth:`send_command` for details. |
869
|
|
|
""" |
870
|
|
|
if not ticket_id: |
871
|
|
|
raise RequiredArgument( |
872
|
|
|
function=self.modify_ticket.__name__, argument='ticket_id' |
873
|
|
|
) |
874
|
|
|
|
875
|
|
|
if status and not note: |
876
|
|
|
raise RequiredArgument( |
877
|
|
|
function=self.modify_ticket.__name__, argument='note' |
878
|
|
|
) |
879
|
|
|
|
880
|
|
|
if note and not status: |
881
|
|
|
raise RequiredArgument( |
882
|
|
|
function=self.modify_ticket.__name__, argument='status' |
883
|
|
|
) |
884
|
|
|
|
885
|
|
|
cmd = XmlCommand("modify_ticket") |
886
|
|
|
cmd.set_attribute("ticket_id", ticket_id) |
887
|
|
|
|
888
|
|
|
if assigned_to_user_id: |
889
|
|
|
_assigned = cmd.add_element("assigned_to") |
890
|
|
|
_user = _assigned.add_element("user") |
891
|
|
|
_user.set_attribute("id", assigned_to_user_id) |
892
|
|
|
|
893
|
|
|
if status: |
894
|
|
|
if not isinstance(status, self.types.TicketStatus): |
895
|
|
|
raise InvalidArgumentType( |
896
|
|
|
function=self.modify_ticket.__name__, |
897
|
|
|
argument='status', |
898
|
|
|
arg_type=TicketStatus.__name__, |
899
|
|
|
) |
900
|
|
|
|
901
|
|
|
cmd.add_element('status', status.value) |
902
|
|
|
cmd.add_element('{}_note'.format(status.name.lower()), note) |
903
|
|
|
|
904
|
|
|
if comment: |
905
|
|
|
cmd.add_element("comment", comment) |
906
|
|
|
|
907
|
|
|
return self._send_xml_command(cmd) |
908
|
|
|
|
909
|
|
View Code Duplication |
def create_filter( |
|
|
|
|
910
|
|
|
self, |
911
|
|
|
name: str, |
912
|
|
|
*, |
913
|
|
|
filter_type: Optional[FilterType] = None, |
914
|
|
|
comment: Optional[str] = None, |
915
|
|
|
term: Optional[str] = None, |
916
|
|
|
) -> Any: |
917
|
|
|
"""Create a new filter |
918
|
|
|
|
919
|
|
|
Arguments: |
920
|
|
|
name: Name of the new filter |
921
|
|
|
filter_type: Filter for entity type |
922
|
|
|
comment: Comment for the filter |
923
|
|
|
term: Filter term e.g. 'name=foo' |
924
|
|
|
|
925
|
|
|
Returns: |
926
|
|
|
The response. See :py:meth:`send_command` for details. |
927
|
|
|
""" |
928
|
|
|
if not name: |
929
|
|
|
raise RequiredArgument( |
930
|
|
|
function=self.create_filter.__name__, argument="name" |
931
|
|
|
) |
932
|
|
|
|
933
|
|
|
cmd = XmlCommand("create_filter") |
934
|
|
|
_xmlname = cmd.add_element("name", name) |
935
|
|
|
|
936
|
|
|
if comment: |
937
|
|
|
cmd.add_element("comment", comment) |
938
|
|
|
|
939
|
|
|
if term: |
940
|
|
|
cmd.add_element("term", term) |
941
|
|
|
|
942
|
|
|
if filter_type: |
943
|
|
|
if not isinstance(filter_type, self.types.FilterType): |
944
|
|
|
raise InvalidArgumentType( |
945
|
|
|
function=self.create_filter.__name__, |
946
|
|
|
argument="filter_type", |
947
|
|
|
arg_type=self.types.FilterType.__name__, |
948
|
|
|
) |
949
|
|
|
|
950
|
|
|
cmd.add_element("type", filter_type.value) |
951
|
|
|
|
952
|
|
|
return self._send_xml_command(cmd) |
953
|
|
|
|
954
|
|
View Code Duplication |
def modify_filter( |
|
|
|
|
955
|
|
|
self, |
956
|
|
|
filter_id: str, |
957
|
|
|
*, |
958
|
|
|
comment: Optional[str] = None, |
959
|
|
|
name: Optional[str] = None, |
960
|
|
|
term: Optional[str] = None, |
961
|
|
|
filter_type: Optional[FilterType] = None, |
962
|
|
|
) -> Any: |
963
|
|
|
"""Modifies an existing filter. |
964
|
|
|
|
965
|
|
|
Arguments: |
966
|
|
|
filter_id: UUID of the filter to be modified |
967
|
|
|
comment: Comment on filter. |
968
|
|
|
name: Name of filter. |
969
|
|
|
term: Filter term. |
970
|
|
|
filter_type: Resource type filter applies to. |
971
|
|
|
|
972
|
|
|
Returns: |
973
|
|
|
The response. See :py:meth:`send_command` for details. |
974
|
|
|
""" |
975
|
|
|
if not filter_id: |
976
|
|
|
raise RequiredArgument( |
977
|
|
|
function=self.modify_filter.__name__, argument='filter_id' |
978
|
|
|
) |
979
|
|
|
|
980
|
|
|
cmd = XmlCommand("modify_filter") |
981
|
|
|
cmd.set_attribute("filter_id", filter_id) |
982
|
|
|
|
983
|
|
|
if comment: |
984
|
|
|
cmd.add_element("comment", comment) |
985
|
|
|
|
986
|
|
|
if name: |
987
|
|
|
cmd.add_element("name", name) |
988
|
|
|
|
989
|
|
|
if term: |
990
|
|
|
cmd.add_element("term", term) |
991
|
|
|
|
992
|
|
|
if filter_type: |
993
|
|
|
if not isinstance(filter_type, self.types.FilterType): |
994
|
|
|
raise InvalidArgumentType( |
995
|
|
|
function=self.modify_filter.__name__, |
996
|
|
|
argument='filter_type', |
997
|
|
|
arg_type=FilterType.__name__, |
998
|
|
|
) |
999
|
|
|
cmd.add_element("type", filter_type.value) |
1000
|
|
|
|
1001
|
|
|
return self._send_xml_command(cmd) |
1002
|
|
|
|
1003
|
|
|
def create_schedule( |
1004
|
|
|
self, |
1005
|
|
|
name: str, |
1006
|
|
|
icalendar: str, |
1007
|
|
|
timezone: str, |
1008
|
|
|
*, |
1009
|
|
|
comment: Optional[str] = None, |
1010
|
|
|
) -> Any: |
1011
|
|
|
"""Create a new schedule based in `iCalendar`_ data. |
1012
|
|
|
|
1013
|
|
|
Example: |
1014
|
|
|
Requires https://pypi.org/project/icalendar/ |
1015
|
|
|
|
1016
|
|
|
.. code-block:: python |
1017
|
|
|
|
1018
|
|
|
import pytz |
1019
|
|
|
|
1020
|
|
|
from datetime import datetime |
1021
|
|
|
|
1022
|
|
|
from icalendar import Calendar, Event |
1023
|
|
|
|
1024
|
|
|
cal = Calendar() |
1025
|
|
|
|
1026
|
|
|
cal.add('prodid', '-//Foo Bar//') |
1027
|
|
|
cal.add('version', '2.0') |
1028
|
|
|
|
1029
|
|
|
event = Event() |
1030
|
|
|
event.add('dtstamp', datetime.now(tz=pytz.UTC)) |
1031
|
|
|
event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc)) |
1032
|
|
|
|
1033
|
|
|
cal.add_component(event) |
1034
|
|
|
|
1035
|
|
|
gmp.create_schedule( |
1036
|
|
|
name="My Schedule", |
1037
|
|
|
icalendar=cal.to_ical(), |
1038
|
|
|
timezone='UTC' |
1039
|
|
|
) |
1040
|
|
|
|
1041
|
|
|
|
1042
|
|
|
Arguments: |
1043
|
|
|
name: Name of the new schedule |
1044
|
|
|
icalendar: `iCalendar`_ (RFC 5545) based data. |
1045
|
|
|
timezone: Timezone to use for the icalender events e.g |
1046
|
|
|
Europe/Berlin. If the datetime values in the icalendar data are |
1047
|
|
|
missing timezone information this timezone gets applied. |
1048
|
|
|
Otherwise the datetime values from the icalendar data are |
1049
|
|
|
displayed in this timezone |
1050
|
|
|
comment: Comment on schedule. |
1051
|
|
|
|
1052
|
|
|
Returns: |
1053
|
|
|
The response. See :py:meth:`send_command` for details. |
1054
|
|
|
|
1055
|
|
|
.. _iCalendar: |
1056
|
|
|
https://tools.ietf.org/html/rfc5545 |
1057
|
|
|
""" |
1058
|
|
|
if not name: |
1059
|
|
|
raise RequiredArgument( |
1060
|
|
|
function=self.create_schedule.__name__, argument='name' |
1061
|
|
|
) |
1062
|
|
|
if not icalendar: |
1063
|
|
|
raise RequiredArgument( |
1064
|
|
|
function=self.create_schedule.__name__, argument='icalendar' |
1065
|
|
|
) |
1066
|
|
|
if not timezone: |
1067
|
|
|
raise RequiredArgument( |
1068
|
|
|
function=self.create_schedule.__name__, argument='timezone' |
1069
|
|
|
) |
1070
|
|
|
|
1071
|
|
|
cmd = XmlCommand("create_schedule") |
1072
|
|
|
|
1073
|
|
|
cmd.add_element("name", name) |
1074
|
|
|
cmd.add_element("icalendar", icalendar) |
1075
|
|
|
cmd.add_element("timezone", timezone) |
1076
|
|
|
|
1077
|
|
|
if comment: |
1078
|
|
|
cmd.add_element("comment", comment) |
1079
|
|
|
|
1080
|
|
|
return self._send_xml_command(cmd) |
1081
|
|
|
|
1082
|
|
|
def modify_schedule( |
1083
|
|
|
self, |
1084
|
|
|
schedule_id: str, |
1085
|
|
|
*, |
1086
|
|
|
name: Optional[str] = None, |
1087
|
|
|
icalendar: Optional[str] = None, |
1088
|
|
|
timezone: Optional[str] = None, |
1089
|
|
|
comment: Optional[str] = None, |
1090
|
|
|
) -> Any: |
1091
|
|
|
"""Modifies an existing schedule |
1092
|
|
|
|
1093
|
|
|
Arguments: |
1094
|
|
|
schedule_id: UUID of the schedule to be modified |
1095
|
|
|
name: Name of the schedule |
1096
|
|
|
icalendar: `iCalendar`_ (RFC 5545) based data. |
1097
|
|
|
timezone: Timezone to use for the icalender events e.g |
1098
|
|
|
Europe/Berlin. If the datetime values in the icalendar data are |
1099
|
|
|
missing timezone information this timezone gets applied. |
1100
|
|
|
Otherwise the datetime values from the icalendar data are |
1101
|
|
|
displayed in this timezone |
1102
|
|
|
commenhedule. |
1103
|
|
|
|
1104
|
|
|
Returns: |
1105
|
|
|
The response. See :py:meth:`send_command` for details. |
1106
|
|
|
|
1107
|
|
|
.. _iCalendar: |
1108
|
|
|
https://tools.ietf.org/html/rfc5545 |
1109
|
|
|
""" |
1110
|
|
|
if not schedule_id: |
1111
|
|
|
raise RequiredArgument( |
1112
|
|
|
function=self.modify_schedule.__name__, argument='schedule_id' |
1113
|
|
|
) |
1114
|
|
|
|
1115
|
|
|
cmd = XmlCommand("modify_schedule") |
1116
|
|
|
cmd.set_attribute("schedule_id", schedule_id) |
1117
|
|
|
|
1118
|
|
|
if name: |
1119
|
|
|
cmd.add_element("name", name) |
1120
|
|
|
|
1121
|
|
|
if icalendar: |
1122
|
|
|
cmd.add_element("icalendar", icalendar) |
1123
|
|
|
|
1124
|
|
|
if timezone: |
1125
|
|
|
cmd.add_element("timezone", timezone) |
1126
|
|
|
|
1127
|
|
|
if comment: |
1128
|
|
|
cmd.add_element("comment", comment) |
1129
|
|
|
|
1130
|
|
|
return self._send_xml_command(cmd) |
1131
|
|
|
|
1132
|
|
|
def clone_filter(self, filter_id: str) -> Any: |
1133
|
|
|
"""Clone an existing filter |
1134
|
|
|
|
1135
|
|
|
Arguments: |
1136
|
|
|
filter_id: UUID of an existing filter to clone from |
1137
|
|
|
|
1138
|
|
|
Returns: |
1139
|
|
|
The response. See :py:meth:`send_command` for details. |
1140
|
|
|
""" |
1141
|
|
|
if not filter_id: |
1142
|
|
|
raise RequiredArgument( |
1143
|
|
|
function=self.clone_filter.__name__, argument='filter_id' |
1144
|
|
|
) |
1145
|
|
|
|
1146
|
|
|
cmd = XmlCommand("create_filter") |
1147
|
|
|
cmd.add_element("copy", filter_id) |
1148
|
|
|
return self._send_xml_command(cmd) |
1149
|
|
|
|
1150
|
|
|
def create_group( |
1151
|
|
|
self, |
1152
|
|
|
name: str, |
1153
|
|
|
*, |
1154
|
|
|
comment: Optional[str] = None, |
1155
|
|
|
special: Optional[bool] = False, |
1156
|
|
|
users: Optional[List[str]] = None, |
1157
|
|
|
) -> Any: |
1158
|
|
|
"""Create a new group |
1159
|
|
|
|
1160
|
|
|
Arguments: |
1161
|
|
|
name: Name of the new group |
1162
|
|
|
comment: Comment for the group |
1163
|
|
|
special: Create permission giving members full access to each |
1164
|
|
|
other's entities |
1165
|
|
|
users: List of user names to be in the group |
1166
|
|
|
|
1167
|
|
|
Returns: |
1168
|
|
|
The response. See :py:meth:`send_command` for details. |
1169
|
|
|
""" |
1170
|
|
|
if not name: |
1171
|
|
|
raise RequiredArgument( |
1172
|
|
|
function=self.create_group.__name__, argument='name' |
1173
|
|
|
) |
1174
|
|
|
|
1175
|
|
|
cmd = XmlCommand("create_group") |
1176
|
|
|
cmd.add_element("name", name) |
1177
|
|
|
|
1178
|
|
|
if comment: |
1179
|
|
|
cmd.add_element("comment", comment) |
1180
|
|
|
|
1181
|
|
|
if special: |
1182
|
|
|
_xmlspecial = cmd.add_element("specials") |
1183
|
|
|
_xmlspecial.add_element("full") |
1184
|
|
|
|
1185
|
|
|
if users: |
1186
|
|
|
cmd.add_element("users", to_comma_list(users)) |
1187
|
|
|
|
1188
|
|
|
return self._send_xml_command(cmd) |
1189
|
|
|
|
1190
|
|
|
def clone_group(self, group_id: str) -> Any: |
1191
|
|
|
"""Clone an existing group |
1192
|
|
|
|
1193
|
|
|
Arguments: |
1194
|
|
|
group_id: UUID of an existing group to clone from |
1195
|
|
|
|
1196
|
|
|
Returns: |
1197
|
|
|
The response. See :py:meth:`send_command` for details. |
1198
|
|
|
""" |
1199
|
|
|
if not group_id: |
1200
|
|
|
raise RequiredArgument( |
1201
|
|
|
function=self.clone_group.__name__, argument='group_id' |
1202
|
|
|
) |
1203
|
|
|
|
1204
|
|
|
cmd = XmlCommand("create_group") |
1205
|
|
|
cmd.add_element("copy", group_id) |
1206
|
|
|
return self._send_xml_command(cmd) |
1207
|
|
|
|
1208
|
|
|
def clone_permission(self, permission_id: str) -> Any: |
1209
|
|
|
"""Clone an existing permission |
1210
|
|
|
|
1211
|
|
|
Arguments: |
1212
|
|
|
permission_id: UUID of an existing permission to clone from |
1213
|
|
|
|
1214
|
|
|
Returns: |
1215
|
|
|
The response. See :py:meth:`send_command` for details. |
1216
|
|
|
""" |
1217
|
|
|
if not permission_id: |
1218
|
|
|
raise RequiredArgument( |
1219
|
|
|
function=self.clone_permission.__name__, |
1220
|
|
|
argument='permission_id', |
1221
|
|
|
) |
1222
|
|
|
|
1223
|
|
|
cmd = XmlCommand("create_permission") |
1224
|
|
|
cmd.add_element("copy", permission_id) |
1225
|
|
|
return self._send_xml_command(cmd) |
1226
|
|
|
|
1227
|
|
|
def clone_report_format( |
1228
|
|
|
self, report_format_id: [Union[str, ReportFormatType]] |
1229
|
|
|
) -> Any: |
1230
|
|
|
"""Clone a report format from an existing one |
1231
|
|
|
|
1232
|
|
|
Arguments: |
1233
|
|
|
report_format_id: UUID of the existing report format |
1234
|
|
|
or ReportFormatType (enum) |
1235
|
|
|
|
1236
|
|
|
Returns: |
1237
|
|
|
The response. See :py:meth:`send_command` for details. |
1238
|
|
|
""" |
1239
|
|
|
if not report_format_id: |
1240
|
|
|
raise RequiredArgument( |
1241
|
|
|
function=self.clone_report_format.__name__, |
1242
|
|
|
argument='report_format_id', |
1243
|
|
|
) |
1244
|
|
|
|
1245
|
|
|
cmd = XmlCommand("create_report_format") |
1246
|
|
|
|
1247
|
|
|
if isinstance(report_format_id, ReportFormatType): |
1248
|
|
|
report_format_id = report_format_id.value |
1249
|
|
|
|
1250
|
|
|
cmd.add_element("copy", report_format_id) |
1251
|
|
|
return self._send_xml_command(cmd) |
1252
|
|
|
|
1253
|
|
|
def import_report_format(self, report_format: str) -> Any: |
1254
|
|
|
"""Import a report format from XML |
1255
|
|
|
|
1256
|
|
|
Arguments: |
1257
|
|
|
report_format: Report format XML as string to import. This XML must |
1258
|
|
|
contain a :code:`<get_report_formats_response>` root element. |
1259
|
|
|
|
1260
|
|
|
Returns: |
1261
|
|
|
The response. See :py:meth:`send_command` for details. |
1262
|
|
|
""" |
1263
|
|
|
if not report_format: |
1264
|
|
|
raise RequiredArgument( |
1265
|
|
|
function=self.import_report_format.__name__, |
1266
|
|
|
argument='report_format', |
1267
|
|
|
) |
1268
|
|
|
|
1269
|
|
|
cmd = XmlCommand("create_report_format") |
1270
|
|
|
|
1271
|
|
|
try: |
1272
|
|
|
cmd.append_xml_str(report_format) |
1273
|
|
|
except etree.XMLSyntaxError as e: |
1274
|
|
|
raise InvalidArgument( |
1275
|
|
|
function=self.import_report_format.__name__, |
1276
|
|
|
argument='report_format', |
1277
|
|
|
) from e |
1278
|
|
|
|
1279
|
|
|
return self._send_xml_command(cmd) |
1280
|
|
|
|
1281
|
|
|
def create_role( |
1282
|
|
|
self, |
1283
|
|
|
name: str, |
1284
|
|
|
*, |
1285
|
|
|
comment: Optional[str] = None, |
1286
|
|
|
users: Optional[List[str]] = None, |
1287
|
|
|
) -> Any: |
1288
|
|
|
"""Create a new role |
1289
|
|
|
|
1290
|
|
|
Arguments: |
1291
|
|
|
name: Name of the role |
1292
|
|
|
comment: Comment for the role |
1293
|
|
|
users: List of user names to add to the role |
1294
|
|
|
|
1295
|
|
|
Returns: |
1296
|
|
|
The response. See :py:meth:`send_command` for details. |
1297
|
|
|
""" |
1298
|
|
|
|
1299
|
|
|
if not name: |
1300
|
|
|
raise RequiredArgument( |
1301
|
|
|
function=self.create_role.__name__, argument='name' |
1302
|
|
|
) |
1303
|
|
|
|
1304
|
|
|
cmd = XmlCommand("create_role") |
1305
|
|
|
cmd.add_element("name", name) |
1306
|
|
|
|
1307
|
|
|
if comment: |
1308
|
|
|
cmd.add_element("comment", comment) |
1309
|
|
|
|
1310
|
|
|
if users: |
1311
|
|
|
cmd.add_element("users", to_comma_list(users)) |
1312
|
|
|
|
1313
|
|
|
return self._send_xml_command(cmd) |
1314
|
|
|
|
1315
|
|
|
def clone_role(self, role_id: str) -> Any: |
1316
|
|
|
"""Clone an existing role |
1317
|
|
|
|
1318
|
|
|
Arguments: |
1319
|
|
|
role_id: UUID of an existing role to clone from |
1320
|
|
|
|
1321
|
|
|
Returns: |
1322
|
|
|
The response. See :py:meth:`send_command` for details. |
1323
|
|
|
""" |
1324
|
|
|
if not role_id: |
1325
|
|
|
raise RequiredArgument( |
1326
|
|
|
function=self.clone_role.__name__, argument='role_id' |
1327
|
|
|
) |
1328
|
|
|
|
1329
|
|
|
cmd = XmlCommand("create_role") |
1330
|
|
|
cmd.add_element("copy", role_id) |
1331
|
|
|
return self._send_xml_command(cmd) |
1332
|
|
|
|
1333
|
|
|
def clone_schedule(self, schedule_id: str) -> Any: |
1334
|
|
|
"""Clone an existing schedule |
1335
|
|
|
|
1336
|
|
|
Arguments: |
1337
|
|
|
schedule_id: UUID of an existing schedule to clone from |
1338
|
|
|
|
1339
|
|
|
Returns: |
1340
|
|
|
The response. See :py:meth:`send_command` for details. |
1341
|
|
|
""" |
1342
|
|
|
if not schedule_id: |
1343
|
|
|
raise RequiredArgument( |
1344
|
|
|
function=self.clone_schedule.__name__, argument='schedule_id' |
1345
|
|
|
) |
1346
|
|
|
|
1347
|
|
|
cmd = XmlCommand("create_schedule") |
1348
|
|
|
cmd.add_element("copy", schedule_id) |
1349
|
|
|
return self._send_xml_command(cmd) |
1350
|
|
|
|
1351
|
|
|
def clone_tag(self, tag_id: str) -> Any: |
1352
|
|
|
"""Clone an existing tag |
1353
|
|
|
|
1354
|
|
|
Arguments: |
1355
|
|
|
tag_id: UUID of an existing tag to clone from |
1356
|
|
|
|
1357
|
|
|
Returns: |
1358
|
|
|
The response. See :py:meth:`send_command` for details. |
1359
|
|
|
""" |
1360
|
|
|
if not tag_id: |
1361
|
|
|
raise RequiredArgument( |
1362
|
|
|
function=self.clone_tag.__name__, argument='tag_id' |
1363
|
|
|
) |
1364
|
|
|
|
1365
|
|
|
cmd = XmlCommand("create_tag") |
1366
|
|
|
cmd.add_element("copy", tag_id) |
1367
|
|
|
return self._send_xml_command(cmd) |
1368
|
|
|
|
1369
|
|
|
def create_user( |
1370
|
|
|
self, |
1371
|
|
|
name: str, |
1372
|
|
|
*, |
1373
|
|
|
password: Optional[str] = None, |
1374
|
|
|
hosts: Optional[List[str]] = None, |
1375
|
|
|
hosts_allow: Optional[bool] = False, |
1376
|
|
|
ifaces: Optional[List[str]] = None, |
1377
|
|
|
ifaces_allow: Optional[bool] = False, |
1378
|
|
|
role_ids: Optional[List[str]] = None, |
1379
|
|
|
) -> Any: |
1380
|
|
|
"""Create a new user |
1381
|
|
|
|
1382
|
|
|
Arguments: |
1383
|
|
|
name: Name of the user |
1384
|
|
|
password: Password of the user |
1385
|
|
|
hosts: A list of host addresses (IPs, DNS names) |
1386
|
|
|
hosts_allow: If True allow only access to passed hosts otherwise |
1387
|
|
|
deny access. Default is False for deny hosts. |
1388
|
|
|
ifaces: A list of interface names |
1389
|
|
|
ifaces_allow: If True allow only access to passed interfaces |
1390
|
|
|
otherwise deny access. Default is False for deny interfaces. |
1391
|
|
|
role_ids: A list of role UUIDs for the user |
1392
|
|
|
|
1393
|
|
|
Returns: |
1394
|
|
|
The response. See :py:meth:`send_command` for details. |
1395
|
|
|
""" |
1396
|
|
|
if not name: |
1397
|
|
|
raise RequiredArgument( |
1398
|
|
|
function=self.create_user.__name__, argument='name' |
1399
|
|
|
) |
1400
|
|
|
|
1401
|
|
|
cmd = XmlCommand("create_user") |
1402
|
|
|
cmd.add_element("name", name) |
1403
|
|
|
|
1404
|
|
|
if password: |
1405
|
|
|
cmd.add_element("password", password) |
1406
|
|
|
|
1407
|
|
|
if hosts: |
1408
|
|
|
cmd.add_element( |
1409
|
|
|
"hosts", |
1410
|
|
|
to_comma_list(hosts), |
1411
|
|
|
attrs={"allow": to_bool(hosts_allow)}, |
1412
|
|
|
) |
1413
|
|
|
|
1414
|
|
|
if ifaces: |
1415
|
|
|
cmd.add_element( |
1416
|
|
|
"ifaces", |
1417
|
|
|
to_comma_list(ifaces), |
1418
|
|
|
attrs={"allow": to_bool(ifaces_allow)}, |
1419
|
|
|
) |
1420
|
|
|
|
1421
|
|
|
if role_ids: |
1422
|
|
|
for role in role_ids: |
1423
|
|
|
cmd.add_element("role", attrs={"id": role}) |
1424
|
|
|
|
1425
|
|
|
return self._send_xml_command(cmd) |
1426
|
|
|
|
1427
|
|
|
def clone_user(self, user_id: str) -> Any: |
1428
|
|
|
"""Clone an existing user |
1429
|
|
|
|
1430
|
|
|
Arguments: |
1431
|
|
|
user_id: UUID of existing user to clone from |
1432
|
|
|
|
1433
|
|
|
Returns: |
1434
|
|
|
The response. See :py:meth:`send_command` for details. |
1435
|
|
|
""" |
1436
|
|
|
if not user_id: |
1437
|
|
|
raise RequiredArgument( |
1438
|
|
|
function=self.clone_user.__name__, argument='user_id' |
1439
|
|
|
) |
1440
|
|
|
|
1441
|
|
|
cmd = XmlCommand("create_user") |
1442
|
|
|
cmd.add_element("copy", user_id) |
1443
|
|
|
return self._send_xml_command(cmd) |
1444
|
|
|
|
1445
|
|
|
def delete_filter( |
1446
|
|
|
self, filter_id: str, *, ultimate: Optional[bool] = False |
1447
|
|
|
) -> Any: |
1448
|
|
|
"""Deletes an existing filter |
1449
|
|
|
|
1450
|
|
|
Arguments: |
1451
|
|
|
filter_id: UUID of the filter to be deleted. |
1452
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1453
|
|
|
""" |
1454
|
|
|
if not filter_id: |
1455
|
|
|
raise RequiredArgument( |
1456
|
|
|
function=self.delete_filter.__name__, argument='filter_id' |
1457
|
|
|
) |
1458
|
|
|
|
1459
|
|
|
cmd = XmlCommand("delete_filter") |
1460
|
|
|
cmd.set_attribute("filter_id", filter_id) |
1461
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1462
|
|
|
|
1463
|
|
|
return self._send_xml_command(cmd) |
1464
|
|
|
|
1465
|
|
|
def delete_group( |
1466
|
|
|
self, group_id: str, *, ultimate: Optional[bool] = False |
1467
|
|
|
) -> Any: |
1468
|
|
|
"""Deletes an existing group |
1469
|
|
|
|
1470
|
|
|
Arguments: |
1471
|
|
|
group_id: UUID of the group to be deleted. |
1472
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1473
|
|
|
""" |
1474
|
|
|
if not group_id: |
1475
|
|
|
raise RequiredArgument( |
1476
|
|
|
function=self.delete_group.__name__, argument='group_id' |
1477
|
|
|
) |
1478
|
|
|
|
1479
|
|
|
cmd = XmlCommand("delete_group") |
1480
|
|
|
cmd.set_attribute("group_id", group_id) |
1481
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1482
|
|
|
|
1483
|
|
|
return self._send_xml_command(cmd) |
1484
|
|
|
|
1485
|
|
|
def delete_permission( |
1486
|
|
|
self, permission_id: str, *, ultimate: Optional[bool] = False |
1487
|
|
|
) -> Any: |
1488
|
|
|
"""Deletes an existing permission |
1489
|
|
|
|
1490
|
|
|
Arguments: |
1491
|
|
|
permission_id: UUID of the permission to be deleted. |
1492
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1493
|
|
|
""" |
1494
|
|
|
if not permission_id: |
1495
|
|
|
raise RequiredArgument( |
1496
|
|
|
function=self.delete_permission.__name__, |
1497
|
|
|
argument='permission_id', |
1498
|
|
|
) |
1499
|
|
|
|
1500
|
|
|
cmd = XmlCommand("delete_permission") |
1501
|
|
|
cmd.set_attribute("permission_id", permission_id) |
1502
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1503
|
|
|
|
1504
|
|
|
return self._send_xml_command(cmd) |
1505
|
|
|
|
1506
|
|
|
def delete_report_format( |
1507
|
|
|
self, |
1508
|
|
|
report_format_id: Optional[Union[str, ReportFormatType]] = None, |
1509
|
|
|
*, |
1510
|
|
|
ultimate: Optional[bool] = False, |
1511
|
|
|
) -> Any: |
1512
|
|
|
"""Deletes an existing report format |
1513
|
|
|
|
1514
|
|
|
Arguments: |
1515
|
|
|
report_format_id: UUID of the report format to be deleted. |
1516
|
|
|
or ReportFormatType (enum) |
1517
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1518
|
|
|
""" |
1519
|
|
|
if not report_format_id: |
1520
|
|
|
raise RequiredArgument( |
1521
|
|
|
function=self.delete_report_format.__name__, |
1522
|
|
|
argument='report_format_id', |
1523
|
|
|
) |
1524
|
|
|
|
1525
|
|
|
cmd = XmlCommand("delete_report_format") |
1526
|
|
|
|
1527
|
|
|
if isinstance(report_format_id, ReportFormatType): |
1528
|
|
|
report_format_id = report_format_id.value |
1529
|
|
|
|
1530
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
1531
|
|
|
|
1532
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1533
|
|
|
|
1534
|
|
|
return self._send_xml_command(cmd) |
1535
|
|
|
|
1536
|
|
|
def delete_role( |
1537
|
|
|
self, role_id: str, *, ultimate: Optional[bool] = False |
1538
|
|
|
) -> Any: |
1539
|
|
|
"""Deletes an existing role |
1540
|
|
|
|
1541
|
|
|
Arguments: |
1542
|
|
|
role_id: UUID of the role to be deleted. |
1543
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1544
|
|
|
""" |
1545
|
|
|
if not role_id: |
1546
|
|
|
raise RequiredArgument( |
1547
|
|
|
function=self.delete_role.__name__, argument='role_id' |
1548
|
|
|
) |
1549
|
|
|
|
1550
|
|
|
cmd = XmlCommand("delete_role") |
1551
|
|
|
cmd.set_attribute("role_id", role_id) |
1552
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1553
|
|
|
|
1554
|
|
|
return self._send_xml_command(cmd) |
1555
|
|
|
|
1556
|
|
|
def delete_schedule( |
1557
|
|
|
self, schedule_id: str, *, ultimate: Optional[bool] = False |
1558
|
|
|
) -> Any: |
1559
|
|
|
"""Deletes an existing schedule |
1560
|
|
|
|
1561
|
|
|
Arguments: |
1562
|
|
|
schedule_id: UUID of the schedule to be deleted. |
1563
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1564
|
|
|
""" |
1565
|
|
|
if not schedule_id: |
1566
|
|
|
raise RequiredArgument( |
1567
|
|
|
function=self.delete_schedule.__name__, argument='schedule_id' |
1568
|
|
|
) |
1569
|
|
|
|
1570
|
|
|
cmd = XmlCommand("delete_schedule") |
1571
|
|
|
cmd.set_attribute("schedule_id", schedule_id) |
1572
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1573
|
|
|
|
1574
|
|
|
return self._send_xml_command(cmd) |
1575
|
|
|
|
1576
|
|
|
def delete_tag( |
1577
|
|
|
self, tag_id: str, *, ultimate: Optional[bool] = False |
1578
|
|
|
) -> Any: |
1579
|
|
|
"""Deletes an existing tag |
1580
|
|
|
|
1581
|
|
|
Arguments: |
1582
|
|
|
tag_id: UUID of the tag to be deleted. |
1583
|
|
|
ultimate: Whether to remove entirely, or to the trashcan. |
1584
|
|
|
""" |
1585
|
|
|
if not tag_id: |
1586
|
|
|
raise RequiredArgument( |
1587
|
|
|
function=self.delete_tag.__name__, argument='tag_id' |
1588
|
|
|
) |
1589
|
|
|
|
1590
|
|
|
cmd = XmlCommand("delete_tag") |
1591
|
|
|
cmd.set_attribute("tag_id", tag_id) |
1592
|
|
|
cmd.set_attribute("ultimate", to_bool(ultimate)) |
1593
|
|
|
|
1594
|
|
|
return self._send_xml_command(cmd) |
1595
|
|
|
|
1596
|
|
|
def delete_user( |
1597
|
|
|
self, |
1598
|
|
|
user_id: str = None, |
1599
|
|
|
*, |
1600
|
|
|
name: Optional[str] = None, |
1601
|
|
|
inheritor_id: Optional[str] = None, |
1602
|
|
|
inheritor_name: Optional[str] = None, |
1603
|
|
|
) -> Any: |
1604
|
|
|
"""Deletes an existing user |
1605
|
|
|
|
1606
|
|
|
Either user_id or name must be passed. |
1607
|
|
|
|
1608
|
|
|
Arguments: |
1609
|
|
|
user_id: UUID of the task to be deleted. |
1610
|
|
|
name: The name of the user to be deleted. |
1611
|
|
|
inheritor_id: The ID of the inheriting user or "self". Overrides |
1612
|
|
|
inheritor_name. |
1613
|
|
|
inheritor_name: The name of the inheriting user. |
1614
|
|
|
|
1615
|
|
|
""" |
1616
|
|
|
if not user_id and not name: |
1617
|
|
|
raise RequiredArgument( |
1618
|
|
|
function=self.delete_user.__name__, argument='user_id or name' |
1619
|
|
|
) |
1620
|
|
|
|
1621
|
|
|
cmd = XmlCommand("delete_user") |
1622
|
|
|
|
1623
|
|
|
if user_id: |
1624
|
|
|
cmd.set_attribute("user_id", user_id) |
1625
|
|
|
|
1626
|
|
|
if name: |
1627
|
|
|
cmd.set_attribute("name", name) |
1628
|
|
|
|
1629
|
|
|
if inheritor_id: |
1630
|
|
|
cmd.set_attribute("inheritor_id", inheritor_id) |
1631
|
|
|
if inheritor_name: |
1632
|
|
|
cmd.set_attribute("inheritor_name", inheritor_name) |
1633
|
|
|
|
1634
|
|
|
return self._send_xml_command(cmd) |
1635
|
|
|
|
1636
|
|
|
def describe_auth(self) -> Any: |
1637
|
|
|
"""Describe authentication methods |
1638
|
|
|
|
1639
|
|
|
Returns a list of all used authentication methods if such a list is |
1640
|
|
|
available. |
1641
|
|
|
|
1642
|
|
|
Returns: |
1643
|
|
|
The response. See :py:meth:`send_command` for details. |
1644
|
|
|
""" |
1645
|
|
|
return self._send_xml_command(XmlCommand("describe_auth")) |
1646
|
|
|
|
1647
|
|
|
def empty_trashcan(self) -> Any: |
1648
|
|
|
"""Empty the trashcan |
1649
|
|
|
|
1650
|
|
|
Remove all entities from the trashcan. **Attention:** this command can |
1651
|
|
|
not be reverted |
1652
|
|
|
|
1653
|
|
|
Returns: |
1654
|
|
|
The response. See :py:meth:`send_command` for details. |
1655
|
|
|
""" |
1656
|
|
|
return self._send_xml_command(XmlCommand("empty_trashcan")) |
1657
|
|
|
|
1658
|
|
|
def get_feeds(self) -> Any: |
1659
|
|
|
"""Request the list of feeds |
1660
|
|
|
|
1661
|
|
|
Returns: |
1662
|
|
|
The response. See :py:meth:`send_command` for details. |
1663
|
|
|
""" |
1664
|
|
|
return self._send_xml_command(XmlCommand("get_feeds")) |
1665
|
|
|
|
1666
|
|
View Code Duplication |
def get_filters( |
|
|
|
|
1667
|
|
|
self, |
1668
|
|
|
*, |
1669
|
|
|
filter: Optional[str] = None, |
1670
|
|
|
filter_id: Optional[str] = None, |
1671
|
|
|
trash: Optional[bool] = None, |
1672
|
|
|
alerts: Optional[bool] = None, |
1673
|
|
|
) -> Any: |
1674
|
|
|
"""Request a list of filters |
1675
|
|
|
|
1676
|
|
|
Arguments: |
1677
|
|
|
filter: Filter term to use for the query |
1678
|
|
|
filter_id: UUID of an existing filter to use for the query |
1679
|
|
|
trash: Whether to get the trashcan filters instead |
1680
|
|
|
alerts: Whether to include list of alerts that use the filter. |
1681
|
|
|
|
1682
|
|
|
Returns: |
1683
|
|
|
The response. See :py:meth:`send_command` for details. |
1684
|
|
|
""" |
1685
|
|
|
cmd = XmlCommand("get_filters") |
1686
|
|
|
|
1687
|
|
|
add_filter(cmd, filter, filter_id) |
1688
|
|
|
|
1689
|
|
|
if trash is not None: |
1690
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1691
|
|
|
|
1692
|
|
|
if alerts is not None: |
1693
|
|
|
cmd.set_attribute("alerts", to_bool(alerts)) |
1694
|
|
|
|
1695
|
|
|
return self._send_xml_command(cmd) |
1696
|
|
|
|
1697
|
|
|
def get_filter( |
1698
|
|
|
self, filter_id: str, *, alerts: Optional[bool] = None |
1699
|
|
|
) -> Any: |
1700
|
|
|
"""Request a single filter |
1701
|
|
|
|
1702
|
|
|
Arguments: |
1703
|
|
|
filter_id: UUID of an existing filter |
1704
|
|
|
alerts: Whether to include list of alerts that use the filter. |
1705
|
|
|
|
1706
|
|
|
Returns: |
1707
|
|
|
The response. See :py:meth:`send_command` for details. |
1708
|
|
|
""" |
1709
|
|
|
cmd = XmlCommand("get_filters") |
1710
|
|
|
|
1711
|
|
|
if not filter_id: |
1712
|
|
|
raise RequiredArgument( |
1713
|
|
|
function=self.get_filter.__name__, argument='filter_id' |
1714
|
|
|
) |
1715
|
|
|
|
1716
|
|
|
cmd.set_attribute("filter_id", filter_id) |
1717
|
|
|
|
1718
|
|
|
if alerts is not None: |
1719
|
|
|
cmd.set_attribute("alerts", to_bool(alerts)) |
1720
|
|
|
|
1721
|
|
|
return self._send_xml_command(cmd) |
1722
|
|
|
|
1723
|
|
View Code Duplication |
def get_groups( |
|
|
|
|
1724
|
|
|
self, |
1725
|
|
|
*, |
1726
|
|
|
filter: Optional[str] = None, |
1727
|
|
|
filter_id: Optional[str] = None, |
1728
|
|
|
trash: Optional[bool] = None, |
1729
|
|
|
) -> Any: |
1730
|
|
|
"""Request a list of groups |
1731
|
|
|
|
1732
|
|
|
Arguments: |
1733
|
|
|
filter: Filter term to use for the query |
1734
|
|
|
filter_id: UUID of an existing filter to use for the query |
1735
|
|
|
trash: Whether to get the trashcan groups instead |
1736
|
|
|
|
1737
|
|
|
Returns: |
1738
|
|
|
The response. See :py:meth:`send_command` for details. |
1739
|
|
|
""" |
1740
|
|
|
cmd = XmlCommand("get_groups") |
1741
|
|
|
|
1742
|
|
|
add_filter(cmd, filter, filter_id) |
1743
|
|
|
|
1744
|
|
|
if trash is not None: |
1745
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1746
|
|
|
|
1747
|
|
|
return self._send_xml_command(cmd) |
1748
|
|
|
|
1749
|
|
|
def get_group(self, group_id: str) -> Any: |
1750
|
|
|
"""Request a single group |
1751
|
|
|
|
1752
|
|
|
Arguments: |
1753
|
|
|
group_id: UUID of an existing group |
1754
|
|
|
|
1755
|
|
|
Returns: |
1756
|
|
|
The response. See :py:meth:`send_command` for details. |
1757
|
|
|
""" |
1758
|
|
|
cmd = XmlCommand("get_groups") |
1759
|
|
|
|
1760
|
|
|
if not group_id: |
1761
|
|
|
raise RequiredArgument( |
1762
|
|
|
function=self.get_group.__name__, argument='group_id' |
1763
|
|
|
) |
1764
|
|
|
|
1765
|
|
|
cmd.set_attribute("group_id", group_id) |
1766
|
|
|
return self._send_xml_command(cmd) |
1767
|
|
|
|
1768
|
|
View Code Duplication |
def get_permissions( |
|
|
|
|
1769
|
|
|
self, |
1770
|
|
|
*, |
1771
|
|
|
filter: Optional[str] = None, |
1772
|
|
|
filter_id: Optional[str] = None, |
1773
|
|
|
trash: Optional[bool] = None, |
1774
|
|
|
) -> Any: |
1775
|
|
|
"""Request a list of permissions |
1776
|
|
|
|
1777
|
|
|
Arguments: |
1778
|
|
|
filter: Filter term to use for the query |
1779
|
|
|
filter_id: UUID of an existing filter to use for the query |
1780
|
|
|
trash: Whether to get permissions in the trashcan instead |
1781
|
|
|
|
1782
|
|
|
Returns: |
1783
|
|
|
The response. See :py:meth:`send_command` for details. |
1784
|
|
|
""" |
1785
|
|
|
cmd = XmlCommand("get_permissions") |
1786
|
|
|
|
1787
|
|
|
add_filter(cmd, filter, filter_id) |
1788
|
|
|
|
1789
|
|
|
if trash is not None: |
1790
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1791
|
|
|
|
1792
|
|
|
return self._send_xml_command(cmd) |
1793
|
|
|
|
1794
|
|
|
def get_permission(self, permission_id: str) -> Any: |
1795
|
|
|
"""Request a single permission |
1796
|
|
|
|
1797
|
|
|
Arguments: |
1798
|
|
|
permission_id: UUID of an existing permission |
1799
|
|
|
|
1800
|
|
|
Returns: |
1801
|
|
|
The response. See :py:meth:`send_command` for details. |
1802
|
|
|
""" |
1803
|
|
|
cmd = XmlCommand("get_permissions") |
1804
|
|
|
|
1805
|
|
|
if not permission_id: |
1806
|
|
|
raise RequiredArgument( |
1807
|
|
|
function=self.get_permission.__name__, argument='permission_id' |
1808
|
|
|
) |
1809
|
|
|
|
1810
|
|
|
cmd.set_attribute("permission_id", permission_id) |
1811
|
|
|
return self._send_xml_command(cmd) |
1812
|
|
|
|
1813
|
|
|
def get_preferences( |
1814
|
|
|
self, *, nvt_oid: Optional[str] = None, config_id: Optional[str] = None |
1815
|
|
|
) -> Any: |
1816
|
|
|
"""Request a list of preferences |
1817
|
|
|
|
1818
|
|
|
When the command includes a config_id attribute, the preference element |
1819
|
|
|
includes the preference name, type and value, and the NVT to which the |
1820
|
|
|
preference applies. Otherwise, the preference element includes just the |
1821
|
|
|
name and value, with the NVT and type built into the name. |
1822
|
|
|
|
1823
|
|
|
Arguments: |
1824
|
|
|
nvt_oid: OID of nvt |
1825
|
|
|
config_id: UUID of scan config of which to show preference values |
1826
|
|
|
|
1827
|
|
|
Returns: |
1828
|
|
|
The response. See :py:meth:`send_command` for details. |
1829
|
|
|
""" |
1830
|
|
|
cmd = XmlCommand("get_preferences") |
1831
|
|
|
|
1832
|
|
|
if nvt_oid: |
1833
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
1834
|
|
|
|
1835
|
|
|
if config_id: |
1836
|
|
|
cmd.set_attribute("config_id", config_id) |
1837
|
|
|
|
1838
|
|
|
return self._send_xml_command(cmd) |
1839
|
|
|
|
1840
|
|
|
def get_preference( |
1841
|
|
|
self, |
1842
|
|
|
name: str, |
1843
|
|
|
*, |
1844
|
|
|
nvt_oid: Optional[str] = None, |
1845
|
|
|
config_id: Optional[str] = None, |
1846
|
|
|
) -> Any: |
1847
|
|
|
"""Request a nvt preference |
1848
|
|
|
|
1849
|
|
|
Arguments: |
1850
|
|
|
name: name of a particular preference |
1851
|
|
|
nvt_oid: OID of nvt |
1852
|
|
|
config_id: UUID of scan config of which to show preference values |
1853
|
|
|
|
1854
|
|
|
Returns: |
1855
|
|
|
The response. See :py:meth:`send_command` for details. |
1856
|
|
|
""" |
1857
|
|
|
cmd = XmlCommand("get_preferences") |
1858
|
|
|
|
1859
|
|
|
if not name: |
1860
|
|
|
raise RequiredArgument( |
1861
|
|
|
function=self.get_preference.__name__, argument='name' |
1862
|
|
|
) |
1863
|
|
|
|
1864
|
|
|
cmd.set_attribute("preference", name) |
1865
|
|
|
|
1866
|
|
|
if nvt_oid: |
1867
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
1868
|
|
|
|
1869
|
|
|
if config_id: |
1870
|
|
|
cmd.set_attribute("config_id", config_id) |
1871
|
|
|
|
1872
|
|
|
return self._send_xml_command(cmd) |
1873
|
|
|
|
1874
|
|
View Code Duplication |
def get_report_formats( |
|
|
|
|
1875
|
|
|
self, |
1876
|
|
|
*, |
1877
|
|
|
filter: Optional[str] = None, |
1878
|
|
|
filter_id: Optional[str] = None, |
1879
|
|
|
trash: Optional[bool] = None, |
1880
|
|
|
alerts: Optional[bool] = None, |
1881
|
|
|
params: Optional[bool] = None, |
1882
|
|
|
details: Optional[bool] = None, |
1883
|
|
|
) -> Any: |
1884
|
|
|
"""Request a list of report formats |
1885
|
|
|
|
1886
|
|
|
Arguments: |
1887
|
|
|
filter: Filter term to use for the query |
1888
|
|
|
filter_id: UUID of an existing filter to use for the query |
1889
|
|
|
trash: Whether to get the trashcan report formats instead |
1890
|
|
|
alerts: Whether to include alerts that use the report format |
1891
|
|
|
params: Whether to include report format parameters |
1892
|
|
|
details: Include report format file, signature and parameters |
1893
|
|
|
|
1894
|
|
|
Returns: |
1895
|
|
|
The response. See :py:meth:`send_command` for details. |
1896
|
|
|
""" |
1897
|
|
|
cmd = XmlCommand("get_report_formats") |
1898
|
|
|
|
1899
|
|
|
add_filter(cmd, filter, filter_id) |
1900
|
|
|
|
1901
|
|
|
if details is not None: |
1902
|
|
|
cmd.set_attribute("details", to_bool(details)) |
1903
|
|
|
|
1904
|
|
|
if alerts is not None: |
1905
|
|
|
cmd.set_attribute("alerts", to_bool(alerts)) |
1906
|
|
|
|
1907
|
|
|
if params is not None: |
1908
|
|
|
cmd.set_attribute("params", to_bool(params)) |
1909
|
|
|
|
1910
|
|
|
if trash is not None: |
1911
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1912
|
|
|
|
1913
|
|
|
return self._send_xml_command(cmd) |
1914
|
|
|
|
1915
|
|
View Code Duplication |
def get_report_format( |
|
|
|
|
1916
|
|
|
self, report_format_id: Union[str, ReportFormatType] |
1917
|
|
|
) -> Any: |
1918
|
|
|
"""Request a single report format |
1919
|
|
|
|
1920
|
|
|
Arguments: |
1921
|
|
|
report_format_id: UUID of an existing report format |
1922
|
|
|
or ReportFormatType (enum) |
1923
|
|
|
|
1924
|
|
|
Returns: |
1925
|
|
|
The response. See :py:meth:`send_command` for details. |
1926
|
|
|
""" |
1927
|
|
|
cmd = XmlCommand("get_report_formats") |
1928
|
|
|
|
1929
|
|
|
if not report_format_id: |
1930
|
|
|
raise RequiredArgument( |
1931
|
|
|
function=self.get_report_format.__name__, |
1932
|
|
|
argument='report_format_id', |
1933
|
|
|
) |
1934
|
|
|
|
1935
|
|
|
if isinstance(report_format_id, ReportFormatType): |
1936
|
|
|
report_format_id = report_format_id.value |
1937
|
|
|
|
1938
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
1939
|
|
|
|
1940
|
|
|
# for single entity always request all details |
1941
|
|
|
cmd.set_attribute("details", "1") |
1942
|
|
|
return self._send_xml_command(cmd) |
1943
|
|
|
|
1944
|
|
View Code Duplication |
def get_roles( |
|
|
|
|
1945
|
|
|
self, |
1946
|
|
|
*, |
1947
|
|
|
filter: Optional[str] = None, |
1948
|
|
|
filter_id: Optional[str] = None, |
1949
|
|
|
trash: Optional[bool] = None, |
1950
|
|
|
) -> Any: |
1951
|
|
|
"""Request a list of roles |
1952
|
|
|
|
1953
|
|
|
Arguments: |
1954
|
|
|
filter: Filter term to use for the query |
1955
|
|
|
filter_id: UUID of an existing filter to use for the query |
1956
|
|
|
trash: Whether to get the trashcan roles instead |
1957
|
|
|
|
1958
|
|
|
Returns: |
1959
|
|
|
The response. See :py:meth:`send_command` for details. |
1960
|
|
|
""" |
1961
|
|
|
cmd = XmlCommand("get_roles") |
1962
|
|
|
|
1963
|
|
|
add_filter(cmd, filter, filter_id) |
1964
|
|
|
|
1965
|
|
|
if trash is not None: |
1966
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
1967
|
|
|
|
1968
|
|
|
return self._send_xml_command(cmd) |
1969
|
|
|
|
1970
|
|
|
def get_role(self, role_id: str) -> Any: |
1971
|
|
|
"""Request a single role |
1972
|
|
|
|
1973
|
|
|
Arguments: |
1974
|
|
|
role_id: UUID of an existing role |
1975
|
|
|
|
1976
|
|
|
Returns: |
1977
|
|
|
The response. See :py:meth:`send_command` for details. |
1978
|
|
|
""" |
1979
|
|
|
if not role_id: |
1980
|
|
|
raise RequiredArgument( |
1981
|
|
|
function=self.get_role.__name__, argument='role_id' |
1982
|
|
|
) |
1983
|
|
|
|
1984
|
|
|
cmd = XmlCommand("get_roles") |
1985
|
|
|
cmd.set_attribute("role_id", role_id) |
1986
|
|
|
return self._send_xml_command(cmd) |
1987
|
|
|
|
1988
|
|
View Code Duplication |
def get_schedules( |
|
|
|
|
1989
|
|
|
self, |
1990
|
|
|
*, |
1991
|
|
|
filter: Optional[str] = None, |
1992
|
|
|
filter_id: Optional[str] = None, |
1993
|
|
|
trash: Optional[bool] = None, |
1994
|
|
|
tasks: Optional[bool] = None, |
1995
|
|
|
) -> Any: |
1996
|
|
|
"""Request a list of schedules |
1997
|
|
|
|
1998
|
|
|
Arguments: |
1999
|
|
|
filter: Filter term to use for the query |
2000
|
|
|
filter_id: UUID of an existing filter to use for the query |
2001
|
|
|
trash: Whether to get the trashcan schedules instead |
2002
|
|
|
tasks: Whether to include tasks using the schedules |
2003
|
|
|
|
2004
|
|
|
Returns: |
2005
|
|
|
The response. See :py:meth:`send_command` for details. |
2006
|
|
|
""" |
2007
|
|
|
cmd = XmlCommand("get_schedules") |
2008
|
|
|
|
2009
|
|
|
add_filter(cmd, filter, filter_id) |
2010
|
|
|
|
2011
|
|
|
if trash is not None: |
2012
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
2013
|
|
|
|
2014
|
|
|
if tasks is not None: |
2015
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
2016
|
|
|
|
2017
|
|
|
return self._send_xml_command(cmd) |
2018
|
|
|
|
2019
|
|
|
def get_schedule( |
2020
|
|
|
self, schedule_id: str, *, tasks: Optional[bool] = None |
2021
|
|
|
) -> Any: |
2022
|
|
|
"""Request a single schedule |
2023
|
|
|
|
2024
|
|
|
Arguments: |
2025
|
|
|
schedule_id: UUID of an existing schedule |
2026
|
|
|
tasks: Whether to include tasks using the schedules |
2027
|
|
|
|
2028
|
|
|
Returns: |
2029
|
|
|
The response. See :py:meth:`send_command` for details. |
2030
|
|
|
""" |
2031
|
|
|
cmd = XmlCommand("get_schedules") |
2032
|
|
|
|
2033
|
|
|
if not schedule_id: |
2034
|
|
|
raise RequiredArgument( |
2035
|
|
|
function=self.get_schedule.__name__, argument='schedule_id' |
2036
|
|
|
) |
2037
|
|
|
|
2038
|
|
|
cmd.set_attribute("schedule_id", schedule_id) |
2039
|
|
|
|
2040
|
|
|
if tasks is not None: |
2041
|
|
|
cmd.set_attribute("tasks", to_bool(tasks)) |
2042
|
|
|
|
2043
|
|
|
return self._send_xml_command(cmd) |
2044
|
|
|
|
2045
|
|
|
def get_settings(self, *, filter: Optional[str] = None) -> Any: |
2046
|
|
|
"""Request a list of user settings |
2047
|
|
|
|
2048
|
|
|
Arguments: |
2049
|
|
|
filter: Filter term to use for the query |
2050
|
|
|
|
2051
|
|
|
Returns: |
2052
|
|
|
The response. See :py:meth:`send_command` for details. |
2053
|
|
|
""" |
2054
|
|
|
cmd = XmlCommand("get_settings") |
2055
|
|
|
|
2056
|
|
|
if filter: |
2057
|
|
|
cmd.set_attribute("filter", filter) |
2058
|
|
|
|
2059
|
|
|
return self._send_xml_command(cmd) |
2060
|
|
|
|
2061
|
|
|
def get_setting(self, setting_id: str) -> Any: |
2062
|
|
|
"""Request a single setting |
2063
|
|
|
|
2064
|
|
|
Arguments: |
2065
|
|
|
setting_id: UUID of an existing setting |
2066
|
|
|
|
2067
|
|
|
Returns: |
2068
|
|
|
The response. See :py:meth:`send_command` for details. |
2069
|
|
|
""" |
2070
|
|
|
cmd = XmlCommand("get_settings") |
2071
|
|
|
|
2072
|
|
|
if not setting_id: |
2073
|
|
|
raise RequiredArgument( |
2074
|
|
|
function=self.get_setting.__name__, argument='setting_id' |
2075
|
|
|
) |
2076
|
|
|
|
2077
|
|
|
cmd.set_attribute("setting_id", setting_id) |
2078
|
|
|
return self._send_xml_command(cmd) |
2079
|
|
|
|
2080
|
|
|
def get_system_reports( |
2081
|
|
|
self, |
2082
|
|
|
*, |
2083
|
|
|
name: Optional[str] = None, |
2084
|
|
|
duration: Optional[int] = None, |
2085
|
|
|
start_time: Optional[str] = None, |
2086
|
|
|
end_time: Optional[str] = None, |
2087
|
|
|
brief: Optional[bool] = None, |
2088
|
|
|
slave_id: Optional[str] = None, |
2089
|
|
|
) -> Any: |
2090
|
|
|
"""Request a list of system reports |
2091
|
|
|
|
2092
|
|
|
Arguments: |
2093
|
|
|
name: A string describing the required system report |
2094
|
|
|
duration: The number of seconds into the past that the system report |
2095
|
|
|
should include |
2096
|
|
|
start_time: The start of the time interval the system report should |
2097
|
|
|
include in ISO time format |
2098
|
|
|
end_time: The end of the time interval the system report should |
2099
|
|
|
include in ISO time format |
2100
|
|
|
brief: Whether to include the actual system reports |
2101
|
|
|
slave_id: UUID of GMP scanner from which to get the system reports |
2102
|
|
|
|
2103
|
|
|
Returns: |
2104
|
|
|
The response. See :py:meth:`send_command` for details. |
2105
|
|
|
""" |
2106
|
|
|
cmd = XmlCommand("get_system_reports") |
2107
|
|
|
|
2108
|
|
|
if name: |
2109
|
|
|
cmd.set_attribute("name", name) |
2110
|
|
|
|
2111
|
|
|
if duration is not None: |
2112
|
|
|
if not isinstance(duration, Integral): |
2113
|
|
|
raise InvalidArgument("duration needs to be an integer number") |
2114
|
|
|
|
2115
|
|
|
cmd.set_attribute("duration", str(duration)) |
2116
|
|
|
|
2117
|
|
|
if start_time: |
2118
|
|
|
cmd.set_attribute("start_time", str(start_time)) |
2119
|
|
|
|
2120
|
|
|
if end_time: |
2121
|
|
|
cmd.set_attribute("end_time", str(end_time)) |
2122
|
|
|
|
2123
|
|
|
if brief is not None: |
2124
|
|
|
cmd.set_attribute("brief", to_bool(brief)) |
2125
|
|
|
|
2126
|
|
|
if slave_id: |
2127
|
|
|
cmd.set_attribute("slave_id", slave_id) |
2128
|
|
|
|
2129
|
|
|
return self._send_xml_command(cmd) |
2130
|
|
|
|
2131
|
|
View Code Duplication |
def get_tags( |
|
|
|
|
2132
|
|
|
self, |
2133
|
|
|
*, |
2134
|
|
|
filter: Optional[str] = None, |
2135
|
|
|
filter_id: Optional[str] = None, |
2136
|
|
|
trash: Optional[bool] = None, |
2137
|
|
|
names_only: Optional[bool] = None, |
2138
|
|
|
) -> Any: |
2139
|
|
|
"""Request a list of tags |
2140
|
|
|
|
2141
|
|
|
Arguments: |
2142
|
|
|
filter: Filter term to use for the query |
2143
|
|
|
filter_id: UUID of an existing filter to use for the query |
2144
|
|
|
trash: Whether to get tags from the trashcan instead |
2145
|
|
|
names_only: Whether to get only distinct tag names |
2146
|
|
|
|
2147
|
|
|
Returns: |
2148
|
|
|
The response. See :py:meth:`send_command` for details. |
2149
|
|
|
""" |
2150
|
|
|
cmd = XmlCommand("get_tags") |
2151
|
|
|
|
2152
|
|
|
add_filter(cmd, filter, filter_id) |
2153
|
|
|
|
2154
|
|
|
if trash is not None: |
2155
|
|
|
cmd.set_attribute("trash", to_bool(trash)) |
2156
|
|
|
|
2157
|
|
|
if names_only is not None: |
2158
|
|
|
cmd.set_attribute("names_only", to_bool(names_only)) |
2159
|
|
|
|
2160
|
|
|
return self._send_xml_command(cmd) |
2161
|
|
|
|
2162
|
|
|
def get_tag(self, tag_id: str) -> Any: |
2163
|
|
|
"""Request a single tag |
2164
|
|
|
|
2165
|
|
|
Arguments: |
2166
|
|
|
tag_id: UUID of an existing tag |
2167
|
|
|
|
2168
|
|
|
Returns: |
2169
|
|
|
The response. See :py:meth:`send_command` for details. |
2170
|
|
|
""" |
2171
|
|
|
cmd = XmlCommand("get_tags") |
2172
|
|
|
|
2173
|
|
|
if not tag_id: |
2174
|
|
|
raise RequiredArgument( |
2175
|
|
|
function=self.get_tag.__name__, argument='tag_id' |
2176
|
|
|
) |
2177
|
|
|
|
2178
|
|
|
cmd.set_attribute("tag_id", tag_id) |
2179
|
|
|
return self._send_xml_command(cmd) |
2180
|
|
|
|
2181
|
|
|
def get_users( |
2182
|
|
|
self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
2183
|
|
|
) -> Any: |
2184
|
|
|
"""Request a list of users |
2185
|
|
|
|
2186
|
|
|
Arguments: |
2187
|
|
|
filter: Filter term to use for the query |
2188
|
|
|
filter_id: UUID of an existing filter to use for the query |
2189
|
|
|
|
2190
|
|
|
Returns: |
2191
|
|
|
The response. See :py:meth:`send_command` for details. |
2192
|
|
|
""" |
2193
|
|
|
cmd = XmlCommand("get_users") |
2194
|
|
|
|
2195
|
|
|
add_filter(cmd, filter, filter_id) |
2196
|
|
|
|
2197
|
|
|
return self._send_xml_command(cmd) |
2198
|
|
|
|
2199
|
|
|
def get_user(self, user_id: str) -> Any: |
2200
|
|
|
"""Request a single user |
2201
|
|
|
|
2202
|
|
|
Arguments: |
2203
|
|
|
user_id: UUID of an existing user |
2204
|
|
|
|
2205
|
|
|
Returns: |
2206
|
|
|
The response. See :py:meth:`send_command` for details. |
2207
|
|
|
""" |
2208
|
|
|
cmd = XmlCommand("get_users") |
2209
|
|
|
|
2210
|
|
|
if not user_id: |
2211
|
|
|
raise RequiredArgument( |
2212
|
|
|
function=self.get_user.__name__, argument='user_id' |
2213
|
|
|
) |
2214
|
|
|
|
2215
|
|
|
cmd.set_attribute("user_id", user_id) |
2216
|
|
|
return self._send_xml_command(cmd) |
2217
|
|
|
|
2218
|
|
|
def get_version(self) -> Any: |
2219
|
|
|
"""Get the Greenbone Manager Protocol version used by the remote gvmd |
2220
|
|
|
|
2221
|
|
|
Returns: |
2222
|
|
|
The response. See :py:meth:`send_command` for details. |
2223
|
|
|
""" |
2224
|
|
|
return self._send_xml_command(XmlCommand("get_version")) |
2225
|
|
|
|
2226
|
|
|
def help( |
2227
|
|
|
self, *, format: Optional[str] = None, help_type: Optional[str] = None |
2228
|
|
|
) -> Any: |
2229
|
|
|
"""Get the help text |
2230
|
|
|
|
2231
|
|
|
Arguments: |
2232
|
|
|
format: One of "html", "rnc", "text" or "xml |
2233
|
|
|
help_type: One of "brief" or "". Default "" |
2234
|
|
|
|
2235
|
|
|
Returns: |
2236
|
|
|
The response. See :py:meth:`send_command` for details. |
2237
|
|
|
""" |
2238
|
|
|
cmd = XmlCommand("help") |
2239
|
|
|
|
2240
|
|
|
if not help_type: |
2241
|
|
|
help_type = "" |
2242
|
|
|
|
2243
|
|
|
if help_type not in ("", "brief"): |
2244
|
|
|
raise InvalidArgument( |
2245
|
|
|
'help_type argument must be an empty string or "brief"' |
2246
|
|
|
) |
2247
|
|
|
|
2248
|
|
|
cmd.set_attribute("type", help_type) |
2249
|
|
|
|
2250
|
|
|
if format: |
2251
|
|
|
if not format.lower() in ("html", "rnc", "text", "xml"): |
2252
|
|
|
raise InvalidArgument( |
2253
|
|
|
"help format Argument must be one of html, rnc, text or " |
2254
|
|
|
"xml" |
2255
|
|
|
) |
2256
|
|
|
|
2257
|
|
|
cmd.set_attribute("format", format) |
2258
|
|
|
|
2259
|
|
|
return self._send_xml_command(cmd) |
2260
|
|
|
|
2261
|
|
|
def modify_auth(self, group_name: str, auth_conf_settings: dict) -> Any: |
2262
|
|
|
"""Modifies an existing auth. |
2263
|
|
|
|
2264
|
|
|
Arguments: |
2265
|
|
|
group_name: Name of the group to be modified. |
2266
|
|
|
auth_conf_settings: The new auth config. |
2267
|
|
|
|
2268
|
|
|
Returns: |
2269
|
|
|
The response. See :py:meth:`send_command` for details. |
2270
|
|
|
""" |
2271
|
|
|
if not group_name: |
2272
|
|
|
raise RequiredArgument( |
2273
|
|
|
function=self.modify_auth.__name__, argument='group_name' |
2274
|
|
|
) |
2275
|
|
|
if not auth_conf_settings: |
2276
|
|
|
raise RequiredArgument( |
2277
|
|
|
function=self.modify_auth.__name__, |
2278
|
|
|
argument='auth_conf_settings', |
2279
|
|
|
) |
2280
|
|
|
cmd = XmlCommand("modify_auth") |
2281
|
|
|
_xmlgroup = cmd.add_element("group", attrs={"name": str(group_name)}) |
2282
|
|
|
|
2283
|
|
|
for key, value in auth_conf_settings.items(): |
2284
|
|
|
_xmlauthconf = _xmlgroup.add_element("auth_conf_setting") |
2285
|
|
|
_xmlauthconf.add_element("key", key) |
2286
|
|
|
_xmlauthconf.add_element("value", value) |
2287
|
|
|
|
2288
|
|
|
return self._send_xml_command(cmd) |
2289
|
|
|
|
2290
|
|
View Code Duplication |
def modify_group( |
|
|
|
|
2291
|
|
|
self, |
2292
|
|
|
group_id: str, |
2293
|
|
|
*, |
2294
|
|
|
comment: Optional[str] = None, |
2295
|
|
|
name: Optional[str] = None, |
2296
|
|
|
users: Optional[List[str]] = None, |
2297
|
|
|
) -> Any: |
2298
|
|
|
"""Modifies an existing group. |
2299
|
|
|
|
2300
|
|
|
Arguments: |
2301
|
|
|
group_id: UUID of group to modify. |
2302
|
|
|
comment: Comment on group. |
2303
|
|
|
name: Name of group. |
2304
|
|
|
users: List of user names to be in the group |
2305
|
|
|
|
2306
|
|
|
Returns: |
2307
|
|
|
The response. See :py:meth:`send_command` for details. |
2308
|
|
|
""" |
2309
|
|
|
if not group_id: |
2310
|
|
|
raise RequiredArgument( |
2311
|
|
|
function=self.modify_group.__name__, argument='group_id' |
2312
|
|
|
) |
2313
|
|
|
|
2314
|
|
|
cmd = XmlCommand("modify_group") |
2315
|
|
|
cmd.set_attribute("group_id", group_id) |
2316
|
|
|
|
2317
|
|
|
if comment: |
2318
|
|
|
cmd.add_element("comment", comment) |
2319
|
|
|
|
2320
|
|
|
if name: |
2321
|
|
|
cmd.add_element("name", name) |
2322
|
|
|
|
2323
|
|
|
if users: |
2324
|
|
|
cmd.add_element("users", to_comma_list(users)) |
2325
|
|
|
|
2326
|
|
|
return self._send_xml_command(cmd) |
2327
|
|
|
|
2328
|
|
|
def modify_report_format( |
2329
|
|
|
self, |
2330
|
|
|
report_format_id: Optional[Union[str, ReportFormatType]] = None, |
2331
|
|
|
*, |
2332
|
|
|
active: Optional[bool] = None, |
2333
|
|
|
name: Optional[str] = None, |
2334
|
|
|
summary: Optional[str] = None, |
2335
|
|
|
param_name: Optional[str] = None, |
2336
|
|
|
param_value: Optional[str] = None, |
2337
|
|
|
) -> Any: |
2338
|
|
|
"""Modifies an existing report format. |
2339
|
|
|
|
2340
|
|
|
Arguments: |
2341
|
|
|
report_format_id: UUID of report format to modify |
2342
|
|
|
or ReportFormatType (enum) |
2343
|
|
|
active: Whether the report format is active. |
2344
|
|
|
name: The name of the report format. |
2345
|
|
|
summary: A summary of the report format. |
2346
|
|
|
param_name: The name of the param. |
2347
|
|
|
param_value: The value of the param. |
2348
|
|
|
|
2349
|
|
|
Returns: |
2350
|
|
|
The response. See :py:meth:`send_command` for details. |
2351
|
|
|
""" |
2352
|
|
|
if not report_format_id: |
2353
|
|
|
raise RequiredArgument( |
2354
|
|
|
function=self.modify_report_format.__name__, |
2355
|
|
|
argument='report_format_id ', |
2356
|
|
|
) |
2357
|
|
|
|
2358
|
|
|
cmd = XmlCommand("modify_report_format") |
2359
|
|
|
|
2360
|
|
|
if isinstance(report_format_id, ReportFormatType): |
2361
|
|
|
report_format_id = report_format_id.value |
2362
|
|
|
|
2363
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
2364
|
|
|
|
2365
|
|
|
if active is not None: |
2366
|
|
|
cmd.add_element("active", to_bool(active)) |
2367
|
|
|
|
2368
|
|
|
if name: |
2369
|
|
|
cmd.add_element("name", name) |
2370
|
|
|
|
2371
|
|
|
if summary: |
2372
|
|
|
cmd.add_element("summary", summary) |
2373
|
|
|
|
2374
|
|
|
if param_name: |
2375
|
|
|
_xmlparam = cmd.add_element("param") |
2376
|
|
|
_xmlparam.add_element("name", param_name) |
2377
|
|
|
|
2378
|
|
|
if param_value is not None: |
2379
|
|
|
_xmlparam.add_element("value", param_value) |
2380
|
|
|
|
2381
|
|
|
return self._send_xml_command(cmd) |
2382
|
|
|
|
2383
|
|
View Code Duplication |
def modify_role( |
|
|
|
|
2384
|
|
|
self, |
2385
|
|
|
role_id: str, |
2386
|
|
|
*, |
2387
|
|
|
comment: Optional[str] = None, |
2388
|
|
|
name: Optional[str] = None, |
2389
|
|
|
users: Optional[List[str]] = None, |
2390
|
|
|
) -> Any: |
2391
|
|
|
"""Modifies an existing role. |
2392
|
|
|
|
2393
|
|
|
Arguments: |
2394
|
|
|
role_id: UUID of role to modify. |
2395
|
|
|
comment: Name of role. |
2396
|
|
|
name: Comment on role. |
2397
|
|
|
users: List of user names. |
2398
|
|
|
|
2399
|
|
|
Returns: |
2400
|
|
|
The response. See :py:meth:`send_command` for details. |
2401
|
|
|
""" |
2402
|
|
|
if not role_id: |
2403
|
|
|
raise RequiredArgument( |
2404
|
|
|
function=self.modify_role.__name__, argument='role_id argument' |
2405
|
|
|
) |
2406
|
|
|
|
2407
|
|
|
cmd = XmlCommand("modify_role") |
2408
|
|
|
cmd.set_attribute("role_id", role_id) |
2409
|
|
|
|
2410
|
|
|
if comment: |
2411
|
|
|
cmd.add_element("comment", comment) |
2412
|
|
|
|
2413
|
|
|
if name: |
2414
|
|
|
cmd.add_element("name", name) |
2415
|
|
|
|
2416
|
|
|
if users: |
2417
|
|
|
cmd.add_element("users", to_comma_list(users)) |
2418
|
|
|
|
2419
|
|
|
return self._send_xml_command(cmd) |
2420
|
|
|
|
2421
|
|
|
def modify_setting( |
2422
|
|
|
self, |
2423
|
|
|
setting_id: Optional[str] = None, |
2424
|
|
|
name: Optional[str] = None, |
2425
|
|
|
value: Optional[str] = None, |
2426
|
|
|
) -> Any: |
2427
|
|
|
"""Modifies an existing setting. |
2428
|
|
|
|
2429
|
|
|
Arguments: |
2430
|
|
|
setting_id: UUID of the setting to be changed. |
2431
|
|
|
name: The name of the setting. Either setting_id or name must be |
2432
|
|
|
passed. |
2433
|
|
|
value: The value of the setting. |
2434
|
|
|
|
2435
|
|
|
Returns: |
2436
|
|
|
The response. See :py:meth:`send_command` for details. |
2437
|
|
|
""" |
2438
|
|
|
if not setting_id and not name: |
2439
|
|
|
raise RequiredArgument( |
2440
|
|
|
function=self.modify_setting.__name__, |
2441
|
|
|
argument='setting_id or name argument', |
2442
|
|
|
) |
2443
|
|
|
|
2444
|
|
|
if value is None: |
2445
|
|
|
raise RequiredArgument( |
2446
|
|
|
function=self.modify_setting.__name__, argument='value argument' |
2447
|
|
|
) |
2448
|
|
|
|
2449
|
|
|
cmd = XmlCommand("modify_setting") |
2450
|
|
|
|
2451
|
|
|
if setting_id: |
2452
|
|
|
cmd.set_attribute("setting_id", setting_id) |
2453
|
|
|
else: |
2454
|
|
|
cmd.add_element("name", name) |
2455
|
|
|
|
2456
|
|
|
cmd.add_element("value", to_base64(value)) |
2457
|
|
|
|
2458
|
|
|
return self._send_xml_command(cmd) |
2459
|
|
|
|
2460
|
|
View Code Duplication |
def modify_user( |
|
|
|
|
2461
|
|
|
self, |
2462
|
|
|
user_id: str = None, |
2463
|
|
|
name: str = None, |
2464
|
|
|
*, |
2465
|
|
|
new_name: Optional[str] = None, |
2466
|
|
|
comment: Optional[str] = None, |
2467
|
|
|
password: Optional[str] = None, |
2468
|
|
|
auth_source: Optional[UserAuthType] = None, |
2469
|
|
|
role_ids: Optional[List[str]] = None, |
2470
|
|
|
hosts: Optional[List[str]] = None, |
2471
|
|
|
hosts_allow: Optional[bool] = False, |
2472
|
|
|
ifaces: Optional[List[str]] = None, |
2473
|
|
|
ifaces_allow: Optional[bool] = False, |
2474
|
|
|
group_ids: Optional[List[str]] = None, |
2475
|
|
|
) -> Any: |
2476
|
|
|
"""Modifies an existing user. Most of the fields need to be supplied |
2477
|
|
|
for changing a single field even if no change is wanted for those. |
2478
|
|
|
Else empty values are inserted for the missing fields instead. |
2479
|
|
|
Arguments: |
2480
|
|
|
user_id: UUID of the user to be modified. Overrides name element |
2481
|
|
|
argument. |
2482
|
|
|
name: The name of the user to be modified. Either user_id or name |
2483
|
|
|
must be passed. |
2484
|
|
|
new_name: The new name for the user. |
2485
|
|
|
comment: Comment on the user. |
2486
|
|
|
password: The password for the user. |
2487
|
|
|
auth_source: Source allowed for authentication for this user. |
2488
|
|
|
roles_id: List of roles UUIDs for the user. |
2489
|
|
|
hosts: User access rules: List of hosts. |
2490
|
|
|
hosts_allow: Defines how the hosts list is to be interpreted. |
2491
|
|
|
If False (default) the list is treated as a deny list. |
2492
|
|
|
All hosts are allowed by default except those provided by |
2493
|
|
|
the hosts parameter. If True the list is treated as a |
2494
|
|
|
allow list. All hosts are denied by default except those |
2495
|
|
|
provided by the hosts parameter. |
2496
|
|
|
ifaces: User access rules: List of ifaces. |
2497
|
|
|
ifaces_allow: Defines how the ifaces list is to be interpreted. |
2498
|
|
|
If False (default) the list is treated as a deny list. |
2499
|
|
|
All ifaces are allowed by default except those provided by |
2500
|
|
|
the ifaces parameter. If True the list is treated as a |
2501
|
|
|
allow list. All ifaces are denied by default except those |
2502
|
|
|
provided by the ifaces parameter. |
2503
|
|
|
group_ids: List of group UUIDs for the user. |
2504
|
|
|
|
2505
|
|
|
Returns: |
2506
|
|
|
The response. See :py:meth:`send_command` for details. |
2507
|
|
|
""" |
2508
|
|
|
if not user_id and not name: |
2509
|
|
|
raise RequiredArgument( |
2510
|
|
|
function=self.modify_user.__name__, argument='user_id or name' |
2511
|
|
|
) |
2512
|
|
|
|
2513
|
|
|
cmd = XmlCommand("modify_user") |
2514
|
|
|
|
2515
|
|
|
if user_id: |
2516
|
|
|
cmd.set_attribute("user_id", user_id) |
2517
|
|
|
else: |
2518
|
|
|
cmd.add_element("name", name) |
2519
|
|
|
|
2520
|
|
|
if new_name: |
2521
|
|
|
cmd.add_element("new_name", new_name) |
2522
|
|
|
|
2523
|
|
|
if role_ids: |
2524
|
|
|
for role in role_ids: |
2525
|
|
|
cmd.add_element("role", attrs={"id": role}) |
2526
|
|
|
|
2527
|
|
|
if hosts: |
2528
|
|
|
cmd.add_element( |
2529
|
|
|
"hosts", |
2530
|
|
|
to_comma_list(hosts), |
2531
|
|
|
attrs={"allow": to_bool(hosts_allow)}, |
2532
|
|
|
) |
2533
|
|
|
|
2534
|
|
|
if ifaces: |
2535
|
|
|
cmd.add_element( |
2536
|
|
|
"ifaces", |
2537
|
|
|
to_comma_list(ifaces), |
2538
|
|
|
attrs={"allow": to_bool(ifaces_allow)}, |
2539
|
|
|
) |
2540
|
|
|
|
2541
|
|
|
if comment: |
2542
|
|
|
cmd.add_element("comment", comment) |
2543
|
|
|
|
2544
|
|
|
if password: |
2545
|
|
|
cmd.add_element("password", password) |
2546
|
|
|
|
2547
|
|
|
if auth_source: |
2548
|
|
|
_xmlauthsrc = cmd.add_element("sources") |
2549
|
|
|
_xmlauthsrc.add_element("source", auth_source.value) |
2550
|
|
|
|
2551
|
|
|
if group_ids: |
2552
|
|
|
_xmlgroups = cmd.add_element("groups") |
2553
|
|
|
for group_id in group_ids: |
2554
|
|
|
_xmlgroups.add_element("group", attrs={"id": group_id}) |
2555
|
|
|
|
2556
|
|
|
return self._send_xml_command(cmd) |
2557
|
|
|
|
2558
|
|
|
def restore(self, entity_id: str) -> Any: |
2559
|
|
|
"""Restore an entity from the trashcan |
2560
|
|
|
|
2561
|
|
|
Arguments: |
2562
|
|
|
entity_id: ID of the entity to be restored from the trashcan |
2563
|
|
|
|
2564
|
|
|
Returns: |
2565
|
|
|
The response. See :py:meth:`send_command` for details. |
2566
|
|
|
""" |
2567
|
|
|
if not entity_id: |
2568
|
|
|
raise RequiredArgument( |
2569
|
|
|
function=self.restore.__name__, argument='entity_id' |
2570
|
|
|
) |
2571
|
|
|
|
2572
|
|
|
cmd = XmlCommand("restore") |
2573
|
|
|
cmd.set_attribute("id", entity_id) |
2574
|
|
|
|
2575
|
|
|
return self._send_xml_command(cmd) |
2576
|
|
|
|
2577
|
|
|
def sync_cert(self) -> Any: |
2578
|
|
|
"""Request a synchronization with the CERT feed service |
2579
|
|
|
|
2580
|
|
|
Returns: |
2581
|
|
|
The response. See :py:meth:`send_command` for details. |
2582
|
|
|
""" |
2583
|
|
|
return self._send_xml_command(XmlCommand("sync_cert")) |
2584
|
|
|
|
2585
|
|
|
def sync_feed(self) -> Any: |
2586
|
|
|
"""Request a synchronization with the NVT feed service |
2587
|
|
|
|
2588
|
|
|
Returns: |
2589
|
|
|
The response. See :py:meth:`send_command` for details. |
2590
|
|
|
""" |
2591
|
|
|
return self._send_xml_command(XmlCommand("sync_feed")) |
2592
|
|
|
|
2593
|
|
|
def sync_scap(self) -> Any: |
2594
|
|
|
"""Request a synchronization with the SCAP feed service |
2595
|
|
|
|
2596
|
|
|
Returns: |
2597
|
|
|
The response. See :py:meth:`send_command` for details. |
2598
|
|
|
""" |
2599
|
|
|
return self._send_xml_command(XmlCommand("sync_scap")) |
2600
|
|
|
|
2601
|
|
View Code Duplication |
def verify_report_format( |
|
|
|
|
2602
|
|
|
self, report_format_id: Union[str, ReportFormatType] |
2603
|
|
|
) -> Any: |
2604
|
|
|
"""Verify an existing report format |
2605
|
|
|
|
2606
|
|
|
Verifies the trust level of an existing report format. It will be |
2607
|
|
|
checked whether the signature of the report format currently matches the |
2608
|
|
|
report format. This includes the script and files used to generate |
2609
|
|
|
reports of this format. It is *not* verified if the report format works |
2610
|
|
|
as expected by the user. |
2611
|
|
|
|
2612
|
|
|
Arguments: |
2613
|
|
|
report_format_id: UUID of the report format to be verified |
2614
|
|
|
or ReportFormatType (enum) |
2615
|
|
|
|
2616
|
|
|
Returns: |
2617
|
|
|
The response. See :py:meth:`send_command` for details. |
2618
|
|
|
""" |
2619
|
|
|
if not report_format_id: |
2620
|
|
|
raise RequiredArgument( |
2621
|
|
|
function=self.verify_report_format.__name__, |
2622
|
|
|
argument='report_format_id', |
2623
|
|
|
) |
2624
|
|
|
|
2625
|
|
|
cmd = XmlCommand("verify_report_format") |
2626
|
|
|
|
2627
|
|
|
if isinstance(report_format_id, ReportFormatType): |
2628
|
|
|
report_format_id = report_format_id.value |
2629
|
|
|
|
2630
|
|
|
cmd.set_attribute("report_format_id", report_format_id) |
2631
|
|
|
|
2632
|
|
|
return self._send_xml_command(cmd) |
2633
|
|
|
|