Repository: CS-SI/eodag (python)

Issue:
eodag-authenticated and origin raw assets both available in server mode
In server mode, once #721 is done, make available both eodag-authenticated and origin raw assets using https://github.com/stac-extensions/alternate-assets:
```json
{
  "features": [
    {
      "id": "some-product",
      "assets": {
        "B01": {
          "title": "Download link",
          "href": "http://127.0.0.1:5000/collections/some-collection/items/some-product/download/B01",
          "alternate": {
            "origin": {
              "title": "Origin asset link",
              "href": "s3://path/to/B01-asset"
            }
          }
        }
      }
    }
  ]
}
```


Pull request:
feat(server): stac alternate assets
Fixes #767 

Makes origin assets links available through `asset["alternate"]["origin"]["href"]` in server STAC response.

```json
{
  "features": [
    {
      "id": "some-product",
      "assets": {
        "B01": {
          "title": "Download link",
          "href": "http://127.0.0.1:5000/collections/some-collection/items/some-product/download/B01",
          "alternate": {
            "origin": {
              "title": "Origin asset link",
              "href": "s3://path/to/B01-asset"
            }
          }
        }
      }
    }
  ]
}
```

Patch:
diff --git a/eodag/rest/stac.py b/eodag/rest/stac.py
index 4114e3c5..8f84ddea 100644
--- a/eodag/rest/stac.py
+++ b/eodag/rest/stac.py
@@ -275,20 +275,28 @@ class StacItem(StacCommon):
                     "href"
                 ] = f"{without_arg_url}?{urlencode(query_dict, doseq=True)}"
 
-            # add origin assets to product assets
-            origin_assets = product_item["assets"].pop("origin_assets")
+            # move origin asset urls to alternate links and replace with eodag-server ones
+            origin_assets = product_item["assets"].pop("origin_assets", {})
             if getattr(product, "assets", False):
                 # replace origin asset urls with eodag-server ones
                 for asset_key, asset_value in origin_assets.items():
-                    origin_assets[asset_key]["href"] = without_arg_url
+                    # use origin asset as default
+                    product_item["assets"][asset_key] = asset_value
+                    # origin assets as alternate link
+                    product_item["assets"][asset_key]["alternate"] = {
+                        "origin": {
+                            "title": "Origin asset link",
+                            "href": asset_value["href"],
+                        }
+                    }
+                    # use server-mode assets download links
+                    asset_value["href"] = without_arg_url
                     if query_dict:
-                        origin_assets[asset_key][
+                        product_item["assets"][asset_key][
                             "href"
                         ] += f"/{asset_key}?{urlencode(query_dict, doseq=True)}"
                     else:
-                        origin_assets[asset_key]["href"] += f"/{asset_key}"
-
-                product_item["assets"] = dict(product_item["assets"], **origin_assets)
+                        product_item["assets"][asset_key]["href"] += f"/{asset_key}"
 
             # apply conversion if needed
             for prop_key, prop_val in need_conversion.items():


Test patch:
diff --git a/tests/units/test_stac_utils.py b/tests/units/test_stac_utils.py
index 6b3fd0f1..7e03f4ab 100644
--- a/tests/units/test_stac_utils.py
+++ b/tests/units/test_stac_utils.py
@@ -453,10 +453,16 @@ class TestStacUtils(unittest.TestCase):
             "assets"
         ].items():
             self.assertIn(k, response["features"][0]["assets"].keys())
+            # check asset server-mode download link
             self.assertEqual(
                 response["features"][0]["assets"][k]["href"],
                 f"http://foo/collections/S2_MSI_L2A/items/{product_id}/download/{k}?provider=earth_search",
             )
+            # check asset origin download link
+            self.assertEqual(
+                response["features"][0]["assets"][k]["alternate"]["origin"]["href"],
+                self.earth_search_resp_search_json["features"][0]["assets"][k]["href"],
+            )
         # preferred provider should not be changed
         self.assertEqual("peps", self.rest_utils.eodag_api.get_preferred_provider()[0])