Skip to content
Snippets Groups Projects
Commit d06937c6 authored by Mart van Santen's avatar Mart van Santen
Browse files

Processed feedback

parent c2dc6cc2
No related branches found
No related tags found
2 merge requests!68Merge loginpanel into main and release 0.5.0,!60Resolve "Allow CLI to set password"
...@@ -30,7 +30,7 @@ class KratosUser(): ...@@ -30,7 +30,7 @@ class KratosUser():
""" """
api = None api = None
uuid = None __uuid = None
email = None email = None
name = None name = None
state = None state = None
...@@ -44,7 +44,7 @@ class KratosUser(): ...@@ -44,7 +44,7 @@ class KratosUser():
try: try:
obj = api.admin_get_identity(uuid) obj = api.admin_get_identity(uuid)
if obj: if obj:
self.uuid = uuid self.__uuid = uuid
try: try:
self.name = obj.traits['name'] self.name = obj.traits['name']
except KeyError: except KeyError:
...@@ -54,21 +54,23 @@ class KratosUser(): ...@@ -54,21 +54,23 @@ class KratosUser():
self.created_at = obj.created_at self.created_at = obj.created_at
self.updated_at = obj.updated_at self.updated_at = obj.updated_at
except KratosApiException as error: 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): def __repr__(self):
return f"\"{self.name}\" <{self.email}>" return f"\"{self.name}\" <{self.email}>"
@property uuid
def uuid(self):
return self.__uuid
def save(self): def save(self):
"""Saves this object into the kratos backend database. If the object """Saves this object into the kratos backend database. If the object
is new, it will create, otherwise update an entry. is new, it will create, otherwise update an entry.
:raise: BackendError is an error with Kratos happened. :raise: BackendError is an error with Kratos happened.
""" """
# Traits are the "profile" values we will set, kratos will complain on # 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. # empty values, so we check if "name" is set and only add it if so.
traits = {'email':self.email} traits = {'email':self.email}
...@@ -77,14 +79,14 @@ class KratosUser(): ...@@ -77,14 +79,14 @@ class KratosUser():
traits['name'] = self.name traits['name'] = self.name
# If we have a UUID, we are updating # If we have a UUID, we are updating
if self.uuid: if self.__uuid:
body = AdminUpdateIdentityBody( body = AdminUpdateIdentityBody(
schema_id="default", schema_id="default",
state=self.state, state=self.state,
traits=traits, traits=traits,
) )
try: try:
api_response = self.api.admin_update_identity(self.uuid, api_response = self.api.admin_update_identity(self.__uuid,
admin_update_identity_body=body) admin_update_identity_body=body)
except KratosApiException as error: except KratosApiException as error:
raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error
...@@ -99,7 +101,7 @@ class KratosUser(): ...@@ -99,7 +101,7 @@ class KratosUser():
api_response = self.api.admin_create_identity( api_response = self.api.admin_create_identity(
admin_create_identity_body=body) admin_create_identity_body=body)
if api_response.id: if api_response.id:
self.uuid = api_response.id self.__uuid = api_response.id
except KratosApiException as error: except KratosApiException as error:
raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error raise BackendError(f"Unable to save entry, kratos replied with:{error}") from error
...@@ -107,12 +109,14 @@ class KratosUser(): ...@@ -107,12 +109,14 @@ class KratosUser():
"""Deletes the object from kratos """Deletes the object from kratos
:raise: BackendError if Krator API call fails :raise: BackendError if Krator API call fails
""" """
if self.uuid: if self.__uuid:
try: try:
self.api.admin_delete_identity(self.uuid) self.api.admin_delete_identity(self.__uuid)
return True
except KratosApiException as error: 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 @staticmethod
def find_by_email(api, email): def find_by_email(api, email):
...@@ -194,7 +198,7 @@ class KratosUser(): ...@@ -194,7 +198,7 @@ class KratosUser():
# Create body request to get recovery link with admin API # Create body request to get recovery link with admin API
body = AdminCreateSelfServiceRecoveryLinkBody( body = AdminCreateSelfServiceRecoveryLinkBody(
expires_in="15m", expires_in="15m",
identity_id=self.uuid identity_id=self.__uuid
) )
# Get recovery link from admin API # Get recovery link from admin API
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment