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.path import exists
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
|
||||
from keycloak import KeycloakAdmin
|
||||
|
||||
@ -36,10 +37,13 @@ if not exists(Path("accounts.txt").absolute()):
|
||||
print("Missing accounts.txt!")
|
||||
exit(1)
|
||||
|
||||
with open("emails.txt") as handle:
|
||||
emails = handle.readlines()
|
||||
with open("accounts.txt") as handle:
|
||||
emails = [email.strip() for email in handle.readlines()]
|
||||
|
||||
print(f"Parsed {emails} from accounts.txt")
|
||||
|
||||
keycloak = init_keycloak()
|
||||
print(f"Current user account count: {keycloak.users_count()}")
|
||||
|
||||
for email in emails:
|
||||
username = email.split("@")[0].strip()
|
||||
@ -54,16 +58,26 @@ for email in emails:
|
||||
"realmRoles": [
|
||||
"user_default",
|
||||
],
|
||||
"requiredActions": ["UPDATE_PASSWORD", "UPDATE_PROFILE"],
|
||||
}
|
||||
|
||||
print(f"payload: {payload}")
|
||||
if not confirm():
|
||||
print("Bailing out on request...")
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
user_id = keycloak.create_user(payload, exist_ok=False)
|
||||
keycloak.send_update_account(
|
||||
user_id=user_id, payload=json.dumps(["UPDATE_PASSWORD", "UPDATE_PROFILE"])
|
||||
)
|
||||
user_id = keycloak.create_user(payload, exist_ok=True)
|
||||
print(f"Account created for {email}")
|
||||
keycloak.send_verify_email(user_id=user_id)
|
||||
print(f"Verification mail sent to {email}")
|
||||
except Exception as exception:
|
||||
print(f"Keycloak user registration failed, saw: {exception}")
|
||||
if not confirm():
|
||||
print("Bailing out on request...")
|
||||
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