99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from flask import Blueprint, abort
|
|
from flask_restx import Api, Namespace
|
|
from werkzeug.exceptions import InternalServerError
|
|
|
|
api_authorizations = {
|
|
'apikey': {
|
|
'type': 'apiKey',
|
|
'in': 'header',
|
|
'name': 'X-API-KEY'
|
|
},
|
|
'basicAuth': {
|
|
'type': 'basic',
|
|
'scheme': 'basic'
|
|
},
|
|
'bearerAuth': {
|
|
'type': 'apiKey',
|
|
'scheme': 'bearer',
|
|
'name': 'Authorization',
|
|
'in': 'header'
|
|
}
|
|
}
|
|
|
|
api_bp = Blueprint('api', __name__, url_prefix='/api')
|
|
api_v1 = Api(api_bp, prefix="/v1", version='0.1', title='Vue Test API',
|
|
description='The Vue Test API', doc='/v1/doc/', authorizations=api_authorizations, security='bearerAuth')
|
|
|
|
api_user = Namespace('user', description="User management namespace", authorizations=api_authorizations)
|
|
api_group = Namespace('group', description="Group management namespace", authorizations=api_authorizations)
|
|
api_permissions = Namespace('permissions', description="Permissions management namespace", authorizations=api_authorizations)
|
|
api_room = Namespace('room', description="Room management namespace", authorizations=api_authorizations)
|
|
api_recorder = Namespace('recorder', description="Recorder management namespace", authorizations=api_authorizations)
|
|
api_state = Namespace('state', description="Object state management namespace", authorizations=api_authorizations)
|
|
api_virtual_command = Namespace('virtual_command', description="Virtual command namespace",
|
|
authorizations=api_authorizations)
|
|
api_cron_job = Namespace('cron_job', description="Cron job namespace",
|
|
authorizations=api_authorizations)
|
|
api_control = Namespace('control', description="Control namespace",
|
|
authorizations=api_authorizations)
|
|
|
|
api_v1.add_namespace(api_user)
|
|
api_v1.add_namespace(api_group)
|
|
api_v1.add_namespace(api_permissions)
|
|
api_v1.add_namespace(api_room)
|
|
api_v1.add_namespace(api_recorder)
|
|
api_v1.add_namespace(api_state)
|
|
api_v1.add_namespace(api_virtual_command)
|
|
api_v1.add_namespace(api_cron_job)
|
|
api_v1.add_namespace(api_control)
|
|
|
|
auth_api_bp = Blueprint('auth_api', __name__, url_prefix='/api/auth')
|
|
auth_api_v1 = Api(auth_api_bp, prefix="/v1", version='0.1', title='Auth API',
|
|
description='Auth API', doc='/v1/doc/', authorizations=api_authorizations, security='bearerAuth')
|
|
|
|
auth_api_providers_ns = Namespace('providers')
|
|
auth_api_register_ns = Namespace('register')
|
|
auth_api_v1.add_namespace(auth_api_providers_ns)
|
|
auth_api_v1.add_namespace(auth_api_register_ns)
|
|
# user_api_bp = Blueprint('user_api', __name__, url_prefix='/api/user')
|
|
# group_api_bp = Blueprint('group_api', __name__, url_prefix='/api/group')
|
|
|
|
from .example_api import *
|
|
from .auth_api import *
|
|
from .user_api import *
|
|
from .permission_api import *
|
|
from .group_api import *
|
|
from .room_api import *
|
|
from .recorder_api import *
|
|
from .state_api import *
|
|
from .control_api import *
|
|
from .virtual_command_api import *
|
|
|
|
|
|
# from .group_api import *
|
|
|
|
"""
|
|
@api_v1.errorhandler(InternalServerError)
|
|
def handle_500(e):
|
|
original = getattr(e, "original_exception", None)
|
|
|
|
if original is None:
|
|
# direct 500 error, such as abort(500)
|
|
api_v1.abort(500)
|
|
|
|
# wrapped unhandled error
|
|
#return render_template("500_unhandled.html", e=original), 500
|
|
api_v1.abort(500)
|
|
"""
|
|
|
|
@api_bp.route('/<path:path>')
|
|
def catch_all_api(path):
|
|
"""
|
|
Default 404 response for undefined paths in API.
|
|
:param path:
|
|
:return:
|
|
"""
|
|
abort(404)
|