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