stac-fastapi-elasticsearch 4.1.0__py3-none-any.whl → 5.0.0a0__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.
@@ -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,
@@ -38,6 +38,14 @@ from stac_fastapi.extensions.core import (
38
38
  TransactionExtension,
39
39
  )
40
40
  from stac_fastapi.extensions.third_party import BulkTransactionExtension
41
+ from stac_fastapi.sfeos_helpers.aggregation import EsAsyncBaseAggregationClient
42
+ from stac_fastapi.sfeos_helpers.filter import EsAsyncBaseFiltersClient
43
+
44
+ logging.basicConfig(level=logging.INFO)
45
+ logger = logging.getLogger(__name__)
46
+
47
+ TRANSACTIONS_EXTENSIONS = get_bool_env("ENABLE_TRANSACTIONS_EXTENSIONS", default=True)
48
+ logger.info("TRANSACTIONS_EXTENSIONS is set to %s", TRANSACTIONS_EXTENSIONS)
41
49
 
42
50
  settings = ElasticsearchSettings()
43
51
  session = Session.create_from_settings(settings)
@@ -52,7 +60,7 @@ filter_extension.conformance_classes.append(
52
60
  )
53
61
 
54
62
  aggregation_extension = AggregationExtension(
55
- client=EsAsyncAggregationClient(
63
+ client=EsAsyncBaseAggregationClient(
56
64
  database=database_logic, session=session, settings=settings
57
65
  )
58
66
  )
@@ -60,19 +68,6 @@ aggregation_extension.POST = EsAggregationExtensionPostRequest
60
68
  aggregation_extension.GET = EsAggregationExtensionGetRequest
61
69
 
62
70
  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
71
  FieldsExtension(),
77
72
  QueryExtension(),
78
73
  SortExtension(),
@@ -81,6 +76,27 @@ search_extensions = [
81
76
  FreeTextExtension(),
82
77
  ]
83
78
 
79
+ if TRANSACTIONS_EXTENSIONS:
80
+ search_extensions.insert(
81
+ 0,
82
+ TransactionExtension(
83
+ client=TransactionsClient(
84
+ database=database_logic, session=session, settings=settings
85
+ ),
86
+ settings=settings,
87
+ ),
88
+ )
89
+ search_extensions.insert(
90
+ 1,
91
+ BulkTransactionExtension(
92
+ client=BulkTransactionsClient(
93
+ database=database_logic,
94
+ session=session,
95
+ settings=settings,
96
+ )
97
+ ),
98
+ )
99
+
84
100
  extensions = [aggregation_extension] + search_extensions
85
101
 
86
102
  database_logic.extensions = [type(ext).__name__ for ext in extensions]
@@ -90,11 +106,14 @@ post_request_model = create_post_request_model(search_extensions)
90
106
  api = StacApi(
91
107
  title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-elasticsearch"),
92
108
  description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-elasticsearch"),
93
- api_version=os.getenv("STAC_FASTAPI_VERSION", "4.1.0"),
109
+ api_version=os.getenv("STAC_FASTAPI_VERSION", "5.0.0a0"),
94
110
  settings=settings,
95
111
  extensions=extensions,
96
112
  client=CoreClient(
97
- database=database_logic, session=session, post_request_model=post_request_model
113
+ database=database_logic,
114
+ session=session,
115
+ post_request_model=post_request_model,
116
+ landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"),
98
117
  ),
99
118
  search_get_request_model=create_get_request_model(search_extensions),
100
119
  search_post_request_model=post_request_model,
@@ -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
 
@@ -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."""