feat(shared/kanidm): Add helper function sync_call

This avoids wrapping the methods each time we want to call the API in
sync mode
This commit is contained in:
Tom Hubrecht 2025-01-30 09:46:58 +01:00
parent 5940aaa284
commit 6860d6cb3b
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc

View file

@ -1,3 +1,4 @@
from asgiref.sync import async_to_sync
from kanidm import KanidmClient
from loadcredential import Credentials
@ -6,3 +7,10 @@ credentials = Credentials(env_prefix="DGSI_")
klient = KanidmClient(
uri=credentials["KANIDM_URI"], token=credentials["KANIDM_AUTH_TOKEN"]
)
def sync_call(name, *args, **kwargs):
"""
Wraps the required action for use in sync contexts
"""
return async_to_sync(getattr(klient, name))(*args, **kwargs)