aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/moon_manager/api/information/information.py
blob: 132b8bce530427677a4f21fac9b9ef0197e2a14d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Software Name: MOON

# Version: 5.4

# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
# SPDX-License-Identifier: Apache-2.0

# This software is distributed under the 'Apache License 2.0',
# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
# or see the "LICENSE" file for more details.

"""
API to gather information from external component like OpenStack
"""

from uuid import uuid4
import logging
from moon_utilities.security_functions import enforce
from moon_manager.api.information.managers import Managers

LOGGER = logging.getLogger("moon.manager.information.api.information")


class InformationManager(Managers):
    """
    Manager use to get information from external components
    """

    def __init__(self, connector=None):
        self.driver = connector.driver
        Managers.InformationManager = self

    def set_auth(self, **kwargs):
        """Set authorizations if necessary

        :param kwargs: arguments which are necessary to login to the server
        :return: headers to use
        """
        return self.driver.set_auth(**kwargs)

    def unset_auth(self, **kwargs):
        """Unset the authorization is necessary

        :param kwargs: arguments which are necessary to logout to the server
        :return: headers to use
        """
        return self.driver.unset_auth(**kwargs)

    @enforce("read", "pip")
    def get_items(self, item_id=None, **kwargs):
        """List items in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to list items
        :return: a list of items
        """
        return self.driver.get_items(item_id=item_id, **kwargs)

    @enforce("write", "pip")
    def add_item(self, item_id=None, **kwargs):
        """Add a item in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to add a item
        :return: the item added
        """
        if not item_id:
            item_id = uuid4().hex
        return self.driver.add_item(item_id=item_id, **kwargs)

    @enforce(("read", "write"), "pip")
    def update_item(self, item_id, **kwargs):
        """Update a item in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to update the item
        :return: the item updated
        """
        return self.driver.update_item(item_id=item_id, **kwargs)

    @enforce("write", "pip")
    def delete_item(self, item_id, **kwargs):
        """Delete a item in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to delete the item
        :return: True if the item has been deleted
        """
        return self.driver.delete_item(item_id=item_id, **kwargs)

    @enforce("read", "pip")
    def get_projects(self):
        """List projects in the server

        :return: the list of projects
        """
        return self.driver.get_projects()

    @enforce("write", "pip")
    def create_project(self, **tenant_dict):
        """Create a project in the server

        :param tenant_dict: all arguments necessary to create a project
        :return: True if the item has been deleted
        """
        return self.driver.create_project(**tenant_dict)