Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/setup-pyth…
Browse files Browse the repository at this point in the history
…on-5
  • Loading branch information
jonhealy1 authored Dec 9, 2023
2 parents 8ea5140 + 67f5f03 commit 01f4ffa
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
services:

elasticsearch_8_svc:
image: docker.elastic.co/elasticsearch/elasticsearch:8.10.4
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
env:
cluster.name: stac-cluster
node.name: es01
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- Elasticsearch drivers from 7.17.9 to 8.11.0 [#169](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/169)

### Fixed

- Exclude unset fields in search response [#166](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:

elasticsearch:
container_name: es-container
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-8.10.4}
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-8.11.0}
environment:
ES_JAVA_OPTS: -Xms512m -Xmx1g
volumes:
Expand Down
4 changes: 2 additions & 2 deletions stac_fastapi/elasticsearch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"stac-fastapi.types==2.4.8",
"stac-fastapi.api==2.4.8",
"stac-fastapi.extensions==2.4.8",
"elasticsearch[async]==7.17.9",
"elasticsearch-dsl==7.4.1",
"elasticsearch[async]==8.11.0",
"elasticsearch-dsl==8.11.0",
"pystac[validation]",
"uvicorn",
"orjson",
Expand Down
35 changes: 24 additions & 11 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
"""API configuration."""
import os
import ssl
from typing import Any, Dict, Set

from elasticsearch import AsyncElasticsearch, Elasticsearch # type: ignore
from stac_fastapi.types.config import ApiSettings


def _es_config() -> Dict[str, Any]:
# Determine the scheme (http or https)
use_ssl = os.getenv("ES_USE_SSL", "true").lower() == "true"
scheme = "https" if use_ssl else "http"

# Configure the hosts parameter with the correct scheme
hosts = [f"{scheme}://{os.getenv('ES_HOST')}:{os.getenv('ES_PORT')}"]

# Initialize the configuration dictionary
config = {
"hosts": [{"host": os.getenv("ES_HOST"), "port": os.getenv("ES_PORT")}],
"hosts": hosts,
"headers": {"accept": "application/vnd.elasticsearch+json; compatible-with=7"},
"use_ssl": True,
"verify_certs": True,
}

if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
config["http_auth"] = (u, p)
# Explicitly exclude SSL settings when not using SSL
if not use_ssl:
return config

if (v := os.getenv("ES_USE_SSL")) and v == "false":
config["use_ssl"] = False
# Include SSL settings if using https
config["ssl_version"] = ssl.TLSVersion.TLSv1_3 # type: ignore
config["verify_certs"] = os.getenv("ES_VERIFY_CERTS", "true").lower() != "false" # type: ignore

if (v := os.getenv("ES_VERIFY_CERTS")) and v == "false":
config["verify_certs"] = False
# Include CA Certificates if verifying certs
if config["verify_certs"]:
config["ca_certs"] = os.getenv(
"CURL_CA_BUNDLE", "/etc/ssl/certs/ca-certificates.crt"
)

if v := os.getenv("CURL_CA_BUNDLE"):
config["ca_certs"] = v
# Handle authentication
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
config["http_auth"] = (u, p)

return config

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,19 @@ def indices(collection_ids: Optional[List[str]]) -> str:


async def create_collection_index() -> None:
"""Create the index for Collections in Elasticsearch.
"""
Create the index for a Collection.
Returns:
None
This function creates the Elasticsearch index for the `Collections` with the predefined mapping.
If the index already exists, the function ignores the error and continues execution.
"""
client = AsyncElasticsearchSettings().create_client

await client.indices.create(
await client.options(ignore_status=400).indices.create(
index=f"{COLLECTIONS_INDEX}-000001",
aliases={COLLECTIONS_INDEX: {}},
mappings=ES_COLLECTIONS_MAPPINGS,
ignore=400, # ignore 400 already exists code
)
await client.close()

Expand All @@ -200,12 +201,11 @@ async def create_item_index(collection_id: str):
client = AsyncElasticsearchSettings().create_client
index_name = index_by_collection_id(collection_id)

await client.indices.create(
await client.options(ignore_status=400).indices.create(
index=f"{index_by_collection_id(collection_id)}-000001",
aliases={index_name: {}},
mappings=ES_ITEMS_MAPPINGS,
settings=ES_ITEMS_SETTINGS,
ignore=400, # ignore 400 already exists code
)
await client.close()

Expand Down
1 change: 1 addition & 0 deletions stac_fastapi/elasticsearch/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ async def test_search_polygon_intersects_get(app_client, ctx):
assert len(resp_json["features"]) == 1


@pytest.mark.asyncio
async def test_search_point_intersects_post(app_client, ctx):
point = [150.04, -33.14]
intersects = {"type": "Point", "coordinates": point}
Expand Down
1 change: 1 addition & 0 deletions stac_fastapi/elasticsearch/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Config:
@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()

Expand Down

0 comments on commit 01f4ffa

Please sign in to comment.