True up.
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
# packetserver/http/server.py
|
||||
from fastapi import FastAPI, Depends, HTTPException, status
|
||||
from fastapi import FastAPI, Depends, HTTPException, status, Query
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from starlette.requests import Request
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from persistent.mapping import PersistentMapping
|
||||
import persistent.list
|
||||
|
||||
# No database module needed – get_db_connection is provided by the runner
|
||||
# get_http_user logic inlined directly in the dependency (simple and avoids module)
|
||||
|
||||
from ..database import get_db_connection # reuse existing helper if available
|
||||
from .database import get_http_user
|
||||
from .auth import HttpUser
|
||||
|
||||
app = FastAPI(
|
||||
@@ -24,10 +29,22 @@ templates = Jinja2Templates(directory="packetserver/http/templates")
|
||||
|
||||
security = HTTPBasic()
|
||||
|
||||
|
||||
async def get_current_http_user(credentials: HTTPBasicCredentials = Depends(security)):
|
||||
db = get_db_connection() # your existing way to get the open DB
|
||||
user: HttpUser | None = get_http_user(db, credentials.username)
|
||||
# get_db_connection is injected by the standalone runner
|
||||
conn = get_db_connection()
|
||||
root = conn.root()
|
||||
|
||||
# Inline httpUsers mapping access (replaces get_http_user from nonexistent database.py)
|
||||
http_users = root.get("httpUsers")
|
||||
if http_users is None:
|
||||
# No users yet – auth fails
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid username or password",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
|
||||
user: HttpUser | None = http_users.get(credentials.username.upper())
|
||||
|
||||
if not user:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in New Issue
Block a user