diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7664798..f9b803d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ stages: - quality assurance -pylint: +backend-pylint: stage: quality assurance image: python:3.11.4-buster before_script: diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff5ea15 --- /dev/null +++ b/.vscode/settings.json @@ -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": [] +} \ No newline at end of file diff --git a/backend/.pylintrc b/backend/.pylintrc index b12f0a2..d3d7cae 100644 --- a/backend/.pylintrc +++ b/backend/.pylintrc @@ -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, diff --git a/backend/src/app.py b/backend/src/app.py index 719dc90..d54b818 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -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() diff --git a/backend/src/routes/__init__.py b/backend/src/routes/__init__.py index b3dc1ab..ce5e1ae 100644 --- a/backend/src/routes/__init__.py +++ b/backend/src/routes/__init__.py @@ -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 diff --git a/backend/src/routes/health.py b/backend/src/routes/health.py new file mode 100644 index 0000000..39d8b1c --- /dev/null +++ b/backend/src/routes/health.py @@ -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 diff --git a/backend/src/routes/openapi.py b/backend/src/routes/openapi.py new file mode 100644 index 0000000..55ade67 --- /dev/null +++ b/backend/src/routes/openapi.py @@ -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')) diff --git a/backend/src/routes/apiversion.py b/backend/src/routes/version.py similarity index 100% rename from backend/src/routes/apiversion.py rename to backend/src/routes/version.py