Skip to content

Commit 83194d7

Browse files
committed
Issue #668 add OpenEOCapabilities.get_federation to list federation backends
1 parent 082a2f5 commit 83194d7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

openeo/rest/capabilities.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Union
1+
from typing import Dict, List, Optional, Union
22

33
from openeo.internal.jupyter import render_component
44
from openeo.util import deep_get
@@ -53,3 +53,13 @@ def list_plans(self) -> List[dict]:
5353

5454
def _repr_html_(self):
5555
return render_component("capabilities", data=self.capabilities, parameters={"url": self.url})
56+
57+
def get_federation(self) -> Union[Dict[str, dict], None]:
58+
"""
59+
Lists all back-ends (with details, such as URL) that are part of the federation
60+
if this backend acts as a federated backend,
61+
as specified in the openEO Federation Extension.
62+
Returns ``None`` otherwise
63+
"""
64+
# TODO: also check related conformance class in `/conformance`?
65+
return self.get("federation")

tests/rest/test_capabilities.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,20 @@ def test_list_plans(self):
4949
assert OpenEoCapabilities({"billing": None}).list_plans() == []
5050
assert OpenEoCapabilities({"billing": {"plans": []}}).list_plans() == []
5151
assert OpenEoCapabilities({"billing": {"plans": [{"name": "free"}]}}).list_plans() == [{"name": "free"}]
52+
53+
def test_federation_absent(self):
54+
assert OpenEoCapabilities({}).get_federation() is None
55+
56+
def test_federation_present(self):
57+
data = {
58+
"api_version": "1.2.3",
59+
"federation": {
60+
"a": {"url": "https://a.test/openeo/v2", "title": "A backend"},
61+
"bb": {"url": "https://openeo.b.test/v9"},
62+
},
63+
}
64+
capabilities = OpenEoCapabilities(data)
65+
assert capabilities.get_federation() == {
66+
"a": {"url": "https://a.test/openeo/v2", "title": "A backend"},
67+
"bb": {"url": "https://openeo.b.test/v9"},
68+
}

0 commit comments

Comments
 (0)