Passed
Pull Request — master (#125)
by Juan José
01:45
created

gmp.protocols.ospv1.Osp.get_scans()   A

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nop 4
dl 0
loc 18
rs 10
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
Module for communication to a daemon speaking Open Scanner Protocol version 1
20
"""
21
from gmp.protocols.base import Protocol
22
from gmp.xml import XmlCommand
23
24
PROTOCOL_VERSION = (1, 2,)
25
26
class Osp(Protocol):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
27
28
    @staticmethod
29
    def get_protocol_version():
30
        """Allow to determine the Open Scanner Protocol version.
31
32
            Returns:
33
                str: Implemented version of the Open Scanner Protocol
34
        """
35
        return '.'.join(str(x) for x in PROTOCOL_VERSION)
36
37
    def get_version(self):
38
        """Get the version of the OSPD server which is connected to."""
39
        cmd = XmlCommand('get_version')
40
        return self.send_command(cmd.to_string())
41
42
    def help(self):
43
        """Get the help text."""
44
        cmd = XmlCommand('help')
45
        return self.send_command(cmd.to_string())
46
47
    def get_scans(self, scan_id=None, details='1', pop_results='0'):
48
        """Get the stored scans.
49
50
         Args:
51
            scan_id (uuid): Identifier for a scan.
52
            details (boolean): Whether to get full scan reports.
53
            pop_results (boolean) Whether to remove the fetched results.
54
55
        Returns:
56
            str: Response from server.
57
        """
58
        cmd = XmlCommand('get_scans')
59
        if scan_id:
60
            cmd.set_attribute('scan_id', scan_id)
61
        cmd.set_attribute('details', details)
62
        cmd.set_attribute('pop_results', pop_results)
63
64
        return self.send_command(cmd.to_string())
65
66
    def delete_scan(self, scan_id):
67
        """Delete a finished scan.
68
        Args:
69
            scan_id (uuid): Identifier for a finished scan.
70
        Returns:
71
            str: Response from server.
72
        """
73
        cmd = XmlCommand('delete_scan')
74
        if scan_id:
75
            cmd.set_attribute('scan_id', scan_id)
76
77
        return self.send_command(cmd.to_string())
78
79
    def get_scanner_details(self):
80
        """Return scanner description and parameters."""
81
        cmd = XmlCommand('get_scanner_details')
82
        return self.send_command(cmd.to_string())
83
84
    def get_vts(self, vt_id=None):
85
        """Return information about vulnerability tests,
86
        if offered by scanner.
87
88
        Args:
89
            vt_id (uuid): Identifier for a vulnerability test.
90
        Returns:
91
            str: Response from server.
92
        """
93
        cmd = XmlCommand('get_vts')
94
        if vt_id:
95
            cmd.set_attribute('vt_id', vt_id)
96
97
        return self.send_command(cmd.to_string())
98
99
    def start_scan(self):
100
        """Start a new scan.
101
102
        Args:
103
            scan_id (uuid): Identifier for a running scan.
104
        Returns:
105
            str: Response from server.
106
        """
107
108
    def stop_scan(self, scan_id=None):
109
        """Stop a currently running scan.
110
111
        Args:
112
            scan_id (uuid): Identifier for a running scan.
113
        Returns:
114
            str: Response from server.
115
        """
116
        cmd = XmlCommand('stop_scan')
117
        if scan_id:
118
            cmd.set_attribute('scan_id', scan_id)
119
120
        return self.send_command(cmd.to_string())
121