True up.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.idea*
|
||||
.venv*
|
||||
*__pycache__*
|
||||
build/*
|
||||
*.egg-info/*
|
||||
|
||||
@@ -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(
|
||||
|
||||
8
setup.py
8
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",
|
||||
],
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user