From 7579215c4862fda1835840e1bbf85d1f78f8d45f Mon Sep 17 00:00:00 2001 From: IAmTomahawkx Date: Wed, 4 Oct 2023 20:00:42 -0700 Subject: [PATCH] lint the fallback --- mystbin/fallback/fallback.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/mystbin/fallback/fallback.py b/mystbin/fallback/fallback.py index 52661dfc..ba7071e8 100644 --- a/mystbin/fallback/fallback.py +++ b/mystbin/fallback/fallback.py @@ -1,11 +1,14 @@ -import os import json +import os + from aiohttp import web + app = web.Application() app.config = {} router = web.RouteTableDef() + def load_config(): if os.path.exists("./config.json"): with open("./config.json", "r") as __f: @@ -14,21 +17,24 @@ def load_config(): elif os.path.exists("../../config.json"): with open("../../config.json", "r") as __f: config = json.load(__f) - + else: raise RuntimeError("Cannot find config file") - + app.config = config + load_config() @router.post("/reload") async def router_reload(request: web.Request) -> web.Response: - if request.remote == "127.0.0.1" and "X-Forwarded-For" not in request.headers: # systemd reloads will only ever come from localhost using curl + if ( + request.remote == "127.0.0.1" and "X-Forwarded-For" not in request.headers + ): # systemd reloads will only ever come from localhost using curl load_config() return web.Response(body="Reloaded", status=200) - + raise web.HTTPPermanentRedirect("/") @@ -39,11 +45,12 @@ async def router_reload(request: web.Request) -> web.Response: @router.patch("/") @router.patch("/{pth:.*}") async def fallback_route(request: web.Request) -> web.Response | web.FileResponse: - if app.config.get("maintenance", False): # type: ignore + if app.config.get("maintenance", False): # type: ignore return web.FileResponse("maintenance.html") - + return web.FileResponse("service_failure.html") + app.add_routes(router) -web.run_app(app, port=app.config["site"]["fallback_port"]) # type: ignore \ No newline at end of file +web.run_app(app, port=app.config["site"]["fallback_port"]) # type: ignore