__init__.py 2.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Copyright (c) 2016, 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.

"""RESTful Flask API definition."""

from typing import List

import tornado.web

22
from zoe_api.rest_api.execution import ExecutionAPI, ExecutionCollectionAPI, ExecutionDeleteAPI, ExecutionEndpointsAPI
23
from zoe_api.rest_api.info import InfoAPI
hxquangnhat's avatar
hxquangnhat committed
24
from zoe_api.rest_api.userinfo import UserInfoAPI
25
from zoe_api.rest_api.service import ServiceAPI
26 27
from zoe_api.rest_api.discovery import DiscoveryAPI
from zoe_api.rest_api.statistics import SchedulerStatsAPI
28
from zoe_api.rest_api.oauth import OAuthGetAPI, OAuthRevokeAPI
hxquangnhat's avatar
hxquangnhat committed
29
from zoe_api.rest_api.login import LoginAPI
30 31 32 33 34 35 36 37 38 39 40 41 42 43

from zoe_lib.version import ZOE_API_VERSION

API_PATH = '/api/' + ZOE_API_VERSION


def api_init(api_endpoint) -> List[tornado.web.URLSpec]:
    """Initialize the API"""
    route_args = {
        'api_endpoint': api_endpoint
    }

    api_routes = [
        tornado.web.url(API_PATH + r'/info', InfoAPI, route_args),
hxquangnhat's avatar
hxquangnhat committed
44
        tornado.web.url(API_PATH + r'/login', LoginAPI, route_args),
hxquangnhat's avatar
hxquangnhat committed
45
        tornado.web.url(API_PATH + r'/userinfo', UserInfoAPI, route_args),
46 47 48

        tornado.web.url(API_PATH + r'/execution/([0-9]+)', ExecutionAPI, route_args),
        tornado.web.url(API_PATH + r'/execution/delete/([0-9]+)', ExecutionDeleteAPI, route_args),
49
        tornado.web.url(API_PATH + r'/execution/endpoints/([0-9]+)', ExecutionEndpointsAPI, route_args),
50 51 52 53 54 55
        tornado.web.url(API_PATH + r'/execution', ExecutionCollectionAPI, route_args),

        tornado.web.url(API_PATH + r'/service/([0-9]+)', ServiceAPI, route_args),

        tornado.web.url(API_PATH + r'/discovery/by_group/([0-9]+)/([a-z0-9A-Z\-]+)', DiscoveryAPI, route_args),

56 57 58 59
        tornado.web.url(API_PATH + r'/statistics/scheduler', SchedulerStatsAPI, route_args),

        tornado.web.url(API_PATH + r'/oauth/token', OAuthGetAPI, route_args),
        tornado.web.url(API_PATH + r'/oauth/revoke/([a-z0-9A-Z\-]+)', OAuthRevokeAPI, route_args)
60 61 62
    ]

    return api_routes