aboutsummaryrefslogtreecommitdiffstats
path: root/moon_engine/moon_engine/api/orchestration/pipeline.py
blob: 47a844095c13ec78366d100ff072e353a8f787bf (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
# 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.


from uuid import uuid4
import logging
from moon_utilities.security_functions import enforce
from moon_engine.api.orchestration.managers import Managers

logger = logging.getLogger("moon.engine.api.orchestration.pipeline")


class PipelineManager(Managers):

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

    @enforce(("read", "write"), "pipelines")
    def update_pipeline(self, moon_user_id, pipeline_id, data):
        return self.driver.update_pipeline(pipeline_id=pipeline_id, data=data)

    @enforce("write", "pipelines")
    def delete_pipeline(self, moon_user_id, pipeline_id):
        return self.driver.delete_pipeline(pipeline_id=pipeline_id)

    @enforce("write", "pipelines")
    def add_pipeline(self, moon_user_id, pipeline_id=None, data=None):
        if not pipeline_id:
            pipeline_id = uuid4().hex
        if data is None:
            data = {}
        if "plugins" not in data:
            data["plugins"] = ["moon_engine.plugins.authz"]
        return self.driver.add_pipeline(pipeline_id=pipeline_id, data=data)

    @enforce("read", "pipelines")
    def get_pipelines(self, moon_user_id, pipeline_id=None):
        return self.driver.get_pipelines(pipeline_id=pipeline_id)

    @enforce("read", "pipelines")
    def get_pipeline_api_key(self, moon_user_id, pipeline_id):
        return self.driver.get_pipeline_api_key(pipeline_id=pipeline_id)