Compare commits
6 Commits
ab248fb9c3
...
main
Author | SHA1 | Date | |
---|---|---|---|
c12ee79458 | |||
d05d812189
|
|||
4bef39c728
|
|||
ad8aa8a5ba
|
|||
f99d069d61
|
|||
7c710d2236
|
@ -6,6 +6,7 @@ import json
|
|||||||
from os import environ
|
from os import environ
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
from keycloak import KeycloakAdmin
|
from keycloak import KeycloakAdmin
|
||||||
|
|
||||||
@ -36,10 +37,13 @@ if not exists(Path("accounts.txt").absolute()):
|
|||||||
print("Missing accounts.txt!")
|
print("Missing accounts.txt!")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
with open("emails.txt") as handle:
|
with open("accounts.txt") as handle:
|
||||||
emails = handle.readlines()
|
emails = [email.strip() for email in handle.readlines()]
|
||||||
|
|
||||||
|
print(f"Parsed {emails} from accounts.txt")
|
||||||
|
|
||||||
keycloak = init_keycloak()
|
keycloak = init_keycloak()
|
||||||
|
print(f"Current user account count: {keycloak.users_count()}")
|
||||||
|
|
||||||
for email in emails:
|
for email in emails:
|
||||||
username = email.split("@")[0].strip()
|
username = email.split("@")[0].strip()
|
||||||
@ -54,16 +58,26 @@ for email in emails:
|
|||||||
"realmRoles": [
|
"realmRoles": [
|
||||||
"user_default",
|
"user_default",
|
||||||
],
|
],
|
||||||
|
"requiredActions": ["UPDATE_PASSWORD", "UPDATE_PROFILE"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print(f"payload: {payload}")
|
||||||
|
if not confirm():
|
||||||
|
print("Bailing out on request...")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_id = keycloak.create_user(payload, exist_ok=False)
|
user_id = keycloak.create_user(payload, exist_ok=True)
|
||||||
keycloak.send_update_account(
|
print(f"Account created for {email}")
|
||||||
user_id=user_id, payload=json.dumps(["UPDATE_PASSWORD", "UPDATE_PROFILE"])
|
|
||||||
)
|
|
||||||
keycloak.send_verify_email(user_id=user_id)
|
keycloak.send_verify_email(user_id=user_id)
|
||||||
|
print(f"Verification mail sent to {email}")
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
print(f"Keycloak user registration failed, saw: {exception}")
|
print(f"Keycloak user registration failed, saw: {exception}")
|
||||||
if not confirm():
|
if not confirm():
|
||||||
print("Bailing out on request...")
|
print("Bailing out on request...")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
print("Sleeping one second to not overload the server...")
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
print(f"Final user account count: {keycloak.users_count()}")
|
||||||
|
Reference in New Issue
Block a user