Spaces:
Sleeping
Sleeping
Commit
·
f73ccd7
1
Parent(s):
4a30677
add security
Browse files
main.py
CHANGED
@@ -17,6 +17,18 @@ app = FastAPI()
|
|
17 |
image_size = 256
|
18 |
hf_token = os.environ.get("api_read")
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
print(hf_token)
|
21 |
|
22 |
models_locations = [
|
|
|
17 |
image_size = 256
|
18 |
hf_token = os.environ.get("api_read")
|
19 |
|
20 |
+
VALID_API_KEYS = os.environ.get("api_key")
|
21 |
+
|
22 |
+
|
23 |
+
@app.middleware("http")
|
24 |
+
async def verify_api_key(request, call_next):
|
25 |
+
api_key = request.headers.get("x-api-key")
|
26 |
+
if api_key not in VALID_API_KEYS:
|
27 |
+
raise HTTPException(status_code=403, detail="Unauthorized")
|
28 |
+
response = await call_next(request)
|
29 |
+
return response
|
30 |
+
|
31 |
+
|
32 |
print(hf_token)
|
33 |
|
34 |
models_locations = [
|