Skip to content

Commit

Permalink
Update charm libs
Browse files Browse the repository at this point in the history
  • Loading branch information
canonical-iam committed Dec 30, 2024
1 parent 6dd107c commit e77af78
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 993 deletions.
19 changes: 12 additions & 7 deletions lib/charms/kratos/v0/kratos_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See LICENSE file for licensing details.

"""Interface library for sharing kratos info.
This library provides a Python API for both requesting and providing kratos deployment info,
such as endpoints, namespace and ConfigMap details.
## Getting Started
Expand Down Expand Up @@ -39,6 +40,7 @@ def some_event_function():
"""

import logging
from os.path import join
from typing import Dict, Optional

from ops.charm import CharmBase, RelationCreatedEvent
Expand All @@ -52,7 +54,7 @@ def some_event_function():

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1
LIBPATCH = 3

RELATION_NAME = "kratos-info"
INTERFACE_NAME = "kratos_info"
Expand Down Expand Up @@ -81,9 +83,7 @@ def __init__(self, charm: CharmBase, relation_name: str = RELATION_NAME):
self._relation_name = relation_name

events = self._charm.on[relation_name]
self.framework.observe(
events.relation_created, self._on_info_provider_relation_created
)
self.framework.observe(events.relation_created, self._on_info_provider_relation_created)

def _on_info_provider_relation_created(self, event: RelationCreatedEvent) -> None:
self.on.ready.emit()
Expand All @@ -92,23 +92,28 @@ def send_info_relation_data(
self,
admin_endpoint: str,
public_endpoint: str,
external_url: str,
providers_configmap_name: str,
schemas_configmap_name: str,
configmaps_namespace: str,
mfa_enabled: bool,
) -> None:
"""Updates relation with endpoints and configmaps info."""
"""Updates relation with endpoints, config and configmaps info."""
if not self._charm.unit.is_leader():
return

external_url = external_url if external_url.endswith("/") else external_url + "/"

relations = self.model.relations[self._relation_name]
info_databag = {
"admin_endpoint": admin_endpoint,
"public_endpoint": public_endpoint,
"login_browser_endpoint": f"{public_endpoint}/self-service/login/browser",
"login_browser_endpoint": join(external_url, "self-service/login/browser"),
"sessions_endpoint": f"{public_endpoint}/sessions/whoami",
"providers_configmap_name": providers_configmap_name,
"schemas_configmap_name": schemas_configmap_name,
"configmaps_namespace": configmaps_namespace,
"mfa_enabled": str(mfa_enabled),
}

for relation in relations:
Expand All @@ -117,6 +122,7 @@ def send_info_relation_data(

class KratosInfoRelationError(Exception):
"""Base class for the relation exceptions."""

pass


Expand Down Expand Up @@ -150,7 +156,6 @@ def is_ready(self) -> bool:
return False
return True


def get_kratos_info(self) -> Optional[Dict]:
"""Get the kratos info."""
info = self.model.relations[self.relation_name]
Expand Down
Loading

0 comments on commit e77af78

Please sign in to comment.