Commit 9f24db3c authored by nanahira's avatar nanahira

add TOKEN_SERVER

parent f3550054
Pipeline #17219 passed with stages
in 16 minutes and 14 seconds
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
```dockerfile ```dockerfile
#ENV TOKEN #ENV TOKEN
#ENV TOKEN_SERVER
#ENV SAVE_FILES="1" #ENV SAVE_FILES="1"
ENV DTYPE="float32" ENV DTYPE="float32"
......
...@@ -8,3 +8,6 @@ services: ...@@ -8,3 +8,6 @@ services:
- ./models:/app/models - ./models:/app/models
- ./main.py:/app/main.py:ro - ./main.py:/app/main.py:ro
- ./hydra_node:/app/hydra_node:ro - ./hydra_node:/app/hydra_node:ro
environment:
# TOKEN_SERVER: https://api.moecube.com/accounts/authUser
TOKEN: mycard
...@@ -26,11 +26,14 @@ import threading ...@@ -26,11 +26,14 @@ import threading
from PIL import Image from PIL import Image
from PIL.PngImagePlugin import PngInfo from PIL.PngImagePlugin import PngInfo
import json import json
import requests
genlock = threading.Lock() genlock = threading.Lock()
TOKEN = os.getenv("TOKEN", None) TOKEN = os.getenv("TOKEN", None)
print(f"Starting Hydra Node HTTP TOKEN={TOKEN}") TOKEN_SERVER = os.getenv("TOKEN_SERVER", None)
print(f"Starting Hydra Node HTTP")
#Initialize model and config #Initialize model and config
model, config, model_hash = init_config_model() model, config, model_hash = init_config_model()
...@@ -56,6 +59,21 @@ def verify_token(req: Request): ...@@ -56,6 +59,21 @@ def verify_token(req: Request):
status_code=401, status_code=401,
detail="Unauthorized" detail="Unauthorized"
) )
if TOKEN_SERVER:
if "Authorization" not in req.headers:
raise HTTPException(
status_code=401,
detail="Unauthorized"
)
token = req.headers["Authorization"]
if token.startswith("Bearer "):
token = token[7:]
tokenAuthResult = requests.get(TOKEN_SERVER, headers={"Authorization": "Bearer "+token})
if tokenAuthResult.status_code >= 400:
raise HTTPException(
status_code=tokenAuthResult.status_code,
detail="Unauthorized"
)
return True return True
#Initialize fastapi #Initialize fastapi
app = FastAPI() app = FastAPI()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment