2021-05-15 13:27:43 -04:00
|
|
|
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"
|
2021-05-15 13:27:43 -04:00
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
2022-01-24 23:37:04 -05:00
|
|
|
parser.add_argument("username", type=str)
|
2021-05-15 13:27:43 -04:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2022-01-24 23:37:04 -05:00
|
|
|
username = options["username"]
|
2021-05-15 13:27:43 -04:00
|
|
|
user = LDAPBackend().populate_user(username)
|
|
|
|
if user is None:
|
|
|
|
raise Exception(f"No user named {username}")
|
|
|
|
else:
|
|
|
|
print("Imported user:", user)
|