cmsmanage/tasks/management/commands/import_ldap_user.py

19 lines
540 B
Python
Raw Normal View History

from django.core.management.base import BaseCommand
from django_auth_ldap.backend import LDAPBackend
class Command(BaseCommand):
2022-01-24 23:37:04 -05:00
help = "Import a user from LDAP by username"
def add_arguments(self, parser):
2022-01-24 23:37:04 -05:00
parser.add_argument("username", type=str)
def handle(self, *args, **options):
2022-01-24 23:37:04 -05:00
username = options["username"]
user = LDAPBackend().populate_user(username)
if user is None:
raise Exception(f"No user named {username}")
else:
print("Imported user:", user)