diff --git a/openeo/rest/capabilities.py b/openeo/rest/capabilities.py index a39f97512..08f6435a7 100644 --- a/openeo/rest/capabilities.py +++ b/openeo/rest/capabilities.py @@ -1,4 +1,4 @@ -from typing import List, Optional, Union +from typing import Dict, List, Optional, Union from openeo.internal.jupyter import render_component from openeo.util import deep_get @@ -53,3 +53,13 @@ def list_plans(self) -> List[dict]: def _repr_html_(self): return render_component("capabilities", data=self.capabilities, parameters={"url": self.url}) + + def get_federation(self) -> Union[Dict[str, dict], None]: + """ + Lists all back-ends (with details, such as URL) that are part of the federation + if this backend acts as a federated backend, + as specified in the openEO Federation Extension. + Returns ``None`` otherwise + """ + # TODO: also check related conformance class in `/conformance`? + return self.get("federation") diff --git a/tests/rest/test_capabilities.py b/tests/rest/test_capabilities.py index eebe42dbc..bacd31b20 100644 --- a/tests/rest/test_capabilities.py +++ b/tests/rest/test_capabilities.py @@ -49,3 +49,20 @@ def test_list_plans(self): assert OpenEoCapabilities({"billing": None}).list_plans() == [] assert OpenEoCapabilities({"billing": {"plans": []}}).list_plans() == [] assert OpenEoCapabilities({"billing": {"plans": [{"name": "free"}]}}).list_plans() == [{"name": "free"}] + + def test_federation_absent(self): + assert OpenEoCapabilities({}).get_federation() is None + + def test_federation_present(self): + data = { + "api_version": "1.2.3", + "federation": { + "a": {"url": "https://a.test/openeo/v2", "title": "A backend"}, + "bb": {"url": "https://openeo.b.test/v9"}, + }, + } + capabilities = OpenEoCapabilities(data) + assert capabilities.get_federation() == { + "a": {"url": "https://a.test/openeo/v2", "title": "A backend"}, + "bb": {"url": "https://openeo.b.test/v9"}, + }