alexfremont commited on
Commit
8f60eb0
·
1 Parent(s): 1ef2263

change key verif

Browse files
Files changed (1) hide show
  1. main.py +7 -4
main.py CHANGED
@@ -24,15 +24,18 @@ VALID_API_KEYS = os.environ.get("api_key")
24
  @app.middleware("http")
25
  async def verify_api_key(request, call_next):
26
  logging.info(f"Received request: {request.method} {request.url}")
27
- api_key = request.headers.get("x-api-key")
28
- if api_key is None or api_key not in VALID_API_KEYS:
29
- logging.warning("Unauthorized access attempt.")
30
- raise HTTPException(status_code=403, detail="Unauthorized")
 
 
31
  response = await call_next(request)
32
  return response
33
 
34
 
35
  print(hf_token)
 
36
 
37
  models_locations = [
38
  {
 
24
  @app.middleware("http")
25
  async def verify_api_key(request, call_next):
26
  logging.info(f"Received request: {request.method} {request.url}")
27
+ if request.url.path == "/predict":
28
+ api_key = request.headers.get("x-api-key")
29
+ if api_key is None or api_key not in VALID_API_KEYS:
30
+ logging.warning("Unauthorized access attempt.")
31
+ raise HTTPException(status_code=403, detail="Unauthorized")
32
+
33
  response = await call_next(request)
34
  return response
35
 
36
 
37
  print(hf_token)
38
+ print(VALID_API_KEYS)
39
 
40
  models_locations = [
41
  {