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
|
|
|
# pylint: disable=redefined-builtin |
20
|
|
|
# MAYBE we should change filter to filter_string (everywhere) |
21
|
|
|
|
22
|
|
|
from enum import Enum |
23
|
|
|
from numbers import Real |
24
|
|
|
from typing import Optional |
25
|
|
|
|
26
|
|
|
from gvm.errors import InvalidArgument |
27
|
|
|
|
28
|
|
|
Severity = Real |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
class SeverityLevel(Enum): |
32
|
|
|
"""Enum for severity levels""" |
33
|
|
|
|
34
|
|
|
HIGH = "High" |
35
|
|
|
MEDIUM = "Medium" |
36
|
|
|
LOW = "Low" |
37
|
|
|
LOG = "Log" |
38
|
|
|
ALARM = "Alarm" |
39
|
|
|
DEBUG = "Debug" |
40
|
|
|
|
41
|
|
|
|
42
|
|
View Code Duplication |
def get_severity_level_from_string( |
|
|
|
|
43
|
|
|
severity_level: Optional[str], |
44
|
|
|
) -> Optional[SeverityLevel]: |
45
|
|
|
"""Convert a severity level string into a SeverityLevel instance""" |
46
|
|
|
if not severity_level: |
47
|
|
|
return None |
48
|
|
|
|
49
|
|
|
try: |
50
|
|
|
return SeverityLevel[severity_level.upper()] |
51
|
|
|
except KeyError: |
52
|
|
|
raise InvalidArgument( |
53
|
|
|
argument='severity_level', |
54
|
|
|
function=get_severity_level_from_string.__name__, |
55
|
|
|
) from None |
56
|
|
|
|