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