stac-fastapi-opensearch 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.
@@ -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.extensions.core import (
27
27
  AggregationExtension,
28
28
  FilterExtension,
@@ -31,6 +31,7 @@ from stac_fastapi.extensions.core import (
31
31
  TokenPaginationExtension,
32
32
  TransactionExtension,
33
33
  )
34
+ from stac_fastapi.extensions.core.filter import FilterConformanceClasses
34
35
  from stac_fastapi.extensions.third_party import BulkTransactionExtension
35
36
  from stac_fastapi.opensearch.config import OpensearchSettings
36
37
  from stac_fastapi.opensearch.database_logic import (
@@ -38,6 +39,14 @@ from stac_fastapi.opensearch.database_logic import (
38
39
  create_collection_index,
39
40
  create_index_templates,
40
41
  )
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 = OpensearchSettings()
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
- "http://www.opengis.net/spec/cql2/1.0/conf/advanced-comparison-operators"
60
+ FilterConformanceClasses.ADVANCED_COMPARISON_OPERATORS
52
61
  )
53
62
 
54
63
  aggregation_extension = AggregationExtension(
55
- client=EsAsyncAggregationClient(
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,52 @@ search_extensions = [
81
77
  FreeTextExtension(),
82
78
  ]
83
79
 
80
+
81
+ if TRANSACTIONS_EXTENSIONS:
82
+ search_extensions.insert(
83
+ 0,
84
+ TransactionExtension(
85
+ client=TransactionsClient(
86
+ database=database_logic, session=session, settings=settings
87
+ ),
88
+ settings=settings,
89
+ ),
90
+ )
91
+ search_extensions.insert(
92
+ 1,
93
+ BulkTransactionExtension(
94
+ client=BulkTransactionsClient(
95
+ database=database_logic,
96
+ session=session,
97
+ settings=settings,
98
+ )
99
+ ),
100
+ )
101
+
84
102
  extensions = [aggregation_extension] + search_extensions
85
103
 
86
104
  database_logic.extensions = [type(ext).__name__ for ext in extensions]
87
105
 
88
106
  post_request_model = create_post_request_model(search_extensions)
89
107
 
90
- api = StacApi(
91
- title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-opensearch"),
92
- description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-opensearch"),
93
- api_version=os.getenv("STAC_FASTAPI_VERSION", "4.1.0"),
94
- settings=settings,
95
- extensions=extensions,
96
- client=CoreClient(
97
- database=database_logic, session=session, post_request_model=post_request_model
108
+ app_config = {
109
+ "title": os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-opensearch"),
110
+ "description": os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-opensearch"),
111
+ "api_version": os.getenv("STAC_FASTAPI_VERSION", "5.0.0"),
112
+ "settings": settings,
113
+ "extensions": extensions,
114
+ "client": CoreClient(
115
+ database=database_logic,
116
+ session=session,
117
+ post_request_model=post_request_model,
118
+ landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"),
98
119
  ),
99
- search_get_request_model=create_get_request_model(search_extensions),
100
- search_post_request_model=post_request_model,
101
- route_dependencies=get_route_dependencies(),
102
- )
120
+ "search_get_request_model": create_get_request_model(search_extensions),
121
+ "search_post_request_model": post_request_model,
122
+ "route_dependencies": get_route_dependencies(),
123
+ }
124
+
125
+ api = StacApi(**app_config)
103
126
 
104
127
 
105
128
  @asynccontextmanager
@@ -2,13 +2,14 @@
2
2
  import logging
3
3
  import os
4
4
  import ssl
5
- from typing import Any, Dict, Set
5
+ from typing import Any, Dict, Set, Union
6
6
 
7
7
  import certifi
8
8
  from opensearchpy import AsyncOpenSearch, OpenSearch
9
9
 
10
10
  from stac_fastapi.core.base_settings import ApiBaseSettings
11
11
  from stac_fastapi.core.utilities import get_bool_env
12
+ from stac_fastapi.sfeos_helpers.database import validate_refresh
12
13
  from stac_fastapi.types.config import ApiSettings
13
14
 
14
15
 
@@ -39,18 +40,6 @@ def _es_config() -> Dict[str, Any]:
39
40
  if http_compress:
40
41
  config["http_compress"] = True
41
42
 
42
- # Explicitly exclude SSL settings when not using SSL
43
- if not use_ssl:
44
- return config
45
-
46
- # Include SSL settings if using https
47
- config["ssl_version"] = ssl.PROTOCOL_SSLv23
48
- config["verify_certs"] = get_bool_env("ES_VERIFY_CERTS", default=True)
49
-
50
- # Include CA Certificates if verifying certs
51
- if config["verify_certs"]:
52
- config["ca_certs"] = os.getenv("CURL_CA_BUNDLE", certifi.where())
53
-
54
43
  # Handle authentication
55
44
  if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
56
45
  config["http_auth"] = (u, p)
@@ -64,6 +53,18 @@ def _es_config() -> Dict[str, Any]:
64
53
 
65
54
  config["headers"] = headers
66
55
 
56
+ # Explicitly exclude SSL settings when not using SSL
57
+ if not use_ssl:
58
+ return config
59
+
60
+ # Include SSL settings if using https
61
+ config["ssl_version"] = ssl.PROTOCOL_SSLv23
62
+ config["verify_certs"] = get_bool_env("ES_VERIFY_CERTS", default=True)
63
+
64
+ # Include CA Certificates if verifying certs
65
+ if config["verify_certs"]:
66
+ config["ca_certs"] = os.getenv("CURL_CA_BUNDLE", certifi.where())
67
+
67
68
  return config
68
69
 
69
70
 
@@ -85,6 +86,17 @@ class OpensearchSettings(ApiSettings, ApiBaseSettings):
85
86
  enable_direct_response: bool = get_bool_env("ENABLE_DIRECT_RESPONSE", default=False)
86
87
  raise_on_bulk_error: bool = get_bool_env("RAISE_ON_BULK_ERROR", default=False)
87
88
 
89
+ @property
90
+ def database_refresh(self) -> Union[bool, str]:
91
+ """
92
+ Get the value of the DATABASE_REFRESH environment variable.
93
+
94
+ Returns:
95
+ Union[bool, str]: The value of DATABASE_REFRESH, which can be True, False, or "wait_for".
96
+ """
97
+ value = os.getenv("DATABASE_REFRESH", "false")
98
+ return validate_refresh(value)
99
+
88
100
  @property
89
101
  def create_client(self):
90
102
  """Create es client."""
@@ -106,6 +118,17 @@ class AsyncOpensearchSettings(ApiSettings, ApiBaseSettings):
106
118
  enable_direct_response: bool = get_bool_env("ENABLE_DIRECT_RESPONSE", default=False)
107
119
  raise_on_bulk_error: bool = get_bool_env("RAISE_ON_BULK_ERROR", default=False)
108
120
 
121
+ @property
122
+ def database_refresh(self) -> Union[bool, str]:
123
+ """
124
+ Get the value of the DATABASE_REFRESH environment variable.
125
+
126
+ Returns:
127
+ Union[bool, str]: The value of DATABASE_REFRESH, which can be True, False, or "wait_for".
128
+ """
129
+ value = os.getenv("DATABASE_REFRESH", "false")
130
+ return validate_refresh(value)
131
+
109
132
  @property
110
133
  def create_client(self):
111
134
  """Create async elasticsearch client."""