Completed
Push — master ( 668af9...8a1738 )
by
unknown
14s queued 11s
created

gvm.protocols.gmpv7.Gmp.get_agents()   B

Complexity

Conditions 5

Size

Total Lines 45
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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