diff --git a/scripts/users.py b/scripts/users.py index 02d2bae..eb49ca3 100755 --- a/scripts/users.py +++ b/scripts/users.py @@ -117,7 +117,6 @@ def validate_username(username: str) -> None: fail(f"invalid username: {username} (allowed: a-z, 0-9, _, ., -)") - def trigger_password_reset(username: str) -> None: url = f"{LLDAP_URL}/auth/reset/step1/{username}" try: @@ -169,7 +168,7 @@ def email_in_use(conn: Connection, email: str) -> bool: return bool(conn.entries) -@app.command("list", help="List existing users (no passwords shown).") +@app.command("list", help="List existing users ") def cmd_list() -> None: with lldap_connection() as conn: conn.search( @@ -192,7 +191,7 @@ def cmd_list() -> None: print(f"{uid:<20} {cn:<30} {mail:<30} {groups}") -@app.command("add", help="Add a user. Omit --password to send an invite email.") +@app.command("add", help="Add a user. Omit --password to send an invite email") def cmd_add( username: str = typer.Option(..., "--username", "-u", help="Username"), displayname: str = typer.Option(..., "--displayname", "-n", help="Display name"), @@ -249,7 +248,7 @@ def cmd_add( print(f"User '{username}' created.") -@app.command("remove", help="Remove a user.") +@app.command("remove", help="Remove a user") def cmd_remove( username: str = typer.Option(..., "--username", "-u", help="Username"), ) -> None: @@ -264,7 +263,7 @@ def cmd_remove( print(f"User '{username}' removed from LLDAP.") -@app.command("reset-password", help="Trigger a password reset email for an existing user.") +@app.command("reset-password", help="Trigger a password reset email for an existing user") def cmd_reset_password( username: str = typer.Option(..., "--username", "-u", help="Username"), confirm: bool = typer.Option( @@ -274,11 +273,8 @@ def cmd_reset_password( ), ) -> None: validate_username(username) - with lldap_connection() as conn: - user_dn = f"uid={username},ou=people,{LLDAP_BASE_DN}" - conn.search(user_dn, "(objectClass=*)", SUBTREE, attributes=["uid"]) - if not conn.entries: + if not user_exists(conn=conn, username=username): fail(f"user '{username}' not found") if confirm: