Skip to content
Snippets Groups Projects

Resolve "Allow CLI to set password"

Compare and Show latest version
6 files
+ 31
19
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 22
16
@@ -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,12 +54,16 @@ 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
def uuid(self):
"""Gets the protected UUID propery"""
return self.__uuid
def save(self):
"""Saves this object into the kratos backend database. If the object
@@ -67,8 +71,6 @@ class KratosUser():
: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,18 +109,22 @@ 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):
"""Queries Kratos to find kratos ID for this given identifier
:param: api Kratos ADMIN API Object
:param: email Identifier to look for
:param api: Kratos ADMIN API Object
:param email: Identifier to look for
:return: Return none or string with ID
"""
@@ -160,8 +166,8 @@ class KratosUser():
cookies required for Kratos User Panel UI
:param cookies: str[], list of cookies
:return: string Cookies as string
:rtype: str[]
:return: Cookies concatenated as string
:rtype: str
"""
# Find kratos session cookie & csrf
@@ -194,7 +200,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
Loading