Skip to content

Commit e013217

Browse files
authored
fix: set wekeo_main products storageTier to online (#29)
`auto_order_whitelist` setting has been added previously, and now products from federation backends of this whitelist has `storageTier` metadata from eodag [EOProduct()](https://eodag.readthedocs.io/en/stable/api_reference/eoproduct.html#eodag.api.product._product.EOProduct) set to `ONLINE` because products are available immediately after a search. This means that `storage:tier` and `order:status` STAC properties are respectively set to `online` and `succeeded` when these `EOProducts` are converted to STAC items.
1 parent 5d79ce2 commit e013217

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Reach to [stac-fastapi documentation](https://stac-utils.github.io/stac-fastapi/
106106
| `ORIGIN_URL_BLACKLIST` | Hide from clients items assets' origin URLs starting with URLs from the list. A string of comma separated values is expected. | "" |
107107
| `COUNT` | Whether to run a query with a count request or not. | False |
108108
| `FETCH_PROVIDERS` | Fetch additional collections from all EODAG providers. | False |
109+
| `AUTO_ORDER_WHITELIST` | List of providers for which the order should be done at the same time as the download. | ["wekeo_main"] |
109110
| `DOWNLOAD_BASE_URL` | Useful to expose asset download URL in a separate domain name. | "" |
110111

111112
### OpenTelemetry parameters

stac_fastapi/eodag/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ class Settings(ApiSettings):
3838
default=False,
3939
description=("Keep origin as alternate URL when data-download extension is enabled."),
4040
)
41+
4142
origin_url_blacklist: Annotated[Union[str, list[str]], BeforeValidator(str2liststr)] = Field(
4243
default=[],
43-
description=("Hide from clients items assets' origin URLs starting with URLs from the list"),
44+
description=("Hide from clients items assets' origin URLs starting with URLs from the list."),
4445
)
4546

4647
auto_order_whitelist: Annotated[Union[str, list[str]], BeforeValidator(str2liststr)] = Field(
4748
default=[
4849
"wekeo_main",
4950
],
50-
description=("Do the order at the same time as the download"),
51+
description=("List of providers for which the order should be done at the same time as the download."),
5152
)
5253

5354
fetch_providers: bool = Field(default=False, description="Fetch additional collections from all providers.")

stac_fastapi/eodag/models/stac_metadata.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,14 @@ def create_stac_item(
288288
if extension_is_enabled("DataDownload")
289289
else None
290290
)
291-
# create assets only if product is not offline
291+
292292
settings = get_settings()
293293
auto_order_whitelist = settings.auto_order_whitelist
294+
if product.provider in auto_order_whitelist:
295+
# a product from a whitelisted federation backend is considered as online
296+
product.properties["storageStatus"] = ONLINE_STATUS
297+
298+
# create assets only if product is not offline
294299
if (
295300
product.properties.get("storageStatus", ONLINE_STATUS) != OFFLINE_STATUS
296301
or product.provider in auto_order_whitelist

tests/test_download.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ async def test_download_auto_order_whitelist(
7171
and checks that the order function is triggered when the backend is present
7272
in the auto_order_whitelist configuration.
7373
"""
74-
get_settings().auto_order_whitelist = ["peps"]
7574
federation_backend = "peps"
75+
# update the auto_order_whitelist setting to include "peps"
76+
auto_order_whitelist = get_settings().auto_order_whitelist
77+
get_settings().auto_order_whitelist = [federation_backend]
78+
7679
collection_id = defaults.product_type
7780

78-
url = f"data/peps/{defaults.product_type}/dummy_id/downloadLink"
81+
url = f"data/{federation_backend}/{defaults.product_type}/dummy_id/downloadLink"
7982

8083
product = EOProduct(
8184
federation_backend,
@@ -88,7 +91,7 @@ async def test_download_auto_order_whitelist(
8891
product.product_type = collection_id
8992
config = PluginConfig()
9093
config.priority = 0
91-
downloader = HTTPDownload("peps", config)
94+
downloader = HTTPDownload(federation_backend, config)
9295

9396
product.register_downloader(downloader=downloader, authenticator=None)
9497

@@ -98,3 +101,6 @@ async def test_download_auto_order_whitelist(
98101
await request_valid_raw(url, search_result=SearchResult([product]))
99102

100103
assert mock_order.called
104+
105+
# restore the original auto_order_whitelist setting
106+
get_settings().auto_order_whitelist = auto_order_whitelist

tests/test_search.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ async def test_items_response(request_valid, defaults):
143143
== f"http://testserver/data/peps/{res[0]['collection']}/{res[0]['id']}/asset1"
144144
)
145145

146+
# check order status and storage tier properties of the "OFFLINE" item when peps is whitelisted
147+
auto_order_whitelist = get_settings().auto_order_whitelist
148+
get_settings().auto_order_whitelist = ["peps"]
149+
150+
resp_json = await request_valid(
151+
f"search?collections={defaults.product_type}",
152+
)
153+
res = resp_json["features"]
154+
assert res[1]["properties"]["order:status"] == "succeeded"
155+
assert res[1]["properties"]["storage:tier"] == "online"
156+
157+
# restore the original auto_order_whitelist setting
158+
get_settings().auto_order_whitelist = auto_order_whitelist
159+
146160

147161
async def test_items_response_unexpected_types(request_valid, defaults, mock_search_result):
148162
"""Item properties contain values in unexpected types for processingLevel and platform

0 commit comments

Comments
 (0)