stac-fastapi-opensearch 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.extensions.core import (
27
27
  AggregationExtension,
28
28
  FilterExtension,
@@ -38,6 +38,14 @@ from stac_fastapi.opensearch.database_logic import (
38
38
  create_collection_index,
39
39
  create_index_templates,
40
40
  )
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 = OpensearchSettings()
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,28 @@ search_extensions = [
81
76
  FreeTextExtension(),
82
77
  ]
83
78
 
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]
@@ -90,11 +107,14 @@ post_request_model = create_post_request_model(search_extensions)
90
107
  api = StacApi(
91
108
  title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-opensearch"),
92
109
  description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-opensearch"),
93
- api_version=os.getenv("STAC_FASTAPI_VERSION", "4.1.0"),
110
+ api_version=os.getenv("STAC_FASTAPI_VERSION", "5.0.0a0"),
94
111
  settings=settings,
95
112
  extensions=extensions,
96
113
  client=CoreClient(
97
- database=database_logic, session=session, post_request_model=post_request_model
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
119
  search_get_request_model=create_get_request_model(search_extensions),
100
120
  search_post_request_model=post_request_model,
@@ -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
 
@@ -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."""