ospd.resultlist   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 110
dl 0
loc 157
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A ResultList.__init__() 0 2 1
A ResultList.__len__() 0 2 1
A ResultList.add_scan_log_to_list() 0 23 1
A ResultList.add_scan_alarm_to_list() 0 24 1
A ResultList.add_scan_error_to_list() 0 20 1
A ResultList.__iter__() 0 2 1
A ResultList.add_scan_host_detail_to_list() 0 16 1
A ResultList.add_result_to_list() 0 26 1
1
# Copyright (C) 2014-2021 Greenbone Networks GmbH
2
#
3
# SPDX-License-Identifier: AGPL-3.0-or-later
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Affero General Public License as
7
# published by the Free Software Foundation, either version 3 of the
8
# License, or (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU Affero General Public License for more details.
14
#
15
# You should have received a copy of the GNU Affero General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
# pylint: disable=too-many-lines
19
20
""" Class for handling list of resutls.
21
"""
22
23
from collections import OrderedDict
24
from typing import Dict
25
from ospd.misc import ResultType
26
27
28
class ResultList:
29
    """Class for handling list of resutls."""
30
31
    def __init__(self):
32
        self._result_list = list()
33
34
    def __len__(self):
35
        return len(self._result_list)
36
37
    def add_scan_host_detail_to_list(
38
        self,
39
        host: str = '',
40
        hostname: str = '',
41
        name: str = '',
42
        value: str = '',
43
        uri: str = '',
44
    ) -> None:
45
        """Adds a host detail result to result list."""
46
        self.add_result_to_list(
47
            ResultType.HOST_DETAIL,
48
            host,
49
            hostname,
50
            name,
51
            value,
52
            uri,
53
        )
54
55
    def add_scan_error_to_list(
56
        self,
57
        host: str = '',
58
        hostname: str = '',
59
        name: str = '',
60
        value: str = '',
61
        port: str = '',
62
        test_id='',
63
        uri: str = '',
64
    ) -> None:
65
        """Adds an error result to result list."""
66
        self.add_result_to_list(
67
            ResultType.ERROR,
68
            host,
69
            hostname,
70
            name,
71
            value,
72
            port,
73
            test_id,
74
            uri,
75
        )
76
77
    def add_scan_log_to_list(
78
        self,
79
        host: str = '',
80
        hostname: str = '',
81
        name: str = '',
82
        value: str = '',
83
        port: str = '',
84
        test_id: str = '',
85
        qod: str = '',
86
        uri: str = '',
87
    ) -> None:
88
        """Adds log result to a list of results."""
89
        self.add_result_to_list(
90
            ResultType.LOG,
91
            host,
92
            hostname,
93
            name,
94
            value,
95
            port,
96
            test_id,
97
            '0.0',
98
            qod,
99
            uri,
100
        )
101
102
    def add_scan_alarm_to_list(
103
        self,
104
        host: str = '',
105
        hostname: str = '',
106
        name: str = '',
107
        value: str = '',
108
        port: str = '',
109
        test_id: str = '',
110
        severity: str = '',
111
        qod: str = '',
112
        uri: str = '',
113
    ) -> None:
114
        """Adds an alarm result to a result list."""
115
        self.add_result_to_list(
116
            ResultType.ALARM,
117
            host,
118
            hostname,
119
            name,
120
            value,
121
            port,
122
            test_id,
123
            severity,
124
            qod,
125
            uri,
126
        )
127
128
    def add_result_to_list(
129
        self,
130
        result_type: int,
131
        host: str = '',
132
        hostname: str = '',
133
        name: str = '',
134
        value: str = '',
135
        port: str = '',
136
        test_id: str = '',
137
        severity: str = '',
138
        qod: str = '',
139
        uri: str = '',
140
    ) -> None:
141
142
        result = OrderedDict()  # type: Dict
143
        result['type'] = result_type
144
        result['name'] = name
145
        result['severity'] = severity
146
        result['test_id'] = test_id
147
        result['value'] = value
148
        result['host'] = host
149
        result['hostname'] = hostname
150
        result['port'] = port
151
        result['qod'] = qod
152
        result['uri'] = uri
153
        self._result_list.append(result)
154
155
    def __iter__(self):
156
        return iter(self._result_list)
157