Add JSON parser for API key lists in coordinator config
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Waiting to run
Integration Tests / test-service-integration (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled

This commit is contained in:
aitbc
2026-04-15 11:36:33 +02:00
parent 20b96881c4
commit 13080c76b4
2 changed files with 18 additions and 3 deletions

View File

@@ -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]:

View File

@@ -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
# =========================