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