auth via DB
This commit is contained in:
+22
-6
@@ -1,8 +1,9 @@
|
||||
import html
|
||||
|
||||
from fastapi import APIRouter, Form
|
||||
from fastapi import APIRouter, Depends, Form, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
|
||||
from ..auth import require_user
|
||||
from ..config import (
|
||||
DEFAULT_APPFACTORY_HOST,
|
||||
DEFAULT_GITEA_ORG,
|
||||
@@ -20,7 +21,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def index():
|
||||
def index(request: Request, user=Depends(require_user)):
|
||||
apps = get_apps()
|
||||
|
||||
gitea_url = read_env_value("GITEA_URL", "")
|
||||
@@ -147,11 +148,12 @@ def index():
|
||||
</table>
|
||||
</div>
|
||||
""",
|
||||
user=user,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/new-app", response_class=HTMLResponse)
|
||||
def new_app_form():
|
||||
def new_app_form(request: Request, user=Depends(require_user)):
|
||||
return page(
|
||||
"Nová aplikace",
|
||||
"""
|
||||
@@ -183,11 +185,17 @@ def new_app_form():
|
||||
<p><a href="/portal">← Zpět</a></p>
|
||||
</div>
|
||||
""",
|
||||
user=user,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/new-app", response_class=HTMLResponse)
|
||||
def create_app(app_id: str = Form(...), app_name: str = Form(...), template: str = Form(...)):
|
||||
def create_app(
|
||||
app_id: str = Form(...),
|
||||
app_name: str = Form(...),
|
||||
template: str = Form(...),
|
||||
user=Depends(require_user),
|
||||
):
|
||||
if template != "python-fastapi":
|
||||
return HTMLResponse("Nepodporovaná šablona", status_code=400)
|
||||
|
||||
@@ -207,11 +215,12 @@ def create_app(app_id: str = Form(...), app_name: str = Form(...), template: str
|
||||
],
|
||||
extra_link=f"/apps/{html.escape(app_id)}/docs",
|
||||
extra_label="Otevřít Swagger",
|
||||
user=user,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/delete-app", response_class=HTMLResponse)
|
||||
def delete_app(app_id: str = Form(...)):
|
||||
def delete_app(app_id: str = Form(...), user=Depends(require_user)):
|
||||
result = run_command([DELETE_APP_SCRIPT, app_id])
|
||||
status = "OK" if result.returncode == 0 else "FAILED"
|
||||
|
||||
@@ -219,11 +228,17 @@ def delete_app(app_id: str = Form(...)):
|
||||
title=f"Smazání aplikace: {status}",
|
||||
back_url="/portal",
|
||||
sections=[("Výstup", result.stdout), ("Chyba", result.stderr)],
|
||||
user=user,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/update-resources", response_class=HTMLResponse)
|
||||
def update_resources(app_id: str = Form(...), memory: str = Form(""), cpus: str = Form("")):
|
||||
def update_resources(
|
||||
app_id: str = Form(...),
|
||||
memory: str = Form(""),
|
||||
cpus: str = Form(""),
|
||||
user=Depends(require_user),
|
||||
):
|
||||
memory = memory.strip()
|
||||
cpus = cpus.strip()
|
||||
|
||||
@@ -250,4 +265,5 @@ def update_resources(app_id: str = Form(...), memory: str = Form(""), cpus: str
|
||||
("Výstup nasazení", deploy_result.stdout),
|
||||
("Chyba nasazení", deploy_result.stderr),
|
||||
],
|
||||
user=user,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user