cazyundee commited on
Commit
3fee5c9
·
verified ·
1 Parent(s): bb7d60b

fix: read the shared secret per request; add a names-only env diagnostic

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -912,6 +912,7 @@ def _patched_create_app(blocks, **kwargs):
912
  @fa_app.middleware("http")
913
  async def _respite_key_gate(request, call_next):
914
  if request.url.path.startswith(_PROTECTED_PREFIXES):
 
915
  if not _SPACE_KEY:
916
  return JSONResponse(
917
  {"error": "service not configured"}, status_code=503
@@ -921,7 +922,7 @@ def _patched_create_app(blocks, **kwargs):
921
  return JSONResponse({"error": "unauthorized"}, status_code=401)
922
  return await call_next(request)
923
 
924
- _log(f"compute routes key gate installed (key {'set' if _SPACE_KEY else 'MISSING'})")
925
  except Exception as _ke:
926
  _log(f"compute routes key gate FAILED to install: {_ke}")
927
 
@@ -954,6 +955,14 @@ def _patched_create_app(blocks, **kwargs):
954
  except Exception as _ce:
955
  _log(f"respite CORS gate not installed: {_ce}")
956
 
 
 
 
 
 
 
 
 
957
  _log("Routes injected via create_app monkey-patch")
958
  return fa_app
959
 
 
912
  @fa_app.middleware("http")
913
  async def _respite_key_gate(request, call_next):
914
  if request.url.path.startswith(_PROTECTED_PREFIXES):
915
+ _SPACE_KEY = os.environ.get("RESPIRE_SPACE_KEY", "")
916
  if not _SPACE_KEY:
917
  return JSONResponse(
918
  {"error": "service not configured"}, status_code=503
 
922
  return JSONResponse({"error": "unauthorized"}, status_code=401)
923
  return await call_next(request)
924
 
925
+ _log("compute routes key gate installed")
926
  except Exception as _ke:
927
  _log(f"compute routes key gate FAILED to install: {_ke}")
928
 
 
955
  except Exception as _ce:
956
  _log(f"respite CORS gate not installed: {_ce}")
957
 
958
+ @fa_app.get("/respite/_envcheck")
959
+ def _envcheck():
960
+ """TEMPORARY diagnostic. Reports whether expected env NAMES are
961
+ present in the container. Values are never included. Removed once
962
+ the cause of the missing secret is confirmed."""
963
+ names = ["RESPIRE_SPACE_KEY", "GOOGLE_API_KEY", "PUBLICAI_API_KEY", "HF_TOKEN", "SPACE_ID"]
964
+ return JSONResponse({n: bool(os.environ.get(n)) for n in names})
965
+
966
  _log("Routes injected via create_app monkey-patch")
967
  return fa_app
968