Bug 54127 - Handle new expiration_date field in Kelvin API
Handle new expiration_date field in Kelvin API
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: kelvin-rest-api-client
unspecified
Other Mac OS X 10.1
: P5 normal (vote)
: ---
Assigned To: Daniel Tröder
Johannes Keiser
:
Depends on: 54126
Blocks:
  Show dependency treegraph
 
Reported: 2021-11-24 11:39 CET by Daniel Tröder
Modified: 2022-07-04 10:11 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Feature Request
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2021-11-24 11:39:08 CET
+++ This bug was initially created as a clone of Bug #54116 +++
+++ This bug was initially created as a clone of Bug #54126 +++

The Kelvin REST API is getting a new user resource field "expiration_date". Add support for it in the User class.

Handle older Kelvin API versions without "expiration_date" field safely.
Comment 1 Daniel Tröder univentionstaff 2021-11-26 17:08:34 CET
Added support for expiration_date in version 1.5.1 of the package.

[master] 9eedf16 Bug #54127: handle new expiration_date field in Kelvin API

https://test.pypi.org/project/kelvin-rest-api-client/1.5.1/
https://github.com/univention/kelvin-rest-api-client/commit/9eedf167f2a50aacfd7146f8672e575256b0e7e9
https://kelvin-rest-api-client.readthedocs.io/en/latest/history.html

TODO: verify handling of Kelvin API < 1.5.1 (without expiration_date field).
Comment 2 Ole Schwiegert univentionstaff 2021-11-29 00:17:45 CET
The Kelvin Client cannot handle older Kelvin APIs yet.

Executed Code:

import asyncio
from ucsschool.kelvin.client import Session, User, UserResource

if __name__ == "__main__":
    async def get_user(username: str) -> User:
        async with Session(
                "Administrator",
                "univention",
                "10.200.6.110",
                verify=False
        ) as session:
            return await UserResource(session=session).get(name=username)

    obj: User = asyncio.run(get_user("demo_teacher"))
    print(obj.as_dict())
    print(obj.firstname, obj.lastname)



Traceback:

Traceback (most recent call last):
  File "/Users/ole/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch.py", line 14, in <module>
    obj: User = asyncio.run(get_user("demo_teacher"))
  File "/opt/homebrew/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/homebrew/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/ole/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch.py", line 12, in get_user
    return await UserResource(session=session).get(name=username)
  File "/Volumes/CSData/Repos/kelvin-rest-api-client/ucsschool/kelvin/client/base.py", line 189, in get
    return await self.get_from_url(url)
  File "/Volumes/CSData/Repos/kelvin-rest-api-client/ucsschool/kelvin/client/base.py", line 201, in get_from_url
    obj = self.Meta.kelvin_object._from_kelvin_response(resp_json)
  File "/Volumes/CSData/Repos/kelvin-rest-api-client/ucsschool/kelvin/client/user.py", line 166, in _from_kelvin_response
    if response["expiration_date"]:
KeyError: 'expiration_date'
Comment 3 Daniel Tröder univentionstaff 2021-11-29 09:12:10 CET
* The client can now handle Kelvin server version <1.5.1 without 'expiration_date' field (force pushed).
* It "raises" a warning, when it detects and handles a missing 'expiration_date' field.
* The documentation now contains a note about the field having been added with server version 1.5.1 (see https://kelvin-rest-api-client.readthedocs.io/en/latest/usage-users.html).

[master 6711fdf] Bug #54127: handle new expiration_date field in Kelvin API
Comment 4 Johannes Keiser univentionstaff 2021-11-29 15:21:54 CET
OK: Warning is shown if 1.5.1 client is used against 1.5.0 API

  /kelvin-rest-api-client/ucsschool/kelvin/client/user.py:168: RuntimeWarning: User attribute in Kelvin REST API response missing 'expiration_date' attribute. Server version probably < '1.5.1'.

OK: https://kelvin-rest-api-client.readthedocs.io/en/latest/readme.html#tests against 4.4 and 5.0
OK: manual tests against 4.4 and 5.0
OK: code review
OK: changelog + version
OK: docs

-> verified
Comment 5 Daniel Tröder univentionstaff 2021-11-29 15:56:52 CET
Published to PyPI.