Skip to content

Commit

Permalink
Issue Open-EO#668 add OpenEOCapabilities.get_federation to list feder…
Browse files Browse the repository at this point in the history
…ation backends
  • Loading branch information
soxofaan committed Jan 24, 2025
1 parent 082a2f5 commit 83194d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion openeo/rest/capabilities.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
17 changes: 17 additions & 0 deletions tests/rest/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}

0 comments on commit 83194d7

Please sign in to comment.