Spaces:
Sleeping
Sleeping
krishnachoudhary-hclguvi commited on
Add toggleable API auth for hackathon bot evaluation
Browse files
config.py
CHANGED
|
@@ -88,7 +88,13 @@ API_ACCESS_KEY = (
|
|
| 88 |
os.getenv("API_KEY")
|
| 89 |
)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
def is_api_key_valid(key: str) -> bool:
|
|
|
|
|
|
|
| 92 |
return bool(API_ACCESS_KEY and key and key.strip() == API_ACCESS_KEY)
|
| 93 |
|
| 94 |
# Flag to check if Gemini is configured
|
|
|
|
| 88 |
os.getenv("API_KEY")
|
| 89 |
)
|
| 90 |
|
| 91 |
+
# Competition/deployment toggle:
|
| 92 |
+
# When false, endpoints are public and evaluators can call APIs without auth headers.
|
| 93 |
+
REQUIRE_API_KEY = os.getenv("REQUIRE_API_KEY", "false").strip().lower() == "true"
|
| 94 |
+
|
| 95 |
def is_api_key_valid(key: str) -> bool:
|
| 96 |
+
if not REQUIRE_API_KEY:
|
| 97 |
+
return True
|
| 98 |
return bool(API_ACCESS_KEY and key and key.strip() == API_ACCESS_KEY)
|
| 99 |
|
| 100 |
# Flag to check if Gemini is configured
|
main.py
CHANGED
|
@@ -125,6 +125,9 @@ async def get_api_key(
|
|
| 125 |
authorization: Optional[str] = Header(None, alias="Authorization"),
|
| 126 |
) -> str:
|
| 127 |
"""Validate incoming API key from header or bearer auth."""
|
|
|
|
|
|
|
|
|
|
| 128 |
token = x_api_key
|
| 129 |
if authorization:
|
| 130 |
bearer_prefix = "Bearer "
|
|
|
|
| 125 |
authorization: Optional[str] = Header(None, alias="Authorization"),
|
| 126 |
) -> str:
|
| 127 |
"""Validate incoming API key from header or bearer auth."""
|
| 128 |
+
if not config.REQUIRE_API_KEY:
|
| 129 |
+
return "public"
|
| 130 |
+
|
| 131 |
token = x_api_key
|
| 132 |
if authorization:
|
| 133 |
bearer_prefix = "Bearer "
|