File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
stac_fastapi/elasticsearch
stac_fastapi/elasticsearch Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 2424
2525COLLECTIONS_INDEX = os .getenv ("STAC_COLLECTIONS_INDEX" , "collections" )
2626ITEMS_INDEX_PREFIX = os .getenv ("STAC_ITEMS_INDEX_PREFIX" , "items_" )
27+ ES_INDEX_NAME_UNSUPPORTED_CHARS = {
28+ "\\ " ,
29+ "/" ,
30+ "*" ,
31+ "?" ,
32+ '"' ,
33+ "<" ,
34+ ">" ,
35+ "|" ,
36+ " " ,
37+ "," ,
38+ "#" ,
39+ ":" ,
40+ }
2741
2842DEFAULT_INDICES = f"*,-*kibana*,-{ COLLECTIONS_INDEX } "
2943
@@ -136,7 +150,7 @@ def index_by_collection_id(collection_id: str) -> str:
136150 Returns:
137151 str: The index name derived from the collection id.
138152 """
139- return f"{ ITEMS_INDEX_PREFIX } { collection_id } "
153+ return f"{ ITEMS_INDEX_PREFIX } { '' . join ( c for c in collection_id . lower () if c not in ES_INDEX_NAME_UNSUPPORTED_CHARS ) } "
140154
141155
142156def indices (collection_ids : Optional [List [str ]]) -> str :
@@ -152,7 +166,7 @@ def indices(collection_ids: Optional[List[str]]) -> str:
152166 if collection_ids is None :
153167 return DEFAULT_INDICES
154168 else :
155- return "," .join ([f" { ITEMS_INDEX_PREFIX } { c . strip () } " for c in collection_ids ])
169+ return "," .join ([index_by_collection_id ( c ) for c in collection_ids ])
156170
157171
158172async def create_collection_index () -> None :
Original file line number Diff line number Diff line change @@ -75,6 +75,18 @@ async def test_create_item_missing_collection(app_client, ctx):
7575 assert resp .status_code == 404
7676
7777
78+ async def test_create_uppercase_collection_with_item (app_client , ctx , txn_client ):
79+ """Test creation of a collection and item with uppercase collection ID (transactions extension)"""
80+ collection_id = "UPPERCASE"
81+ ctx .item ["collection" ] = collection_id
82+ ctx .collection ["id" ] = collection_id
83+ resp = await app_client .post ("/collections" , json = ctx .collection )
84+ assert resp .status_code == 200
85+ await refresh_indices (txn_client )
86+ resp = await app_client .post (f"/collections/{ collection_id } /items" , json = ctx .item )
87+ assert resp .status_code == 200
88+
89+
7890async def test_update_item_already_exists (app_client , ctx ):
7991 """Test updating an item which already exists (transactions extension)"""
8092
You can’t perform that action at this time.
0 commit comments