From 036b6de47647125ff0f4b41e580da845ab65a7c9 Mon Sep 17 00:00:00 2001 From: Linus Vogel Date: Sun, 21 Dec 2025 17:38:38 +0100 Subject: [PATCH] fix --- pillar_tool/__init__.py | 10 +++++++--- .../__pycache__/__init__.cpython-313.pyc | Bin 1231 -> 1900 bytes .../basicauth_backend.cpython-313.pyc | Bin 1703 -> 1885 bytes pillar_tool/middleware/basicauth_backend.py | 6 ++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pillar_tool/__init__.py b/pillar_tool/__init__.py index da7095d..8ea4286 100644 --- a/pillar_tool/__init__.py +++ b/pillar_tool/__init__.py @@ -13,14 +13,18 @@ def on_auth_error(request: Request, exc: Exception): return response +def on_general_error(request: Request, exc: Exception): + print("wtf?") + response = PlainTextResponse(str(exc), status_code=500) + app = FastAPI() app.add_middleware(AuthenticationMiddleware, backend=BasicAuthBackend(), on_error=on_auth_error) +app.exception_handler(Exception)(on_general_error) @app.get("/") async def root(): return {"message": "Hello World"} -@app.get("/pillar/") +@app.get("/pillar/{param}") async def pillar(param: str): - print(param) - return JSONResponse(content={}) + return JSONResponse(content={ "param": param }) diff --git a/pillar_tool/__pycache__/__init__.cpython-313.pyc b/pillar_tool/__pycache__/__init__.cpython-313.pyc index de3857e69a25badf8e145ea74773263c0905cdf1..6908bf3e34786b51474a493f8012e4958c6b2f97 100644 GIT binary patch delta 1014 zcmZ8f&rcIU6n?Y2g_gG4BJ>A^!%`HiF(A-}5Ub*W1U1&g4HwyjG-atZWw&{|MuRaG zG|`ix*=V>)q6fHf@c*z4B$`U&MGqPeCFSDHnJq2oB=39gee>nbdo%ON^;;AhUT+uB zm5a{hzVan8%*~L}`Pu6rcieK{^q@xqxl?h-PQ@D+WLE?p2q>Onx@^X$kSHWr9lFr3 z`0oytHUdS@38{#(dzzPkZk=n&PNU*YkY*kQ#n*~$^~h;mGnPFqh3t)-9NSB4|D(Qe zEEn5ypAv|3vY++b?lze1j-4s}y64;>RnJZNPRdG>w`9lKBT3f|k8WB7Jyw`ocLZtJ zWxeAP#SGUhZKH!CPpvUS;SDStPXZv5*1-}iFonGqnBHFV?R}Y(`Dsq$vJewetHL95 z`C9IX)+7z?^1cC(W=MAO+Y%Lxa_nBnbo5SN*!Sm{m0u)A>aeQAdnW+Rt=- z6rRC>;CeOu;`V`0`p~l_zYp&k72oBxISg49E)$Wc215+&Y69xIiGwr`TPc39xau1# zt~(_+=8~Qy8VX7^!w< zbj?)hfKEHNX@eC$9<8Ggx6elQbq1&ztjC{prtj|1*2s3EEKOA0lVxG@kHLCa_lP7F z3t7nP!5+g*V_r2)bre;jplgO|pv$W9qe1rZtFGC{8MR>MbPd`2V#FE{`ik9Zi(R~* z)|T=rR{5;jyb$&RV7G!2i%u@hnOxDA9_H1nI8Ha%0LDiOb)FDXgZ>)K)nND=T&cmu zA23_*5J>OlR2`_>?mJ?x?%_ysGh6op_1ia&m^*Y@uZ3vu7vMibpaOx7+&)OUeig;sqgJdCWWHN?1h6|x8h9{WQl39TPs8$|X6@(qkWy%O;aZ4dg7D(sOmt}RZTyn#(b;wgjc2R0T)ks0P67=Y9Y$uA)4BhTbdY)bME d7+KoI8^t?>n`J&SF*2%sW@cdG1GB)c1OPtWMSK7N diff --git a/pillar_tool/middleware/__pycache__/basicauth_backend.cpython-313.pyc b/pillar_tool/middleware/__pycache__/basicauth_backend.cpython-313.pyc index ea77e96d8d499456f02d65101103bc1ec0b9d125..db5ed0316beafd1c2a2a454c4597458f5b84bab7 100644 GIT binary patch delta 593 zcmX|7&1(}u6o0e3v)x_Y4KZS(@hfRcSXwKA1fhgN+zK)UJuHDj?O{olG_Xy|Y%183 zSm-?r9=sH9dQyZQJc{`T7INF@O(=o~AuV_kXA+YK@AuyC&HI}7&irm!W79N%3&}lh z>q_6sY!S|0g9|R&1Uj{dq6wF%%&oMk5KJ*qsY({;0@0{;7c!6sSH1zR@(fpG(Gh^^ zEo9@L!hK>Z{m#nGI8i(3?K;$N`kh|e3&PlN+k5+gUl0BM8e$ZR=Ebj;oih4RyXL6yRjEmw4Af<(Bo9imQ)VZ) zik8?2XLpJ`cgz)NL4df%1cVa`IED-93f@5U-t5UX=vCp1OT@|D7yCYKbZKWb=(bwz zPAk^uAy!eBcIMxkHWve@y~My+tL}B12Z6s%OPq>xhKn42%Lt(nm?KDxAae%65Q1|x Pg*H%>Ubz6_Oq%=yuhfG} delta 409 zcmcc1x15*nGcPX}0}#C6@yMLdJdsbr!wSfo$`H&D%;?Qf1fdy=7=e5yZzeD1B4#g^ zA{GS(2?iyGU}h5Q7JFF{N{O{R%;Iunn3GO|w=WRzq)uvweY zhEaf>fgzM5nA0kPfgzERfgyeJVx|g4uE{dY4NRImlh-mAPu60wV&t8i%Ceq~187X~ zrO8sPWsDq?C$g#t-4GUk!l!sa$>}nm^92s)A7A(<-(l5MkOiu1(sq_(T<0j}WWaEU zMF+?}WT5RV&3ssz*;#I~8kU}C(fIh{lEjkCWHa y^HWN5QtgU#fLx$=8Hzz}{lLt~$atH9_cjCna|Zt}Y(k7Kj2FapzA}IqVC?`>KvydO diff --git a/pillar_tool/middleware/basicauth_backend.py b/pillar_tool/middleware/basicauth_backend.py index 6a35025..726fe6c 100644 --- a/pillar_tool/middleware/basicauth_backend.py +++ b/pillar_tool/middleware/basicauth_backend.py @@ -1,7 +1,8 @@ import base64 import binascii +import hypercorn.logging -from starlette.authentication import AuthenticationBackend, AuthenticationError +from starlette.authentication import AuthenticationBackend, AuthenticationError, AuthCredentials, SimpleUser class BasicAuthBackend(AuthenticationBackend): @@ -18,8 +19,9 @@ class BasicAuthBackend(AuthenticationBackend): except (ValueError, UnicodeDecodeError, binascii.Error): raise AuthenticationError('Invalid basic auth credentials') + username, _, password = decoded.partition(":") if username == 'admin' and password == 'password': - return None + return AuthCredentials(["authenticated"]), SimpleUser('admin') raise AuthenticationError('Invalid basic auth credentials')