Completed
Push — master ( a4987b...bdfb6a )
by Björn
28s queued 14s
created

gvm.protocols.gmpv208.entities.report_formats   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_report_format_id_from_string() 0 16 3
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 enum import Enum
20
from typing import Optional
21
22
from gvm.errors import InvalidArgument
23
24
25
class ReportFormatType(Enum):
26
    """Enum for builtin report formats"""
27
28
    ANONYMOUS_XML = '5057e5cc-b825-11e4-9d0e-28d24461215b'
29
    ARF = '910200ca-dc05-11e1-954f-406186ea4fc5'
30
    CPE = '5ceff8ba-1f62-11e1-ab9f-406186ea4fc5'
31
    CSV_HOSTS = '9087b18c-626c-11e3-8892-406186ea4fc5"'
32
    CSV_RESULTS = 'c1645568-627a-11e3-a660-406186ea4fc5'
33
    GCR_PDF = 'dc51a40a-c022-11e9-b02d-3f7ca5bdcb11'
34
    GSR_HTML = 'ffa123c9-a2d2-409e-bbbb-a6c1385dbeaa'
35
    GSR_PDF = '35ba7077-dc85-42ef-87c9-b0eda7e903b6'
36
    GXCR_PDF = 'f0d348de-c022-11e9-bc4c-4bf1d5e1a8ca'
37
    GXR_PDF = 'ebbc7f34-8ae5-11e1-b07b-001f29eadec8'
38
    ITG = '77bd6c4a-1f62-11e1-abf0-406186ea4fc5'
39
    LATEX = 'a684c02c-b531-11e1-bdc2-406186ea4fc5'
40
    NBE = '9ca6fe72-1f62-11e1-9e7c-406186ea4fc5'
41
    PDF = 'c402cc3e-b531-11e1-9163-406186ea4fc5'
42
    SVG = '9e5e5deb-879e-4ecc-8be6-a71cd0875cdd'
43
    TXT = 'a3810a62-1f62-11e1-9219-406186ea4fc5'
44
    VERINICE_ISM = 'c15ad349-bd8d-457a-880a-c7056532ee15'
45
    VERINICE_ITG = '50c9950a-f326-11e4-800c-28d24461215b'
46
    XML = 'a994b278-1f62-11e1-96ac-406186ea4fc5'
47
48
49
def get_report_format_id_from_string(
50
    report_format: Optional[str],
51
) -> Optional[ReportFormatType]:
52
    """Convert an report format name into a ReportFormatType instance"""
53
    if not report_format:
54
        return None
55
56
    report_format = report_format.lower()
57
58
    try:
59
        return ReportFormatType[report_format.replace(' ', '_').upper()]
60
    except KeyError:
61
        raise InvalidArgument(
62
            argument='report_format',
63
            function=get_report_format_id_from_string.__name__,
64
        ) from None
65