Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions alert_system/etl/base/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@ def _extract_event_items(self, extraction_run_id: str, is_past_event: bool = Fal
logger.warning(f"Failed to fetch events: {e}")
raise

first_event_item = next(event_items, None)
if not first_event_item:
msg = f"No event items found for extraction_run_id={extraction_run_id}"
logger.warning(msg)
raise ValueError(msg)
event_items = list(event_items)
if not event_items:
logger.warning(f"No event items found for extraction_run_id={extraction_run_id}")
return

for event_item in event_items:
self.process_event_item(event_item=event_item, extraction_run_id=extraction_run_id, is_past_event=is_past_event)
Expand Down
20 changes: 19 additions & 1 deletion alert_system/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
from typing import Dict, Generator, Optional

import httpx
from django.conf import settings


def _remap_stac_url(url: str) -> str:
"""
Replace the external STAC base URL prefix with the internal cluster URL.

Requires both EOAPI_STAC_EXTERNAL_URL and EOAPI_STAC_INTERNAL_URL to be set.
"""
external_base = getattr(settings, "EOAPI_STAC_EXTERNAL_URL", None)
internal_base = getattr(settings, "EOAPI_STAC_INTERNAL_URL", None)
if not external_base or not internal_base:
return url
external_base = external_base.rstrip("/")
internal_base = internal_base.rstrip("/")
if url.startswith(external_base):
return internal_base + url[len(external_base) :]
return url


def build_search_params(
Expand Down Expand Up @@ -57,7 +75,7 @@ def build_stac_search(


def fetch_stac_data(url: str, payload: dict | None = None, timeout: int | None = 60):
response = httpx.get(url=url, params=payload, timeout=timeout)
response = httpx.get(url=_remap_stac_url(url), params=payload, timeout=timeout)
response.raise_for_status()
return response.json()

Expand Down
6 changes: 6 additions & 0 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
# PowerBI
POWERBI_WORKSPACE_ID=(str, None),
POWERBI_DATASET_IDS=(str, None),
# Alert system - remap external STAC related-item URLs to internal cluster URLs
EOAPI_STAC_EXTERNAL_URL=(str, None), # e.g. https://montandon-eoapi.ifrc.org/stac
EOAPI_STAC_INTERNAL_URL=(str, None), # e.g. http://montandon-eoapi-stac.montandon-eoapi.svc.cluster.local:8080
)


Expand All @@ -174,6 +177,9 @@ def parse_domain(*env_keys: str) -> str:
return domain.strip("/")


EOAPI_STAC_EXTERNAL_URL = env("EOAPI_STAC_EXTERNAL_URL")
EOAPI_STAC_INTERNAL_URL = env("EOAPI_STAC_INTERNAL_URL")

GO_API_URL = parse_domain("API_FQDN")
GO_WEB_URL = parse_domain("FRONTEND_URL")
# NOTE: Used in local development to point to the frontend service from within go-api container
Expand Down
Loading