From 2ea454d75435d139d237266713d898cd5c3694e8 Mon Sep 17 00:00:00 2001 From: Arie Peterson <arie@greenhost.nl> Date: Fri, 20 Jan 2023 14:19:43 +0100 Subject: [PATCH] Adapt some more kratos API calls to the new library version --- backend/cliapp/cliapp/cli.py | 16 ++++++++-------- backend/helpers/kratos_user.py | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/cliapp/cliapp/cli.py b/backend/cliapp/cliapp/cli.py index 751e58a2..d20c0a8c 100644 --- a/backend/cliapp/cliapp/cli.py +++ b/backend/cliapp/cliapp/cli.py @@ -249,7 +249,7 @@ def show_user(email): internal state/values of the user object :param email: Email address of the user to show """ - user = KratosUser.find_by_email(KRATOS_ADMIN, email) + user = KratosUser.find_by_email(kratos_identity_api, email) if user is not None: print(user) print("") @@ -281,7 +281,7 @@ def update_user(email, field, value): :param value: The value to set the field with """ current_app.logger.info(f"Looking for user with email: {email}") - user = KratosUser.find_by_email(KRATOS_ADMIN, email) + user = KratosUser.find_by_email(kratos_identity_api, email) if not user: current_app.logger.error(f"User with email {email} not found.") sys.exit(1) @@ -303,7 +303,7 @@ def delete_user(email): :param email: Email address of user to delete """ current_app.logger.info(f"Looking for user with email: {email}") - user = KratosUser.find_by_email(KRATOS_ADMIN, email) + user = KratosUser.find_by_email(kratos_identity_api, email) if not user: current_app.logger.error(f"User with email {email} not found.") sys.exit(1) @@ -320,12 +320,12 @@ def create_user(email): current_app.logger.info(f"Creating user with email: ({email})") # Create a user - user = KratosUser.find_by_email(KRATOS_ADMIN, email) + user = KratosUser.find_by_email(kratos_identity_api, email) if user: current_app.logger.info("User already exists. Not recreating") return - user = KratosUser(KRATOS_ADMIN) + user = KratosUser(kratos_identity_api) user.email = email user.save() @@ -350,7 +350,7 @@ def setpassword_user(email, password): try: # Get the ID of the user - kratos_user = KratosUser.find_by_email(KRATOS_ADMIN, email) + kratos_user = KratosUser.find_by_email(kratos_identity_api, email) if kratos_user is None: current_app.logger.error(f"User with email '{email}' not found") sys.exit(1) @@ -375,7 +375,7 @@ def setpassword_user(email, password): def list_user(): """Show a list of users in the database""" current_app.logger.info("Listing users") - users = KratosUser.find_all(KRATOS_ADMIN) + users = KratosUser.find_all(kratos_identity_api) for obj in users: print(obj) @@ -392,7 +392,7 @@ def recover_user(email): try: # Get the ID of the user - kratos_user = KratosUser.find_by_email(KRATOS_ADMIN, email) + kratos_user = KratosUser.find_by_email(kratos_identity_api, email) # Get a recovery URL url = kratos_user.get_recovery_link() diff --git a/backend/helpers/kratos_user.py b/backend/helpers/kratos_user.py index d242b72c..3615809e 100644 --- a/backend/helpers/kratos_user.py +++ b/backend/helpers/kratos_user.py @@ -113,7 +113,7 @@ class KratosUser(): """ if self.__uuid: try: - self.api.admin_delete_identity(self.__uuid) + self.api.delete_identity(self.__uuid) return True except KratosApiException as error: raise BackendError( @@ -133,8 +133,8 @@ class KratosUser(): kratos_id = None # Get out user ID by iterating over all available IDs - data = api.admin_list_identities() - for kratos_obj in data.value: + data = api.list_identities() + for kratos_obj in data: # Unique identifier we use if kratos_obj.traits['email'] == email: kratos_id = str(kratos_obj.id) @@ -152,8 +152,8 @@ class KratosUser(): kratos_id = None return_list = [] # Get out user ID by iterating over all available IDs - data = api.admin_list_identities() - for kratos_obj in data.value: + data = api.list_identities() + for kratos_obj in data: kratos_id = str(kratos_obj.id) return_list.append(KratosUser(api, kratos_id)) -- GitLab