37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from datetime import datetime
|
|
|
|
from flask import redirect, url_for
|
|
from flask.views import MethodView
|
|
|
|
from ..app import Application
|
|
from ..config import APISettings
|
|
from ..models.interface import ApiVersionGet, HealthGet, HealthStatus, OpenAPIGet
|
|
from . import interface_routes as blp
|
|
|
|
APP = Application.get_instance()
|
|
|
|
@blp.route("/health")
|
|
class ApiVersion(MethodView):
|
|
@blp.doc(summary="Returns the status and alive-time of the server")
|
|
@blp.response(200, HealthGet, description="Successful operation")
|
|
def get(self):
|
|
response = {
|
|
"alive_since": datetime.strftime(APP.alive_since, "%d.%m.%Y %H:%M:%S"),
|
|
"alive_for": str(datetime.now() - APP.alive_since),
|
|
"status": HealthStatus.OK
|
|
}
|
|
return response
|
|
|
|
@blp.route("/openapi")
|
|
class ApiVersion(MethodView):
|
|
@blp.doc(summary="Get the OpenAPI spec as a JSON.")
|
|
@blp.response(200, OpenAPIGet, description="Successful operation")
|
|
def get(self):
|
|
return redirect(url_for('api-docs.openapi_json'))
|
|
|
|
@blp.route("/version")
|
|
class ApiVersion(MethodView):
|
|
@blp.doc(summary="Get the REST interface version identification.")
|
|
@blp.response(200, ApiVersionGet, description="Successful operation")
|
|
def get(self):
|
|
return { "version": APISettings.API_VERSION }
|