import ldap3 # type: ignore def ldap_delete_all_uid_entries( uid: str, config_json: dict ) -> bool: server: ldap3.core.server.Server = ldap3.Server( config_json["ldap_host"], get_info=ldap3.ALL ) try: with ldap3.Connection( server, user=config_json["ldap_bind_dn"], password=config_json["ldap_bind_password"], auto_bind=True, ) as conn: conn.search( search_base=config_json["people_dn"], search_filter=f"(uid={uid}#*)", attributes=["uid"], ) entries_to_delete = [] for entry in conn.entries: entries_to_delete.append(entry.entry_dn) for entry in entries_to_delete: conn.delete(entry) except Exception as e: print(f"Error delete user: {e}") return False return True