Skip to content

Commit

Permalink
Merge pull request #180 from canonical/IAM-699-update-kratos-version
Browse files Browse the repository at this point in the history
chore: bump image version
  • Loading branch information
natalian98 committed Mar 8, 2024
2 parents 8d6c8d7 + 40a6844 commit f660d08
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
oci-image:
type: oci-image
description: Kratos oci-image
upstream-source: ghcr.io/canonical/kratos:1.0.0
upstream-source: ghcr.io/canonical/kratos:1.1.0
requires:
pg-database:
interface: postgresql_client
Expand Down
3 changes: 2 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,8 @@ def _on_delete_identity_action(self, event: ActionEvent) -> None:

if email:
identity = self.kratos.get_identity_from_email(email)
if not identity:
identity_id = identity.get("id")
if not identity_id:
event.fail("Couldn't retrieve identity_id from email.")
return

Expand Down
4 changes: 3 additions & 1 deletion src/kratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ def list_identities(self) -> List:

# TODO: Consider reading from the stream instead of waiting for output
cmd_output = json.loads(self._run_cmd(cmd))
identities = cmd_output.get("identities")
logger.info("Successfully fetched all identities")
return cmd_output

return identities

def get_identity_from_email(self, email: str) -> Optional[Dict]:
"""Get an identity using an email.
Expand Down
15 changes: 12 additions & 3 deletions tests/unit/test_kratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def test_delete_identity(
def test_list_identities(
kratos_api: KratosAPI, kratos_identity_json: Dict, mocked_kratos_process: MagicMock
) -> None:
mocked_kratos_process.wait_output.return_value = (json.dumps([kratos_identity_json]), None)
mocked_kratos_process.wait_output.return_value = (
json.dumps(dict(identities=[kratos_identity_json])),
None,
)

kratos_api.list_identities()

Expand All @@ -150,7 +153,10 @@ def test_list_identities(
def test_get_identity_from_email(
kratos_api: KratosAPI, kratos_identity_json: Dict, mocked_kratos_process: MagicMock
) -> None:
mocked_kratos_process.wait_output.return_value = (json.dumps([kratos_identity_json]), None)
mocked_kratos_process.wait_output.return_value = (
json.dumps(dict(identities=[kratos_identity_json])),
None,
)

identity = kratos_api.get_identity_from_email(kratos_identity_json["traits"]["email"])

Expand All @@ -169,7 +175,10 @@ def test_get_identity_from_email(
def test_get_identity_from_email_with_wrong_mail(
kratos_api: KratosAPI, kratos_identity_json: Dict, mocked_kratos_process: MagicMock
) -> None:
mocked_kratos_process.wait_output.return_value = (json.dumps([kratos_identity_json]), None)
mocked_kratos_process.wait_output.return_value = (
json.dumps(dict(identities=[kratos_identity_json])),
None,
)

identity = kratos_api.get_identity_from_email("mail")

Expand Down

0 comments on commit f660d08

Please sign in to comment.