From 5dcebab54556e7b5e67f9ea3db68b6e42b7deeda Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 2 Mar 2024 21:49:39 +0100 Subject: [PATCH] Allow enabling debug endpoints with env var --- formula10/__init__.py | 3 +++ formula10/controller/admin_controller.py | 29 +++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/formula10/__init__.py b/formula10/__init__.py index d4bdc3f..9da6e30 100644 --- a/formula10/__init__.py +++ b/formula10/__init__.py @@ -4,9 +4,12 @@ from flask_sqlalchemy import SQLAlchemy # Load local ENV variables (can be set when calling the executable) ENABLE_TIMING: bool = False if os.getenv("DISABLE_TIMING") == "True" else True +ENABLE_DEBUG_ENDPOINTS: bool = True if os.getenv("ENABLE_DEBUG_ENDPOINTS") == "True" else False print("Running Formula10 with:") if not ENABLE_TIMING: print("- Disabled timing constraints") +if ENABLE_DEBUG_ENDPOINTS: + print("- Enabled debug endpoints") app: Flask = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///formula10.db" diff --git a/formula10/controller/admin_controller.py b/formula10/controller/admin_controller.py index 1e68ceb..8ced1b8 100644 --- a/formula10/controller/admin_controller.py +++ b/formula10/controller/admin_controller.py @@ -2,11 +2,12 @@ from typing import List from urllib.parse import unquote from flask import redirect, render_template, request from werkzeug import Response +from formula10.controller.error_controller import error_redirect from formula10.database.update_queries import update_race_result, update_user -from formula10.database.import_export import export_dynamic_data, reload_season_guess_result_data, reload_static_data +from formula10.database.import_export import export_dynamic_data, reload_dynamic_data, reload_season_guess_result_data, reload_static_data from formula10.domain.template_model import TemplateModel -from formula10 import app +from formula10 import ENABLE_DEBUG_ENDPOINTS, app @app.route("/save/all") @@ -15,11 +16,14 @@ def save() -> Response: return redirect("/") -# @app.route("/load/all") -# def load() -> Response: -# reload_static_data() -# reload_dynamic_data() -# return redirect("/") +@app.route("/load/all") +def load() -> Response: + if not ENABLE_DEBUG_ENDPOINTS: + return error_redirect("Debug endpoints are disabled!") + + reload_static_data() + reload_dynamic_data() + return redirect("/") @app.route("/load/static") @@ -34,10 +38,13 @@ def load_season_results() -> Response: return redirect("/") -# @app.route("/load/dynamic") -# def load_dynamic() -> Response: -# reload_dynamic_data() -# return redirect("/") +@app.route("/load/dynamic") +def load_dynamic() -> Response: + if not ENABLE_DEBUG_ENDPOINTS: + return error_redirect("Debug endpoints are disabled!") + + reload_dynamic_data() + return redirect("/") @app.route("/result")