New endpoints

This commit is contained in:
Firq 2023-09-26 22:54:40 +02:00
parent e2a1edcde3
commit 602677eff7
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
8 changed files with 70 additions and 9 deletions

View file

@ -1,7 +1,7 @@
stages:
- quality assurance
pylint:
backend-pylint:
stage: quality assurance
image: python:3.11.4-buster
before_script:

12
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,12 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/__pycache__": true
},
"hide-files.files": []
}

View file

@ -1,11 +1,10 @@
[MAIN]
disable=
too-many-instance-attributes,
line-too-long,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
too-few-public-methods,
too-many-arguments,
missing-module-docstring,
missing-function-docstring,
missing-class-docstring,
too-few-public-methods,
line-too-long,
too-many-instance-attributes,

View file

@ -1,5 +1,6 @@
# pylint: disable=too-few-public-methods
from datetime import datetime
from flask import Flask
from flask_smorest import Api
from config.api_settings import DefaultSettings
@ -20,6 +21,7 @@ class Application:
app = Flask(__name__)
app.config.from_object(DefaultSettings)
api = None
alive_since = None
@staticmethod
def get_instance():
@ -32,3 +34,4 @@ class Application:
raise IsSingletonException("This class is a singleton")
Application.__instance = self
self.api = Api(self.app)
self.alive_since = datetime.now()

View file

@ -1,6 +1,6 @@
# pylint: disable=wrong-import-position,cyclic-import
from flask_smorest import Blueprint
routes = Blueprint("support-organizer", "support-organizer", url_prefix="/", description="")
routes = Blueprint("interface", "interface", url_prefix="/", description="")
from . import apiversion # avoids circular imports problem
from . import version, openapi, health # avoids circular imports problem

View file

@ -0,0 +1,32 @@
from datetime import datetime
from enum import Enum
from flask.views import MethodView
import marshmallow as ma
from app import Application
from . import routes as blp
instance = Application.get_instance()
class HealthStatus(Enum):
OK = 0
WARNING = 1
ERROR = 2
CRITICAL = 3
class HealthGet(ma.Schema):
alive_since = ma.fields.String()
alive_for = ma.fields.String()
status = ma.fields.Enum(HealthStatus, type=ma.fields.String)
@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(instance.alive_since, "%d.%m.%Y %H:%M:%S"),
"alive_for": str(datetime.now() - instance.alive_since),
"status": HealthStatus.OK
}
return response

View file

@ -0,0 +1,15 @@
from flask import redirect, url_for
from flask.views import MethodView
import marshmallow as ma
from . import routes as blp
class OpenAPIGet(ma.Schema):
pass
@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'))