From a28fbb22711657c6ff7e71cd1241f9026cc230cd Mon Sep 17 00:00:00 2001 From: lilly Date: Sun, 13 Oct 2024 21:44:38 +0200 Subject: [PATCH] add management command for irz ldap utils --- .../management/commands/irz_ldap.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 mafiasi/registration/management/commands/irz_ldap.py diff --git a/mafiasi/registration/management/commands/irz_ldap.py b/mafiasi/registration/management/commands/irz_ldap.py new file mode 100644 index 00000000..c0ad826e --- /dev/null +++ b/mafiasi/registration/management/commands/irz_ldap.py @@ -0,0 +1,24 @@ +from argparse import ArgumentParser +from pprint import pprint + +from django.conf import settings +from django.core.management import BaseCommand + +from mafiasi.registration import utils + + +class Command(BaseCommand): + help = "Utilities for querying the IRZ ldap" + + def add_arguments(self, parser: ArgumentParser): + argg = parser.add_mutually_exclusive_group(required=True) + argg.add_argument("--group", nargs=1, help="Query for a group by gidNumber") + argg.add_argument("--user", nargs=1, help="Query for a user by uid") + + def handle(self, *args, **options): + if options["group"] is not None: + pprint(utils.get_irz_ldap_group(options["group"])) + elif options["user"] is not None: + pprint(utils.get_irz_ldap_entry(options["user"])) + else: + raise ValueError(f"options contains neither a group nor user parameter: {options}")