fires: resolve FIRMS_MAP_KEY from Postgres keystore, not just env
All checks were successful
build-and-deploy / build (push) Successful in 1m40s
All checks were successful
build-and-deploy / build (push) Successful in 1m40s
Key saved via the dashboard Keys page sat unused in api_keys while ingest_fires only checked the env var. Now env first, keystore fallback, picked up on next poll without a restart.
This commit is contained in:
parent
b1c611d4c4
commit
e6648ec1ed
2 changed files with 72 additions and 6 deletions
|
|
@ -25,12 +25,14 @@ import csv
|
|||
import io
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import httpx
|
||||
import nats
|
||||
|
||||
from config import FIRMS_MAP_KEY, FIRMS_DATASET, FIRMS_BBOX, FIRMS_TIMEOUT, NATS_URL
|
||||
from config import FIRMS_DATASET, FIRMS_BBOX, FIRMS_TIMEOUT, NATS_URL
|
||||
from keystore import get_api_key
|
||||
|
||||
logger = logging.getLogger("osint.firms")
|
||||
|
||||
|
|
@ -159,16 +161,21 @@ async def ingest_fires(bbox: str | None = None) -> int:
|
|||
warning when FIRMS_MAP_KEY is not set, so the ingester keeps running for
|
||||
the other sources.
|
||||
"""
|
||||
if not FIRMS_MAP_KEY:
|
||||
# Key resolution: env var first (12-factor), then the shared Postgres
|
||||
# api_keys table so a key saved via the dashboard Keys page is picked up
|
||||
# on the next poll without a restart.
|
||||
map_key = os.getenv("FIRMS_MAP_KEY", "") or await get_api_key("FIRMS_MAP_KEY")
|
||||
if not map_key:
|
||||
logger.warning(
|
||||
"FIRMS_MAP_KEY not set — fire ingest disabled. "
|
||||
"Get a free key at https://firms.modaps.eosdis.nasa.gov/api/map_key_info/"
|
||||
"Set it in the dashboard Keys page or .env. "
|
||||
"Free key: https://firms.modaps.eosdis.nasa.gov/api/map_key_info/"
|
||||
)
|
||||
return 0
|
||||
|
||||
area = bbox or FIRMS_BBOX
|
||||
url = FIRMS_AREA_CSV.format(
|
||||
key=FIRMS_MAP_KEY, dataset=FIRMS_DATASET, bbox=area
|
||||
key=map_key, dataset=FIRMS_DATASET, bbox=area
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient(timeout=FIRMS_TIMEOUT) as client:
|
||||
|
|
|
|||
Loading…
Reference in a new issue