From d06937c6efd925157cdbb5e50e03c9ed3e424940 Mon Sep 17 00:00:00 2001 From: Mart van Santen <mart@greenhost.nl> Date: Tue, 7 Dec 2021 07:47:32 +0100 Subject: [PATCH] Processed feedback --- login/kratos.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/login/kratos.py b/login/kratos.py index 5ae1bb6..d79e5bb 100644 --- a/login/kratos.py +++ b/login/kratos.py @@ -30,7 +30,7 @@ class KratosUser(): """ api = None - uuid = None + __uuid = None email = None name = None state = None @@ -44,7 +44,7 @@ class KratosUser(): try: obj = api.admin_get_identity(uuid) if obj: - self.uuid = uuid + self.__uuid = uuid try: self.name = obj.traits['name'] except KeyError: @@ -54,21 +54,23 @@ class KratosUser(): self.created_at = obj.created_at self.updated_at = obj.updated_at except KratosApiException as error: - print(f"Exception when calling V0alpha2Api->admin_get_identity: {error}") + raise BackendError(f"Unable to get entry, kratos replied with: {error}") from error def __repr__(self): return f"\"{self.name}\" <{self.email}>" + @property uuid + def uuid(self): + return self.__uuid + def save(self): """Saves this object into the kratos backend database. If the object is new, it will create, otherwise update an entry. :raise: BackendError is an error with Kratos happened. """ - - # Traits are the "profile" values we will set, kratos will complain on # empty values, so we check if "name" is set and only add it if so. traits = {'email':self.email} @@ -77,14 +79,14 @@ class KratosUser(): traits['name'] = self.name # If we have a UUID, we are updating - if self.uuid: + if self.__uuid: body = AdminUpdateIdentityBody( schema_id="default", state=self.state, traits=traits, ) try: - api_response = self.api.admin_update_identity(self.uuid, + api_response = self.api.admin_update_identity(self.__uuid, admin_update_identity_body=body) except KratosApiException as error: raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error @@ -99,7 +101,7 @@ class KratosUser(): api_response = self.api.admin_create_identity( admin_create_identity_body=body) if api_response.id: - self.uuid = api_response.id + self.__uuid = api_response.id except KratosApiException as error: raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error @@ -107,12 +109,14 @@ class KratosUser(): """Deletes the object from kratos :raise: BackendError if Krator API call fails """ - if self.uuid: + if self.__uuid: try: - self.api.admin_delete_identity(self.uuid) + self.api.admin_delete_identity(self.__uuid) + return True except KratosApiException as error: - raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error + raise BackendError(f"Unable to delete entry, kratos replied with:{error}") from error + return False @staticmethod def find_by_email(api, email): @@ -194,7 +198,7 @@ class KratosUser(): # Create body request to get recovery link with admin API body = AdminCreateSelfServiceRecoveryLinkBody( expires_in="15m", - identity_id=self.uuid + identity_id=self.__uuid ) # Get recovery link from admin API -- GitLab