Passed
Push — master ( 147191...48952f )
by Björn
110:14 queued 108:31
created

gvm.protocols.gmpv208.entities.vulnerabilities   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A VulnerabilitiesMixin.get_vulnerabilities() 0 19 1
A VulnerabilitiesMixin.get_vulnerability() 0 18 2
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.utils import add_filter
23
from gvm.xml import XmlCommand
24
25
26
class VulnerabilitiesMixin:
27
    def get_vulnerabilities(
28
        self,
29
        *,
30
        filter_string: Optional[str] = None,
31
        filter_id: Optional[str] = None,
32
    ) -> Any:
33
        """Request a list of vulnerabilities
34
35
        Arguments:
36
            filter_string: Filter term to use for the query
37
            filter_id: UUID of an existing filter to use for the query
38
        Returns:
39
            The response. See :py:meth:`send_command` for details.
40
        """
41
        cmd = XmlCommand("get_vulns")
42
43
        add_filter(cmd, filter_string, filter_id)
44
45
        return self._send_xml_command(cmd)
46
47
    def get_vulnerability(self, vulnerability_id: str) -> Any:
48
        """Request a single vulnerability
49
50
        Arguments:
51
            vulnerability_id: ID of an existing vulnerability
52
53
        Returns:
54
            The response. See :py:meth:`send_command` for details.
55
        """
56
        if not vulnerability_id:
57
            raise RequiredArgument(
58
                function=self.get_vulnerability.__name__,
59
                argument='vulnerability_id',
60
            )
61
62
        cmd = XmlCommand("get_vulns")
63
        cmd.set_attribute("vuln_id", vulnerability_id)
64
        return self._send_xml_command(cmd)
65