mirror of
https://gitlab.sectorq.eu/jaydee/api_server.git
synced 2026-11-01 14:07:06 +01:00
Initial commit
This commit is contained in:
commit
8799190d24
5 files changed
+30
No files matched your search
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import os
|
||||||
|
from fastapi import HTTPException, Depends
|
||||||
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||||
|
|
||||||
|
security = HTTPBearer()
|
||||||
|
|
||||||
|
API_TOKEN = os.getenv("API_TOKEN", "mytoken")
|
||||||
|
|
||||||
|
def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
||||||
|
if credentials.credentials != API_TOKEN:
|
||||||
|
raise HTTPException(status_code=401, detail="Invalid token")
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
from fastapi import FastAPI, Depends
|
||||||
|
from app.auth import verify_token
|
||||||
|
from app.scripts import script1, script2
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def root():
|
||||||
|
return {"status": "API running"}
|
||||||
|
|
||||||
|
@app.post("/script1")
|
||||||
|
def run_script1(auth=Depends(verify_token)):
|
||||||
|
result = script1.run()
|
||||||
|
return {"result": result}
|
||||||
|
|
||||||
|
@app.post("/script2")
|
||||||
|
def run_script2(auth=Depends(verify_token)):
|
||||||
|
result = script2.run()
|
||||||
|
return {"result": result}
|
||||||
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user