Update app.py
Browse files
app.py
CHANGED
|
@@ -70,18 +70,13 @@ def seed_api_keys_from_env():
|
|
| 70 |
Seed API keys from env var API_KEYS_SEED.
|
| 71 |
Accepts entries separated by commas, newlines, semicolons, or spaces.
|
| 72 |
Each entry must be 'owner:raw_key'. Example:
|
| 73 |
-
|
| 74 |
alice:MY_SUPER_KEY_1
|
| 75 |
bob:ANOTHER_KEY_2
|
| 76 |
-
|
| 77 |
-
or single-line:
|
| 78 |
-
alice:MY_SUPER_KEY_1,bob:ANOTHER_KEY_2
|
| 79 |
"""
|
| 80 |
seed = os.getenv("API_KEYS_SEED", "")
|
| 81 |
if not seed:
|
| 82 |
return
|
| 83 |
|
| 84 |
-
# Normalize separators into commas
|
| 85 |
normalized = seed.replace("\r", "\n")
|
| 86 |
for sep in ["\n", ";", " "]:
|
| 87 |
normalized = normalized.replace(sep, ",")
|
|
@@ -92,7 +87,6 @@ def seed_api_keys_from_env():
|
|
| 92 |
|
| 93 |
conn = get_db_connection()
|
| 94 |
try:
|
| 95 |
-
# Ensure schema exists
|
| 96 |
conn.execute(
|
| 97 |
"""
|
| 98 |
CREATE TABLE IF NOT EXISTS api_keys (
|
|
@@ -264,10 +258,8 @@ model = None
|
|
| 264 |
|
| 265 |
@app.on_event("startup")
|
| 266 |
async def on_startup():
|
| 267 |
-
# Init auth DB and seed any provided keys (optional)
|
| 268 |
init_db()
|
| 269 |
seed_api_keys_from_env()
|
| 270 |
-
|
| 271 |
# Load ML model
|
| 272 |
global model
|
| 273 |
try:
|
|
|
|
| 70 |
Seed API keys from env var API_KEYS_SEED.
|
| 71 |
Accepts entries separated by commas, newlines, semicolons, or spaces.
|
| 72 |
Each entry must be 'owner:raw_key'. Example:
|
|
|
|
| 73 |
alice:MY_SUPER_KEY_1
|
| 74 |
bob:ANOTHER_KEY_2
|
|
|
|
|
|
|
|
|
|
| 75 |
"""
|
| 76 |
seed = os.getenv("API_KEYS_SEED", "")
|
| 77 |
if not seed:
|
| 78 |
return
|
| 79 |
|
|
|
|
| 80 |
normalized = seed.replace("\r", "\n")
|
| 81 |
for sep in ["\n", ";", " "]:
|
| 82 |
normalized = normalized.replace(sep, ",")
|
|
|
|
| 87 |
|
| 88 |
conn = get_db_connection()
|
| 89 |
try:
|
|
|
|
| 90 |
conn.execute(
|
| 91 |
"""
|
| 92 |
CREATE TABLE IF NOT EXISTS api_keys (
|
|
|
|
| 258 |
|
| 259 |
@app.on_event("startup")
|
| 260 |
async def on_startup():
|
|
|
|
| 261 |
init_db()
|
| 262 |
seed_api_keys_from_env()
|
|
|
|
| 263 |
# Load ML model
|
| 264 |
global model
|
| 265 |
try:
|