From 759d4e7b6a84acd480b4f19cfe36a98674ca17b1 Mon Sep 17 00:00:00 2001 From: LAMBARE Aubin Date: Sat, 8 Jun 2024 16:55:32 +0200 Subject: [PATCH] fix(server): merge providers by group & use groups in item links --- eodag/resources/providers.yml | 2 ++ eodag/rest/stac.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/eodag/resources/providers.yml b/eodag/resources/providers.yml index 612758f1b..658f28361 100644 --- a/eodag/resources/providers.yml +++ b/eodag/resources/providers.yml @@ -880,6 +880,7 @@ --- !provider # MARK: creodias name: creodias + group: test priority: 0 description: CloudFerro DIAS roles: @@ -6066,6 +6067,7 @@ --- !provider # MARK: creodias_s3 name: creodias_s3 + group: test priority: 0 description: CloudFerro DIAS data through S3 protocol roles: diff --git a/eodag/rest/stac.py b/eodag/rest/stac.py index 1764ccd9f..d196e003c 100644 --- a/eodag/rest/stac.py +++ b/eodag/rest/stac.py @@ -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), @@ -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) @@ -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 @@ -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