-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #668 eliminate FederationExtension abstraction
- for user API that's simpler to navigate - revert to methods iso properties (to allow future tweaks, e.g. return parsed object instead of raw dicts)
- Loading branch information
Showing
9 changed files
with
106 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,26 @@ | ||
import logging | ||
from typing import List, Union | ||
from typing import Dict, List, Union | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
class FederationExtension: | ||
def get_backend_details(data: dict) -> Union[Dict[str, dict], None]: | ||
""" | ||
Wrapper the openEO Federation extension as defined by | ||
https://github.com/Open-EO/openeo-api/tree/master/extensions/federation | ||
.. seealso:: :ref:`federation-extension` | ||
Get federated backend details from capabilities document (``GET /``) | ||
at "federation" field | ||
""" | ||
# TODO: return a richer object instead of raw dicts? | ||
return data.get("federation", None) | ||
|
||
__slots__ = ["_data"] | ||
|
||
def __init__(self, data: dict): | ||
self._data = data | ||
|
||
@property | ||
def missing(self) -> Union[List[str], None]: | ||
""" | ||
Get the ``federation:missing`` property (if any) of the resource, | ||
which lists back-ends that were not available during the request. | ||
Example usage with collection listing request | ||
(using :py:meth:`~openeo.rest.connection.Connection.list_collections()`): | ||
.. code-block:: pycon | ||
|
||
>>> collections = connection.list_collections() | ||
>>> collections.ext_federation.missing | ||
["backend1"] | ||
:return: list of back-end IDs that were not available. | ||
Or None, when ``federation:missing`` is not present in response. | ||
""" | ||
return self._data.get("federation:missing", None) | ||
|
||
def warn_on_missing(self, resource_name: str) -> None: | ||
""" | ||
Warn about presence of non-empty ``federation:missing`` in the resource. | ||
""" | ||
missing = self.missing | ||
if missing: | ||
_log.warning(f"Partial {resource_name}: missing federation components: {missing!r}.") | ||
def get_federation_missing(data: dict, *, resource_name: str, auto_warn: bool = False) -> Union[List[str], None]: | ||
""" | ||
Get "federation:missing" field from response data, if present. | ||
:param data: response data | ||
:param resource_name: name of the requested resource (listing) | ||
:param auto_warn: whether to automatically log a warning if missing federation components are detected. | ||
""" | ||
# TODO: options to return richer objects (e.g. resolve backend id to URL/title) | ||
missing = data.get("federation:missing", None) | ||
if auto_warn and missing: | ||
_log.warning(f"Partial {resource_name}: missing federation components: {missing!r}.") | ||
return missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.