Bug 50711 - [Kelvin API] hooks for user resource
Summary: [Kelvin API] hooks for user resource
Status: CLOSED FIXED
Alias: None
Product: UCS@school
Classification: Unclassified
Component: HTTP-API (Kelvin)
Version: UCS@school 4.4
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: Daniel Tröder
QA Contact: Jürn Brodersen
URL:
Keywords:
Depends on:
Blocks: 50637
  Show dependency treegraph
 
Reported: 2020-01-13 09:29 CET by Daniel Tröder
Modified: 2021-02-23 09:29 CET (History)
1 user (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):
Customer ID:
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 2020-01-13 09:29:23 CET
The Kelvin HTTP-API should execute some kind of hooks that allow changing the behavior of the user resource.
It should be as simple as possible to adapt existing python import hooks (subclasses of ucsschool.importer.utils.import_pyhook.ImportPyHook) to use in the Kelvin API.
Comment 1 Daniel Tröder univentionstaff 2020-01-13 09:32:12 CET
/var/lib/ucs-school-import/kelvin-hooks is a volume mounted into the docker container, so it can be accessed from the host.
The directory content will be scanned when the Kelvin API server starts.

[feature/kelvin e7b0c4515] Bug #50711: host accessable directory for kelvin import hooks
Comment 2 Daniel Tröder univentionstaff 2020-01-14 19:10:50 CET
/var/lib/ucs-school-import/kelvin-hooks is a volume mounted into the docker container, so it can be accessed from the host. If it contains hook classes that inherit from ucsschool.importer.utils.import_pyhook.ImportPyHook, they are executed when users are managed through the Kelvin API.

The hooks are very similar to the Python hooks for the UCS@school import. The differences are:

* Python 3.7 only
* Only three types of hooks are executed: ``UserPyHook``, ``FormatPyHook`` and ``ConfigPyHook`` (all located in modules in the ``ucsschool.importer.utils`` package).
* ``self.dry_run`` is always ``False``
* ``self.lo`` is always a LDAP connection with write permissions (``cn=admin``) as ``dry_run`` is always ``False``
* ``FormatPyHook`` and ``ConfigPyHook`` are the same as in the UCS@school import, but a ``UserPyHook`` hook instance has an additional member ``self.udm``.

[feature/kelvin] ea16c2346 Bug #50711: add support for executing import hooks in Kelvin API
[feature/kelvin] 95a556019 Bug #50711: fix encoding and role detection
[feature/kelvin] 77323a961 Bug #50711: fix test
[feature/kelvin] e0360a5d7 Bug #50711: add tests for hooks
[feature/kelvin] 0c15278c4 Bug #50711: linting fixes
Comment 3 Daniel Tröder univentionstaff 2020-01-14 19:19:33 CET
[feature/kelvin b5d7f1dda] Bug #50711: improve readme in hook dir
Comment 4 Daniel Tröder univentionstaff 2020-01-16 15:18:45 CET
In contrast to the UCS@school import, the Kelvin API server should not stop working, when a hook with an error is loaded:

[feature/kelvin] 053b461ec Bug #50711: prevent crashing API server when failing to load a hook

The hook tests didn't remove their files from the Python cache and contained duplicate code:

[feature/kelvin] e1f167ad5 Bug #50711: cleanup python cache, refactor common code

Linting fixes:

[feature/kelvin] 508bac753 Bug #50711: fix format
Comment 5 Daniel Tröder univentionstaff 2020-01-17 14:58:33 CET
[feature/kelvin fa879a099] Bug #50711: remove temporary files after test run
Comment 6 Jürn Brodersen univentionstaff 2020-01-21 11:42:18 CET
What I tested:
Tests look good and are green -> OK
Added a hook -> OK

-> Verified
Comment 7 Daniel Tröder univentionstaff 2021-02-23 09:29:58 CET
A Kelvin API app with the changes in this bug has been published.