Skip to content

Commit

Permalink
fix(server): merge providers by group & use groups in item links (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
alambare authored Jun 11, 2024
1 parent 2c37db3 commit ea12faa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions eodag/rest/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ def as_dict(self) -> Dict[str, Any]:

def get_provider_dict(self, provider: str) -> Dict[str, Any]:
"""Generate STAC provider dict"""
provider_config = [
provider_config = next(
p
for p in self.eodag_api.providers_config.values()
if provider in [p.name, getattr(p, "group", None)]
][0]
)
return {
"name": getattr(provider_config, "group", provider_config.name),
"description": getattr(provider_config, "description", None),
Expand Down Expand Up @@ -321,7 +321,8 @@ def __get_item_list(
else f"{url_parts.netloc}{url_parts.path}"
)
# add provider to query-args
query_dict.update(provider=[product.provider])
p_config = self.eodag_api.providers_config[product.provider]
query_dict.update(provider=[getattr(p_config, "group", p_config.name)])
# add datacube query-string to query-args
if _dc_qs:
query_dict.update(_dc_qs=_dc_qs)
Expand Down Expand Up @@ -625,7 +626,7 @@ def get_stac_item_from_product(self, product: EOProduct) -> Dict[str, Any]:
item_model,
{
"product": product_dict,
"providers": self.get_provider_dict(product.provider),
"providers": [self.get_provider_dict(product.provider)],
},
)
# parse f-strings
Expand Down Expand Up @@ -735,12 +736,18 @@ def __generate_stac_collection(
"""
providers = self.__list_product_type_providers(product_type)

providers_dict: Dict[str, Dict[str, Any]] = {}
for provider in providers:
p_dict = self.get_provider_dict(provider)
providers_dict.setdefault(p_dict["name"], p_dict)
providers_list = list(providers_dict.values())

# parse jsonpath
product_type_collection = jsonpath_parse_dict_items(
collection_model,
{
"product_type": product_type,
"providers": [self.get_provider_dict(p) for p in providers],
"providers": providers_list,
},
)
# override EODAG's collection with the external collection
Expand Down

0 comments on commit ea12faa

Please sign in to comment.