|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2021 Greenbone Networks GmbH |
|
3
|
|
|
# |
|
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
|
5
|
|
|
# |
|
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# This program is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
from typing import Any, Optional |
|
20
|
|
|
|
|
21
|
|
|
from gvm.errors import RequiredArgument |
|
22
|
|
|
from gvm.xml import XmlCommand |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
class PreferencesMixin: |
|
26
|
|
|
def get_preferences( |
|
27
|
|
|
self, *, nvt_oid: Optional[str] = None, config_id: Optional[str] = None |
|
28
|
|
|
) -> Any: |
|
29
|
|
|
"""Request a list of preferences |
|
30
|
|
|
|
|
31
|
|
|
When the command includes a config_id attribute, the preference element |
|
32
|
|
|
includes the preference name, type and value, and the NVT to which the |
|
33
|
|
|
preference applies. Otherwise, the preference element includes just the |
|
34
|
|
|
name and value, with the NVT and type built into the name. |
|
35
|
|
|
|
|
36
|
|
|
Arguments: |
|
37
|
|
|
nvt_oid: OID of nvt |
|
38
|
|
|
config_id: UUID of scan config of which to show preference values |
|
39
|
|
|
|
|
40
|
|
|
Returns: |
|
41
|
|
|
The response. See :py:meth:`send_command` for details. |
|
42
|
|
|
""" |
|
43
|
|
|
cmd = XmlCommand("get_preferences") |
|
44
|
|
|
|
|
45
|
|
|
if nvt_oid: |
|
46
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
|
47
|
|
|
|
|
48
|
|
|
if config_id: |
|
49
|
|
|
cmd.set_attribute("config_id", config_id) |
|
50
|
|
|
|
|
51
|
|
|
return self._send_xml_command(cmd) |
|
52
|
|
|
|
|
53
|
|
|
def get_preference( |
|
54
|
|
|
self, |
|
55
|
|
|
name: str, |
|
56
|
|
|
*, |
|
57
|
|
|
nvt_oid: Optional[str] = None, |
|
58
|
|
|
config_id: Optional[str] = None, |
|
59
|
|
|
) -> Any: |
|
60
|
|
|
"""Request a nvt preference |
|
61
|
|
|
|
|
62
|
|
|
Arguments: |
|
63
|
|
|
name: name of a particular preference |
|
64
|
|
|
nvt_oid: OID of nvt |
|
65
|
|
|
config_id: UUID of scan config of which to show preference values |
|
66
|
|
|
|
|
67
|
|
|
Returns: |
|
68
|
|
|
The response. See :py:meth:`send_command` for details. |
|
69
|
|
|
""" |
|
70
|
|
|
cmd = XmlCommand("get_preferences") |
|
71
|
|
|
|
|
72
|
|
|
if not name: |
|
73
|
|
|
raise RequiredArgument( |
|
74
|
|
|
function=self.get_preference.__name__, argument='name' |
|
75
|
|
|
) |
|
76
|
|
|
|
|
77
|
|
|
cmd.set_attribute("preference", name) |
|
78
|
|
|
|
|
79
|
|
|
if nvt_oid: |
|
80
|
|
|
cmd.set_attribute("nvt_oid", nvt_oid) |
|
81
|
|
|
|
|
82
|
|
|
if config_id: |
|
83
|
|
|
cmd.set_attribute("config_id", config_id) |
|
84
|
|
|
|
|
85
|
|
|
return self._send_xml_command(cmd) |
|
86
|
|
|
|