Skip to content

Commit cdeaec8

Browse files
committed
emv var to turn off collections-search route
1 parent 829858e commit cdeaec8

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
## [Unreleased]
99

1010
### Added
11+
- Environment variable `ENABLE_COLLECTIONS_SEARCH_ROUTE` to turn on/off the `/collections-search` endpoint. [#478](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/478)
1112
- POST and GET `/collections-search` endpoint for collections search queries, needed because POST /collections will not work when the Transactions Extension is enabled. [#478](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/478)
1213
- GET `/collections` collection search structured filter extension with support for both cql2-json and cql2-text formats. [#475](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/475)
1314
- GET `/collections` collection search query extension. [#477](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/477)
1415
- GET `/collections` collections search datetime filtering support. [#476](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/476)
1516

1617
### Changed
17-
- Refactored collection search implementation to support both GET and POST methods. [#478](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/478)
18+
- Refactored `/collections` endpoint implementation to support both GET and POST methods. [#478](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/478)
1819

1920
### Fixed
2021
- support of disabled nested attributes in the properties dictionary. [#474](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/474)

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ These endpoints support advanced collection discovery features including:
152152

153153
These extensions make it easier to build user interfaces that display and navigate through collections efficiently.
154154

155-
> **Configuration**: Collection search extensions (sorting, field selection, free text search, structured filtering, and datetime filtering) can be disabled by setting the `ENABLE_COLLECTIONS_SEARCH` environment variable to `false`. By default, these extensions are enabled.
155+
> **Configuration**: Collection search extensions (sorting, field selection, free text search, structured filtering, and datetime filtering) for the `/collections` endpoint can be disabled by setting the `ENABLE_COLLECTIONS_SEARCH` environment variable to `false`. By default, these extensions are enabled.
156+
>
157+
> **Configuration**: The custom `/collections-search` endpoint can be disabled by setting the `ENABLE_COLLECTIONS_SEARCH_ROUTE` environment variable to `false`. By default, this endpoint is enabled.
156158
157159
> **Note**: Sorting is only available on fields that are indexed for sorting in Elasticsearch/OpenSearch. With the default mappings, you can sort on:
158160
> - `id` (keyword field)
@@ -294,8 +296,8 @@ You can customize additional settings in your `.env` file:
294296
| `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional |
295297
| `RAISE_ON_BULK_ERROR` | Controls whether bulk insert operations raise exceptions on errors. If set to `true`, the operation will stop and raise an exception when an error occurs. If set to `false`, errors will be logged, and the operation will continue. **Note:** STAC Item and ItemCollection validation errors will always raise, regardless of this flag. | `false` | Optional |
296298
| `DATABASE_REFRESH` | Controls whether database operations refresh the index immediately after changes. If set to `true`, changes will be immediately searchable. If set to `false`, changes may not be immediately visible but can improve performance for bulk operations. If set to `wait_for`, changes will wait for the next refresh cycle to become visible. | `false` | Optional |
297-
| `ENABLE_COLLECTIONS_SEARCH` | Enable collection search extensions (sort, fields, free text search, structured filtering, and datetime filtering). | `true` | Optional |
298-
| `ENABLE_TRANSACTIONS_EXTENSIONS` | Enables or disables the Transactions and Bulk Transactions API extensions. If set to `false`, the POST `/collections` route and related transaction endpoints (including bulk transaction operations) will be unavailable in the API. This is useful for deployments where mutating the catalog via the API should be prevented. | `true` | Optional |
299+
| `ENABLE_COLLECTIONS_SEARCH` | Enable collection search extensions (sort, fields, free text search, structured filtering, and datetime filtering) on the core `/collections` endpoint. | `true` | Optional |
300+
| `ENABLE_COLLECTIONS_SEARCH_ROUTE` | Enable the custom `/collections-search` endpoint (both GET and POST methods). When disabled, the custom endpoint will not be available, but collection search extensions will still be available on the core `/collections` endpoint if `ENABLE_COLLECTIONS_SEARCH` is true. | `true` | Optional |
299301
| `STAC_ITEM_LIMIT` | Sets the environment variable for result limiting to SFEOS for the number of returned items and STAC collections. | `10` | Optional |
300302
| `STAC_INDEX_ASSETS` | Controls if Assets are indexed when added to Elasticsearch/Opensearch. This allows asset fields to be included in search queries. | `false` | Optional |
301303
| `ENV_MAX_LIMIT` | Configures the environment variable in SFEOS to override the default `MAX_LIMIT`, which controls the limit parameter for returned items and STAC collections. | `10,000` | Optional |

compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ services:
2222
- ES_VERIFY_CERTS=false
2323
- BACKEND=elasticsearch
2424
- DATABASE_REFRESH=true
25+
- ENABLE_COLLECTIONS_SEARCH=true
26+
- ENABLE_COLLECTIONS_SEARCH_ROUTE=true
2527
ports:
2628
- "8080:8080"
2729
volumes:
@@ -56,6 +58,8 @@ services:
5658
- ES_VERIFY_CERTS=false
5759
- BACKEND=opensearch
5860
- STAC_FASTAPI_RATE_LIMIT=200/minute
61+
- ENABLE_COLLECTIONS_SEARCH=true
62+
- ENABLE_COLLECTIONS_SEARCH_ROUTE=true
5963
ports:
6064
- "8082:8082"
6165
volumes:

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@
6262

6363
TRANSACTIONS_EXTENSIONS = get_bool_env("ENABLE_TRANSACTIONS_EXTENSIONS", default=True)
6464
ENABLE_COLLECTIONS_SEARCH = get_bool_env("ENABLE_COLLECTIONS_SEARCH", default=True)
65+
ENABLE_COLLECTIONS_SEARCH_ROUTE = get_bool_env(
66+
"ENABLE_COLLECTIONS_SEARCH_ROUTE", default=True
67+
)
6568
logger.info("TRANSACTIONS_EXTENSIONS is set to %s", TRANSACTIONS_EXTENSIONS)
6669
logger.info("ENABLE_COLLECTIONS_SEARCH is set to %s", ENABLE_COLLECTIONS_SEARCH)
70+
logger.info(
71+
"ENABLE_COLLECTIONS_SEARCH_ROUTE is set to %s", ENABLE_COLLECTIONS_SEARCH_ROUTE
72+
)
6773

6874
settings = ElasticsearchSettings()
6975
session = Session.create_from_settings(settings)
@@ -124,8 +130,7 @@
124130
# Collection search related variables
125131
collections_get_request_model = None
126132

127-
# Create collection search extensions if enabled
128-
if ENABLE_COLLECTIONS_SEARCH:
133+
if ENABLE_COLLECTIONS_SEARCH or ENABLE_COLLECTIONS_SEARCH_ROUTE:
129134
# Create collection search extensions
130135
collection_search_extensions = [
131136
QueryExtension(conformance_classes=[QueryConformanceClasses.COLLECTIONS]),
@@ -148,6 +153,8 @@
148153
collection_search_extensions
149154
)
150155

156+
# Create collection search extensions if enabled
157+
if ENABLE_COLLECTIONS_SEARCH:
151158
# Initialize collection search POST extension
152159
collection_search_post_ext = CollectionSearchPostExtension(
153160
client=CoreClient(
@@ -167,7 +174,10 @@
167174
FieldsConformanceClasses.COLLECTIONS,
168175
],
169176
)
177+
extensions.append(collection_search_ext)
178+
extensions.append(collection_search_post_ext)
170179

180+
if ENABLE_COLLECTIONS_SEARCH_ROUTE:
171181
# Initialize collections-search endpoint extension
172182
collections_search_endpoint_ext = CollectionsSearchEndpointExtension(
173183
client=CoreClient(
@@ -188,9 +198,6 @@
188198
FieldsConformanceClasses.COLLECTIONS,
189199
],
190200
)
191-
192-
extensions.append(collection_search_ext)
193-
extensions.append(collection_search_post_ext)
194201
extensions.append(collections_search_endpoint_ext)
195202

196203

@@ -250,6 +257,7 @@ async def lifespan(app: FastAPI):
250257
app = api.app
251258
app.router.lifespan_context = lifespan
252259
app.root_path = os.getenv("STAC_FASTAPI_ROOT_PATH", "")
260+
253261
# Add rate limit
254262
setup_rate_limit(app, rate_limit=os.getenv("STAC_FASTAPI_RATE_LIMIT"))
255263

stac_fastapi/opensearch/stac_fastapi/opensearch/app.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@
6262

6363
TRANSACTIONS_EXTENSIONS = get_bool_env("ENABLE_TRANSACTIONS_EXTENSIONS", default=True)
6464
ENABLE_COLLECTIONS_SEARCH = get_bool_env("ENABLE_COLLECTIONS_SEARCH", default=True)
65+
ENABLE_COLLECTIONS_SEARCH_ROUTE = get_bool_env(
66+
"ENABLE_COLLECTIONS_SEARCH_ROUTE", default=True
67+
)
6568
logger.info("TRANSACTIONS_EXTENSIONS is set to %s", TRANSACTIONS_EXTENSIONS)
6669
logger.info("ENABLE_COLLECTIONS_SEARCH is set to %s", ENABLE_COLLECTIONS_SEARCH)
70+
logger.info(
71+
"ENABLE_COLLECTIONS_SEARCH_ROUTE is set to %s", ENABLE_COLLECTIONS_SEARCH_ROUTE
72+
)
6773

6874
settings = OpensearchSettings()
6975
session = Session.create_from_settings(settings)
@@ -124,8 +130,10 @@
124130
# Collection search related variables
125131
collections_get_request_model = None
126132

127-
# Create collection search extensions if enabled
128-
if ENABLE_COLLECTIONS_SEARCH:
133+
# Collection search related variables
134+
collections_get_request_model = None
135+
136+
if ENABLE_COLLECTIONS_SEARCH or ENABLE_COLLECTIONS_SEARCH_ROUTE:
129137
# Create collection search extensions
130138
collection_search_extensions = [
131139
QueryExtension(conformance_classes=[QueryConformanceClasses.COLLECTIONS]),
@@ -148,6 +156,8 @@
148156
collection_search_extensions
149157
)
150158

159+
# Create collection search extensions if enabled
160+
if ENABLE_COLLECTIONS_SEARCH:
151161
# Initialize collection search POST extension
152162
collection_search_post_ext = CollectionSearchPostExtension(
153163
client=CoreClient(
@@ -163,12 +173,14 @@
163173
QueryConformanceClasses.COLLECTIONS,
164174
FilterConformanceClasses.COLLECTIONS,
165175
FreeTextConformanceClasses.COLLECTIONS,
166-
QueryConformanceClasses.COLLECTIONS,
167176
SortConformanceClasses.COLLECTIONS,
168177
FieldsConformanceClasses.COLLECTIONS,
169178
],
170179
)
180+
extensions.append(collection_search_ext)
181+
extensions.append(collection_search_post_ext)
171182

183+
if ENABLE_COLLECTIONS_SEARCH_ROUTE:
172184
# Initialize collections-search endpoint extension
173185
collections_search_endpoint_ext = CollectionsSearchEndpointExtension(
174186
client=CoreClient(
@@ -185,14 +197,10 @@
185197
QueryConformanceClasses.COLLECTIONS,
186198
FilterConformanceClasses.COLLECTIONS,
187199
FreeTextConformanceClasses.COLLECTIONS,
188-
QueryConformanceClasses.COLLECTIONS,
189200
SortConformanceClasses.COLLECTIONS,
190201
FieldsConformanceClasses.COLLECTIONS,
191202
],
192203
)
193-
194-
extensions.append(collection_search_ext)
195-
extensions.append(collection_search_post_ext)
196204
extensions.append(collections_search_endpoint_ext)
197205

198206

0 commit comments

Comments
 (0)