Skip to content

Commit b7377d5

Browse files
committed
add config defaults
1 parent 2adf645 commit b7377d5

File tree

2 files changed

+18
-4
lines changed
  • stac_fastapi
    • elasticsearch/stac_fastapi/elasticsearch
    • opensearch/stac_fastapi/opensearch

2 files changed

+18
-4
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ def _es_config() -> Dict[str, Any]:
1616
scheme = "https" if use_ssl else "http"
1717

1818
# Configure the hosts parameter with the correct scheme
19+
es_hosts = os.getenv("ES_HOST", "localhost").strip() # Default to localhost if ES_HOST is not set
20+
es_port = os.getenv("ES_PORT", "9200") # Default to 9200 if ES_PORT is not set
21+
22+
# Validate ES_HOST
23+
if not es_hosts:
24+
raise ValueError("ES_HOST environment variable is empty or invalid.")
25+
1926
hosts = [
20-
f"{scheme}://{host.strip()}:{os.getenv('ES_PORT')}"
21-
for host in os.getenv("ES_HOST").split(",")
27+
f"{scheme}://{host.strip()}:{es_port}"
28+
for host in es_hosts.split(",")
2229
]
2330

2431
# Initialize the configuration dictionary

stac_fastapi/opensearch/stac_fastapi/opensearch/config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ def _es_config() -> Dict[str, Any]:
1515
scheme = "https" if use_ssl else "http"
1616

1717
# Configure the hosts parameter with the correct scheme
18+
es_hosts = os.getenv("ES_HOST", "localhost").strip() # Default to localhost if ES_HOST is not set
19+
es_port = os.getenv("ES_PORT", "9200") # Default to 9200 if ES_PORT is not set
20+
21+
# Validate ES_HOST
22+
if not es_hosts:
23+
raise ValueError("ES_HOST environment variable is empty or invalid.")
24+
1825
hosts = [
19-
f"{scheme}://{host.strip()}:{os.getenv('ES_PORT')}"
20-
for host in os.getenv("ES_HOST").split(",")
26+
f"{scheme}://{host.strip()}:{es_port}"
27+
for host in es_hosts.split(",")
2128
]
2229

2330
# Initialize the configuration dictionary

0 commit comments

Comments
 (0)