Completed
Push — master ( c5fe8d...802093 )
by Jaspar
32s queued 15s
created

OperatingSystemsMixin.get_operating_systems()   A

Complexity

Conditions 1

Size

Total Lines 23
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 4
dl 0
loc 23
rs 9.95
c 0
b 0
f 0
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
21
from typing import Any, Optional
22
23
from gvm.errors import RequiredArgument
24
from gvm.utils import add_filter
25
from gvm.xml import XmlCommand
26
27
28
class OperatingSystemsMixin:
29
    def delete_operating_system(
30
        self,
31
        operating_system_id: str,
32
    ) -> Any:
33
        """Deletes an existing operating_system
34
35
        Arguments:
36
            operating_system_id: UUID of the single operating_system to delete.
37
38
        """
39
        if not operating_system_id:
40
            raise RequiredArgument(
41
                function=self.delete_operating_system.__name__,
42
                argument='operating_system_id',
43
            )
44
45
        cmd = XmlCommand("delete_asset")
46
        cmd.set_attribute("asset_id", operating_system_id)
47
48
        return self._send_xml_command(cmd)
49
50
    def get_operating_systems(
51
        self,
52
        *,
53
        filter: Optional[str] = None,
54
        filter_id: Optional[str] = None,
55
    ) -> Any:
56
        """Request a list of operating_systems
57
58
        Arguments:
59
            filter: Filter term to use for the query
60
            filter_id: UUID of an existing filter to use for the query
61
62
        Returns:
63
            The response. See :py:meth:`send_command` for details.
64
        """
65
66
        cmd = XmlCommand("get_assets")
67
68
        cmd.set_attribute("type", "os")
69
70
        add_filter(cmd, filter, filter_id)
71
72
        return self._send_xml_command(cmd)
73
74
    def get_operating_system(self, operating_system_id: str) -> Any:
75
        """Request a single operating_system
76
77
        Arguments:
78
            operating_system_id: UUID of an existing operating_system
79
80
        Returns:
81
            The response. See :py:meth:`send_command` for details.
82
        """
83
        cmd = XmlCommand("get_assets")
84
85
        if not operating_system_id:
86
            raise RequiredArgument(
87
                function=self.get_operating_system.__name__,
88
                argument='operating_system_id',
89
            )
90
91
        cmd.set_attribute("asset_id", operating_system_id)
92
        cmd.set_attribute("type", "os")
93
94
        return self._send_xml_command(cmd)
95
96
    def modify_operating_system(
97
        self, operating_system_id: str, *, comment: Optional[str] = None
98
    ) -> Any:
99
        """Modifies an existing operating system.
100
101
        Arguments:
102
            operating_system_id: UUID of the operating_system to be modified.
103
            comment: Comment for the operating_system. Not passing a comment
104
                arguments clears the comment for this operating system.
105
106
        Returns:
107
            The response. See :py:meth:`send_command` for details.
108
        """
109
        if not operating_system_id:
110
            raise RequiredArgument(
111
                function=self.modify_operating_system.__name__,
112
                argument='operating_system_id',
113
            )
114
115
        cmd = XmlCommand("modify_asset")
116
        cmd.set_attribute("asset_id", operating_system_id)
117
        if not comment:
118
            comment = ""
119
        cmd.add_element("comment", comment)
120
121
        return self._send_xml_command(cmd)
122