From 050fe6ab22b3d0d87136d2f92180e6e2342f78b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Ro=C3=9Fner?= <rossner@univention.de>
Date: Mon, 8 Jan 2024 07:55:08 +0100
Subject: [PATCH] fix: Print credentials when importing random users

---
 lib/random_user.py          | 4 ++--
 user_import_udm_rest_api.py | 7 +++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/random_user.py b/lib/random_user.py
index fa2b1d2..097049b 100644
--- a/lib/random_user.py
+++ b/lib/random_user.py
@@ -61,8 +61,8 @@ class RandomUser:
             person["roomNumber"] = str(random.randint(1, 50))+"."+str(random.randint(1, 50))+random.choice(string.ascii_uppercase)
             person["email"] = "rossner@univention.de"
             person['is_admin'] = False
-            callback(person)
+            callback(person, random = True)
             if create_admins:
                 person['username'] = person['username']+'-admin'
                 person['is_admin'] = True
-                callback(person)
+                callback(person, random = True)
diff --git a/user_import_udm_rest_api.py b/user_import_udm_rest_api.py
index 0c9ebd0..d1b9f85 100755
--- a/user_import_udm_rest_api.py
+++ b/user_import_udm_rest_api.py
@@ -15,14 +15,17 @@ from lib.import_user import ImportUser
 admin_user = 'default.admin'
 logging.basicConfig(format='%(asctime)s %(message)s', level=logging.ERROR)
 
-def import_callback(person):
+def import_callback(person, random = False):
     global new_user_password
     if len(new_user_password) < 1:
         person['password'] = ''.join(random.choice(string.ascii_lowercase) for _ in range(16))
     else:
         person['password'] = new_user_password
     ucs.set_user(person)
-    logging.error(f"# {ucs.get_counter()}")
+    if random:
+        logging.error(f"# {ucs.get_counter()}: {person['username']} / {person['password']}")
+    else:
+        logging.error(f"# {ucs.get_counter()}")
 
 if os.getenv('IMPORT_DOMAIN'):
     base_url = os.getenv('IMPORT_DOMAIN')
-- 
GitLab