From f58f669cefa7353f3d7123ffe59858bfb9745f52 Mon Sep 17 00:00:00 2001 From: Michael Woods Date: Sat, 20 Dec 2025 21:59:25 -0500 Subject: [PATCH] True up. --- .gitignore | 2 ++ packetserver/http/server.py | 29 +++++++++++++++++++++++------ setup.py | 8 ++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e87e0ea..4fa44ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea* .venv* *__pycache__* +build/* +*.egg-info/* diff --git a/packetserver/http/server.py b/packetserver/http/server.py index 9c9b6b3..2df7d9f 100644 --- a/packetserver/http/server.py +++ b/packetserver/http/server.py @@ -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( diff --git a/setup.py b/setup.py index 9865181..5304833 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,12 @@ setup( packages=find_packages(), include_package_data=True, install_requires=[ + "fastapi", + "uvicorn[standard]", + "jinja2", + "argon2-cffi", + "ZODB", + "ZEO", 'click', 'pyham_pe', 'msgpack', @@ -19,6 +25,8 @@ setup( 'console_scripts': [ 'packcli = packetserver.client.cli:cli', 'packcfg = packetserver.server.cli:config', + "packetserver-http-users = packetserver.runners.http_user_manager:main", + "packetserver-http-server = packetserver.runners.http_server:main", ], }, ) \ No newline at end of file