mirror of
https://gitlab.sectorq.eu/jaydee/api_server.git
synced 2026-09-17 02:12:55 +02:00
Initial commit
This commit is contained in:
+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}
|
||||||
Reference in New Issue
Block a user