Add JSON parser for API key lists in coordinator config
This commit is contained in:
@@ -61,6 +61,21 @@ class Settings(BaseSettings):
|
||||
miner_api_keys: list[str] = []
|
||||
admin_api_keys: list[str] = []
|
||||
|
||||
@field_validator("client_api_keys", "miner_api_keys", "admin_api_keys", mode="before")
|
||||
@classmethod
|
||||
def parse_api_keys(cls, v: str | list[str]) -> list[str]:
|
||||
import json
|
||||
if isinstance(v, str):
|
||||
try:
|
||||
parsed = json.loads(v)
|
||||
if isinstance(parsed, list):
|
||||
return parsed
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
# Fall back to comma-separated
|
||||
return [k.strip() for k in v.split(",") if k.strip()]
|
||||
return v
|
||||
|
||||
@field_validator("client_api_keys", "miner_api_keys", "admin_api_keys")
|
||||
@classmethod
|
||||
def validate_api_keys(cls, v: list[str]) -> list[str]:
|
||||
|
||||
@@ -47,9 +47,9 @@ SECRET_KEY=production-secret-key-change-me-in-production
|
||||
JWT_SECRET=production-jwt-secret-32-chars-long
|
||||
BLOCKCHAIN_API_KEY=production-api-key-change-me
|
||||
COORDINATOR_API_KEY=admin_prod_key_use_real_value
|
||||
CLIENT_API_KEYS='["client_prod_key_use_real_value"]'
|
||||
MINER_API_KEYS='["miner_prod_key_use_real_value"]'
|
||||
ADMIN_API_KEYS='["admin_prod_key_use_real_value"]'
|
||||
CLIENT_API_KEYS=["client_prod_key_use_real_value"]
|
||||
MINER_API_KEYS=["miner_prod_key_use_real_value"]
|
||||
ADMIN_API_KEYS=["admin_prod_key_use_real_value"]
|
||||
HMAC_SECRET=change_this_to_a_32_byte_random_secret
|
||||
|
||||
# =========================
|
||||
|
||||
Reference in New Issue
Block a user