__init__.py 3.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright (c) 2015, Daniele Venzano
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

16
17
"""Flask initialization for the web interface."""

18
19
20
21
from typing import List

import tornado.web

Daniele Venzano's avatar
Daniele Venzano committed
22
import zoe_api.web.start
23
import zoe_api.web.websockets
Daniele Venzano's avatar
Daniele Venzano committed
24
import zoe_api.web.executions
25
import zoe_api.web.zapp_shop
26
import zoe_api.web.status
27

28
29
from zoe_api.web.filemanager import FileListHandler, UploadHandler, MainWsHandler, DownloadHandler

30
from zoe_lib.version import ZOE_API_VERSION, ZOE_VERSION
31
32


33
def web_init(api_endpoint) -> List[tornado.web.URLSpec]:
Daniele Venzano's avatar
Daniele Venzano committed
34
    """Tornado init for the web interface."""
35

36
37
38
39
    route_args = {
        'api_endpoint': api_endpoint
    }
    web_routes = [
40
41
        tornado.web.url(r'/', zoe_api.web.start.RootWeb, route_args, name='root'),
        tornado.web.url(r'/user', zoe_api.web.start.HomeWeb, route_args, name='home_user'),
42
        tornado.web.url(r'/login', zoe_api.web.start.LoginWeb, route_args, name='login'),
43
        tornado.web.url(r'/logout', zoe_api.web.start.LogoutWeb, route_args, name='logout'),
44

Daniele Venzano's avatar
Daniele Venzano committed
45
        tornado.web.url(r'/executions', zoe_api.web.executions.ExecutionListWeb, route_args, name='execution_list'),
46
47
48
        tornado.web.url(r'/executions/start', zoe_api.web.executions.ExecutionStartWeb, route_args, name='execution_start'),
        tornado.web.url(r'/executions/restart/([0-9]+)', zoe_api.web.executions.ExecutionRestartWeb, route_args, name='execution_restart'),
        tornado.web.url(r'/executions/terminate/([0-9]+)', zoe_api.web.executions.ExecutionTerminateWeb, route_args, name='execution_terminate'),
49
        tornado.web.url(r'/executions/inspect/([0-9]+)', zoe_api.web.executions.ExecutionInspectWeb, route_args, name='execution_inspect'),
50
        tornado.web.url(r'/service/logs/([0-9]+)', zoe_api.web.executions.ServiceLogsWeb, route_args, name='service_logs'),
51

52
53
54
55
        tornado.web.url(r'/websocket', zoe_api.web.websockets.WebSocketEndpointWeb, route_args, name='websocket'),

        tornado.web.url(r'/zapp-shop', zoe_api.web.zapp_shop.ZAppShopHomeWeb, route_args, name='zappshop'),
        tornado.web.url(r'/zapp-shop/logo/([a-z\-.]+)', zoe_api.web.zapp_shop.ZAppLogoWeb, route_args, name='zappshop_logo'),
56
57
        tornado.web.url(r'/zapp-shop/start/([0-9a-z\-.]+)', zoe_api.web.zapp_shop.ZAppStartWeb, route_args, name='zappshop_start'),

58
59
60
61
62
63
        tornado.web.url(r'/status', zoe_api.web.status.StatusEndpointWeb, route_args, name='status'),

        tornado.web.url(r"/ws/", FileListHandler, name='filemanager'),
        tornado.web.url(r"/ws/upload", UploadHandler, route_args),
        tornado.web.url(r"/ws/ws", MainWsHandler, route_args),
        tornado.web.url(r"/ws/download/(.*)", DownloadHandler, route_args)
64
65
66
    ]

    return web_routes
67
68


69
def inject_version():
70
    """Inject some template variables in all templates."""
71
    return {
Daniele Venzano's avatar
Daniele Venzano committed
72
        'zoe_version': ZOE_VERSION,
73
74
        'zoe_api_version': ZOE_API_VERSION,
    }