Skip to content

Commit

Permalink
change/logging: edu-sharing API client init fallback when "services" …
Browse files Browse the repository at this point in the history
…list is empty

- early edu-sharing v9.x versions didn't provide a list of services in the initial about["services"] API response, which was a confirmed bug and has been fixed
  - since the fallback is no longer necessary in "healthy" edu-sharing versions, a logging message will be shown (to make devs aware when the fallback is active)
  • Loading branch information
Criamos committed Sep 3, 2024
1 parent d0238b2 commit 8b5485a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions converter/es_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,16 @@ def init_api_client(self):
EduSharing.nodeApi = NODEV1Api(EduSharing.apiClient)
about = EduSharing.aboutApi.about()
if "services" in about and about["services"]:
# edu-sharing API v6.x to v8.1 behavior: looking for the BULK v1 API "version"-dict
# edu-sharing API v6.x to v9.1 behavior: look for the BULK v1 API "version"-dict
EduSharing.version = \
list(filter(lambda x: x["name"] == "BULK", about["services"]))[0]["instances"][0]["version"]
elif "version" in about and about["version"]:
# edu-sharing API v9.x behavior:
# we expect a "version"-dict to exist within the "about"-dict that might look like this:
elif "services" in about and not about["services"] and "version" in about and about["version"]:
# edu-sharing API v9.x workaround:
# if about["services"] is an empty list (instead of the expected list[dict]),
# we're falling back to the about["version"]-dict that might look like this:
# {'major': 1, 'minor': 1, 'renderservice': '9.0', 'repository': '9.0'}
log.info(f"Failed to retrieve BULK v1 API version from edu-sharing during APi client init: "
f"about['services'] was empty (expected: list[dict]). Using about['version'] fallback...")
EduSharing.version = about["version"]
version_str: str = f"{EduSharing.version['major']}.{EduSharing.version['minor']}"
if (
Expand Down

0 comments on commit 8b5485a

Please sign in to comment.