stac-fastapi-elasticsearch 4.1.0__py3-none-any.whl → 5.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stac_fastapi/elasticsearch/app.py +51 -29
- stac_fastapi/elasticsearch/config.py +28 -5
- stac_fastapi/elasticsearch/database_logic.py +398 -281
- stac_fastapi/elasticsearch/version.py +1 -1
- stac_fastapi_elasticsearch-5.0.0.dist-info/METADATA +575 -0
- stac_fastapi_elasticsearch-5.0.0.dist-info/RECORD +10 -0
- stac_fastapi_elasticsearch-4.1.0.dist-info/METADATA +0 -379
- stac_fastapi_elasticsearch-4.1.0.dist-info/RECORD +0 -10
- {stac_fastapi_elasticsearch-4.1.0.dist-info → stac_fastapi_elasticsearch-5.0.0.dist-info}/WHEEL +0 -0
- {stac_fastapi_elasticsearch-4.1.0.dist-info → stac_fastapi_elasticsearch-5.0.0.dist-info}/entry_points.txt +0 -0
- {stac_fastapi_elasticsearch-4.1.0.dist-info → stac_fastapi_elasticsearch-5.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""FastAPI application."""
|
|
2
2
|
|
|
3
|
+
import logging
|
|
3
4
|
import os
|
|
4
5
|
from contextlib import asynccontextmanager
|
|
5
6
|
|
|
@@ -10,19 +11,18 @@ from stac_fastapi.api.models import create_get_request_model, create_post_reques
|
|
|
10
11
|
from stac_fastapi.core.core import (
|
|
11
12
|
BulkTransactionsClient,
|
|
12
13
|
CoreClient,
|
|
13
|
-
EsAsyncBaseFiltersClient,
|
|
14
14
|
TransactionsClient,
|
|
15
15
|
)
|
|
16
16
|
from stac_fastapi.core.extensions import QueryExtension
|
|
17
17
|
from stac_fastapi.core.extensions.aggregation import (
|
|
18
18
|
EsAggregationExtensionGetRequest,
|
|
19
19
|
EsAggregationExtensionPostRequest,
|
|
20
|
-
EsAsyncAggregationClient,
|
|
21
20
|
)
|
|
22
21
|
from stac_fastapi.core.extensions.fields import FieldsExtension
|
|
23
22
|
from stac_fastapi.core.rate_limit import setup_rate_limit
|
|
24
23
|
from stac_fastapi.core.route_dependencies import get_route_dependencies
|
|
25
24
|
from stac_fastapi.core.session import Session
|
|
25
|
+
from stac_fastapi.core.utilities import get_bool_env
|
|
26
26
|
from stac_fastapi.elasticsearch.config import ElasticsearchSettings
|
|
27
27
|
from stac_fastapi.elasticsearch.database_logic import (
|
|
28
28
|
DatabaseLogic,
|
|
@@ -37,7 +37,16 @@ from stac_fastapi.extensions.core import (
|
|
|
37
37
|
TokenPaginationExtension,
|
|
38
38
|
TransactionExtension,
|
|
39
39
|
)
|
|
40
|
+
from stac_fastapi.extensions.core.filter import FilterConformanceClasses
|
|
40
41
|
from stac_fastapi.extensions.third_party import BulkTransactionExtension
|
|
42
|
+
from stac_fastapi.sfeos_helpers.aggregation import EsAsyncBaseAggregationClient
|
|
43
|
+
from stac_fastapi.sfeos_helpers.filter import EsAsyncBaseFiltersClient
|
|
44
|
+
|
|
45
|
+
logging.basicConfig(level=logging.INFO)
|
|
46
|
+
logger = logging.getLogger(__name__)
|
|
47
|
+
|
|
48
|
+
TRANSACTIONS_EXTENSIONS = get_bool_env("ENABLE_TRANSACTIONS_EXTENSIONS", default=True)
|
|
49
|
+
logger.info("TRANSACTIONS_EXTENSIONS is set to %s", TRANSACTIONS_EXTENSIONS)
|
|
41
50
|
|
|
42
51
|
settings = ElasticsearchSettings()
|
|
43
52
|
session = Session.create_from_settings(settings)
|
|
@@ -48,11 +57,11 @@ filter_extension = FilterExtension(
|
|
|
48
57
|
client=EsAsyncBaseFiltersClient(database=database_logic)
|
|
49
58
|
)
|
|
50
59
|
filter_extension.conformance_classes.append(
|
|
51
|
-
|
|
60
|
+
FilterConformanceClasses.ADVANCED_COMPARISON_OPERATORS
|
|
52
61
|
)
|
|
53
62
|
|
|
54
63
|
aggregation_extension = AggregationExtension(
|
|
55
|
-
client=
|
|
64
|
+
client=EsAsyncBaseAggregationClient(
|
|
56
65
|
database=database_logic, session=session, settings=settings
|
|
57
66
|
)
|
|
58
67
|
)
|
|
@@ -60,19 +69,6 @@ aggregation_extension.POST = EsAggregationExtensionPostRequest
|
|
|
60
69
|
aggregation_extension.GET = EsAggregationExtensionGetRequest
|
|
61
70
|
|
|
62
71
|
search_extensions = [
|
|
63
|
-
TransactionExtension(
|
|
64
|
-
client=TransactionsClient(
|
|
65
|
-
database=database_logic, session=session, settings=settings
|
|
66
|
-
),
|
|
67
|
-
settings=settings,
|
|
68
|
-
),
|
|
69
|
-
BulkTransactionExtension(
|
|
70
|
-
client=BulkTransactionsClient(
|
|
71
|
-
database=database_logic,
|
|
72
|
-
session=session,
|
|
73
|
-
settings=settings,
|
|
74
|
-
)
|
|
75
|
-
),
|
|
76
72
|
FieldsExtension(),
|
|
77
73
|
QueryExtension(),
|
|
78
74
|
SortExtension(),
|
|
@@ -81,25 +77,51 @@ search_extensions = [
|
|
|
81
77
|
FreeTextExtension(),
|
|
82
78
|
]
|
|
83
79
|
|
|
80
|
+
if TRANSACTIONS_EXTENSIONS:
|
|
81
|
+
search_extensions.insert(
|
|
82
|
+
0,
|
|
83
|
+
TransactionExtension(
|
|
84
|
+
client=TransactionsClient(
|
|
85
|
+
database=database_logic, session=session, settings=settings
|
|
86
|
+
),
|
|
87
|
+
settings=settings,
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
search_extensions.insert(
|
|
91
|
+
1,
|
|
92
|
+
BulkTransactionExtension(
|
|
93
|
+
client=BulkTransactionsClient(
|
|
94
|
+
database=database_logic,
|
|
95
|
+
session=session,
|
|
96
|
+
settings=settings,
|
|
97
|
+
)
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
|
|
84
101
|
extensions = [aggregation_extension] + search_extensions
|
|
85
102
|
|
|
86
103
|
database_logic.extensions = [type(ext).__name__ for ext in extensions]
|
|
87
104
|
|
|
88
105
|
post_request_model = create_post_request_model(search_extensions)
|
|
89
106
|
|
|
90
|
-
|
|
91
|
-
title
|
|
92
|
-
description
|
|
93
|
-
api_version
|
|
94
|
-
settings
|
|
95
|
-
extensions
|
|
96
|
-
client
|
|
97
|
-
database=database_logic,
|
|
107
|
+
app_config = {
|
|
108
|
+
"title": os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-elasticsearch"),
|
|
109
|
+
"description": os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-elasticsearch"),
|
|
110
|
+
"api_version": os.getenv("STAC_FASTAPI_VERSION", "5.0.0"),
|
|
111
|
+
"settings": settings,
|
|
112
|
+
"extensions": extensions,
|
|
113
|
+
"client": CoreClient(
|
|
114
|
+
database=database_logic,
|
|
115
|
+
session=session,
|
|
116
|
+
post_request_model=post_request_model,
|
|
117
|
+
landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"),
|
|
98
118
|
),
|
|
99
|
-
search_get_request_model
|
|
100
|
-
search_post_request_model
|
|
101
|
-
route_dependencies
|
|
102
|
-
|
|
119
|
+
"search_get_request_model": create_get_request_model(search_extensions),
|
|
120
|
+
"search_post_request_model": post_request_model,
|
|
121
|
+
"route_dependencies": get_route_dependencies(),
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
api = StacApi(**app_config)
|
|
103
125
|
|
|
104
126
|
|
|
105
127
|
@asynccontextmanager
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
5
5
|
import ssl
|
|
6
|
-
from typing import Any, Dict, Set
|
|
6
|
+
from typing import Any, Dict, Set, Union
|
|
7
7
|
|
|
8
8
|
import certifi
|
|
9
9
|
from elasticsearch._async.client import AsyncElasticsearch
|
|
@@ -11,6 +11,7 @@ from elasticsearch._async.client import AsyncElasticsearch
|
|
|
11
11
|
from elasticsearch import Elasticsearch # type: ignore[attr-defined]
|
|
12
12
|
from stac_fastapi.core.base_settings import ApiBaseSettings
|
|
13
13
|
from stac_fastapi.core.utilities import get_bool_env
|
|
14
|
+
from stac_fastapi.sfeos_helpers.database import validate_refresh
|
|
14
15
|
from stac_fastapi.types.config import ApiSettings
|
|
15
16
|
|
|
16
17
|
|
|
@@ -51,6 +52,10 @@ def _es_config() -> Dict[str, Any]:
|
|
|
51
52
|
if http_compress:
|
|
52
53
|
config["http_compress"] = True
|
|
53
54
|
|
|
55
|
+
# Handle authentication
|
|
56
|
+
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
|
|
57
|
+
config["http_auth"] = (u, p)
|
|
58
|
+
|
|
54
59
|
# Explicitly exclude SSL settings when not using SSL
|
|
55
60
|
if not use_ssl:
|
|
56
61
|
return config
|
|
@@ -63,10 +68,6 @@ def _es_config() -> Dict[str, Any]:
|
|
|
63
68
|
if config["verify_certs"]:
|
|
64
69
|
config["ca_certs"] = os.getenv("CURL_CA_BUNDLE", certifi.where())
|
|
65
70
|
|
|
66
|
-
# Handle authentication
|
|
67
|
-
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
|
|
68
|
-
config["http_auth"] = (u, p)
|
|
69
|
-
|
|
70
71
|
return config
|
|
71
72
|
|
|
72
73
|
|
|
@@ -88,6 +89,17 @@ class ElasticsearchSettings(ApiSettings, ApiBaseSettings):
|
|
|
88
89
|
enable_direct_response: bool = get_bool_env("ENABLE_DIRECT_RESPONSE", default=False)
|
|
89
90
|
raise_on_bulk_error: bool = get_bool_env("RAISE_ON_BULK_ERROR", default=False)
|
|
90
91
|
|
|
92
|
+
@property
|
|
93
|
+
def database_refresh(self) -> Union[bool, str]:
|
|
94
|
+
"""
|
|
95
|
+
Get the value of the DATABASE_REFRESH environment variable.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
Union[bool, str]: The value of DATABASE_REFRESH, which can be True, False, or "wait_for".
|
|
99
|
+
"""
|
|
100
|
+
value = os.getenv("DATABASE_REFRESH", "false")
|
|
101
|
+
return validate_refresh(value)
|
|
102
|
+
|
|
91
103
|
@property
|
|
92
104
|
def create_client(self):
|
|
93
105
|
"""Create es client."""
|
|
@@ -109,6 +121,17 @@ class AsyncElasticsearchSettings(ApiSettings, ApiBaseSettings):
|
|
|
109
121
|
enable_direct_response: bool = get_bool_env("ENABLE_DIRECT_RESPONSE", default=False)
|
|
110
122
|
raise_on_bulk_error: bool = get_bool_env("RAISE_ON_BULK_ERROR", default=False)
|
|
111
123
|
|
|
124
|
+
@property
|
|
125
|
+
def database_refresh(self) -> Union[bool, str]:
|
|
126
|
+
"""
|
|
127
|
+
Get the value of the DATABASE_REFRESH environment variable.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
Union[bool, str]: The value of DATABASE_REFRESH, which can be True, False, or "wait_for".
|
|
131
|
+
"""
|
|
132
|
+
value = os.getenv("DATABASE_REFRESH", "false")
|
|
133
|
+
return validate_refresh(value)
|
|
134
|
+
|
|
112
135
|
@property
|
|
113
136
|
def create_client(self):
|
|
114
137
|
"""Create async elasticsearch client."""
|