Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable debug route by default #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions backend/maelstro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Main backend app setup
"""

import os
from typing import Annotated, Any
from fastapi import (
FastAPI,
Expand All @@ -26,6 +27,8 @@
)
from maelstro.common.models import SearchQuery

DEBUG = os.getenv("DEBUG", "False").lower() == "true"


app = FastAPI(root_path="/maelstro-backend")
setup_exception_handlers(app)
Expand Down Expand Up @@ -65,45 +68,46 @@ def user_page(
}


# pylint: disable=fixme
# TODO: deactivate for prod
@app.head("/debug")
@app.get("/debug")
@app.put("/debug")
@app.post("/debug")
@app.delete("/debug")
@app.options("/debug")
@app.patch("/debug")
async def debug_page(request: Request) -> dict[str, Any]:
"""
Display details of query including headers.
This may be useful in development to check all the headers provided by the gateway.
This entrypoint should be deactivated in prod.
"""
return {
**{
k: str(request.get(k))
for k in [
"method",
"type",
"asgi",
"http_version",
"server",
"client",
"scheme",
"url",
"base_url",
"root_path",
]
},
"data": await request.body(),
"headers": dict(request.headers),
"query_params": request.query_params.multi_items(),
}
if DEBUG:

@app.head("/debug")
@app.get("/debug")
@app.put("/debug")
@app.post("/debug")
@app.delete("/debug")
@app.options("/debug")
@app.patch("/debug")
async def debug_page(request: Request) -> dict[str, Any]:
"""
Display details of query including headers.
This may be useful in development to check all the headers provided by the gateway.
This entrypoint should be deactivated in prod.
"""
return {
**{
k: str(request.get(k))
for k in [
"method",
"type",
"asgi",
"http_version",
"server",
"client",
"scheme",
"url",
"base_url",
"root_path",
]
},
"data": await request.body(),
"headers": dict(request.headers),
"query_params": request.query_params.multi_items(),
}


@app.get("/check_config")
def check_config(check_credentials: bool = True) -> dict[str, bool]:
# pylint: disable=fixme
# TODO: implement check of all servers configured in the config file
return {"test_conf.yaml": True, "check_credentials": check_credentials}

Expand Down