Passed
Push — master ( 48952f...b1214c )
by Jaspar
34:32 queued 33:09
created

TrashcanMixin.restore_from_trashcan()   A

Complexity

Conditions 2

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nop 2
dl 0
loc 19
rs 10
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
from typing import Any
20
21
from gvm.errors import RequiredArgument
22
from gvm.xml import XmlCommand
23
24
25
class TrashcanMixin:
26
    def empty_trashcan(self) -> Any:
27
        """Empty the trashcan
28
29
        Remove all entities from the trashcan. **Attention:** this command can
30
        not be reverted
31
32
        Returns:
33
            The response. See :py:meth:`send_command` for details.
34
        """
35
        return self._send_xml_command(XmlCommand("empty_trashcan"))
36
37
    def restore_from_trashcan(self, entity_id: str) -> Any:
38
        """Restore an entity from the trashcan
39
40
        Arguments:
41
            entity_id: ID of the entity to be restored from the trashcan
42
43
        Returns:
44
            The response. See :py:meth:`send_command` for details.
45
        """
46
        if not entity_id:
47
            raise RequiredArgument(
48
                function=self.restore_from_trashcan.__name__,
49
                argument='entity_id',
50
            )
51
52
        cmd = XmlCommand("restore")
53
        cmd.set_attribute("id", entity_id)
54
55
        return self._send_xml_command(cmd)
56