Docker Plugin API in Python
Jacek Kowalski
2020-05-03 881ffe51002a5d121a49cf05042e9b77a24b660f
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
import functools
 
import flask
from werkzeug.local import LocalProxy
 
 
class InputValidationException(Exception):
    pass
 
 
class Blueprint(flask.Blueprint):
    logger = LocalProxy(lambda: flask.current_app.logger)
 
    def route(self, route, **options):
        parent_function_wrapper = super().route(route, **options)
 
        def newFunctionWrapper(func):
            @functools.wraps(func)
            def newFunction():
                try:
                    result = func()
                except InputValidationException as e:
                    self.logger.error(e)
                    return {
                        'Err': e.args[0],
                    }
                return result
 
            return parent_function_wrapper(newFunction)
 
        return newFunctionWrapper
 
 
app = Blueprint('Plugin', __name__)
 
functions = []
 
 
@app.route('/Plugin.Activate', methods=['POST'])
def Activate():
    return {
        'Implements': functions,
    }
 
 
__all__ = ['InputValidationException', 'Blueprint', 'app', 'functions']