ldap¶
The charmlibs.interfaces.ldap package.
Juju Charm Library for the ldap Juju Interface¶
This Juju charm library contains the Provider and Requirer classes for handling
the ldap interface.
Requirer Charm¶
The requirer charm is expected to:
Provide information for the provider charm to deliver LDAP related information in the juju integration, in order to communicate with the LDAP server and authenticate LDAP operations
Listen to the custom juju event
LdapReadyEventto obtain the LDAP related information from the integrationListen to the custom juju event
LdapUnavailableEventto handle the situation when the LDAP integration is broken
from charmlibs.interfaces.ldap import (
LdapRequirer,
LdapReadyEvent,
LdapUnavailableEvent,
)
class RequirerCharm(CharmBase):
# LDAP requirer charm that integrates with an LDAP provider charm.
def __init__(self, *args):
super().__init__(*args)
self.ldap_requirer = LdapRequirer(self)
self.framework.observe(
self.ldap_requirer.on.ldap_ready,
self._on_ldap_ready,
)
self.framework.observe(
self.ldap_requirer.on.ldap_unavailable,
self._on_ldap_unavailable,
)
def _on_ldap_ready(self, event: LdapReadyEvent) -> None:
# Consume the LDAP related information
ldap_data = self.ldap_requirer.consume_ldap_relation_data(
relation=event.relation,
)
# Configure the LDAP requirer charm
...
def _on_ldap_unavailable(self, event: LdapUnavailableEvent) -> None:
# Handle the situation where the LDAP integration is broken
...
As shown above, the library offers custom juju events to handle specific situations, which are listed below:
ldap_ready: event emitted when the LDAP related information is ready for requirer charm to use.ldap_unavailable: event emitted when the LDAP integration is broken.
Additionally, the requirer charmed operator needs to declare the ldap
interface in the metadata.yaml:
requires:
ldap:
interface: ldap
Provider Charm¶
The provider charm is expected to:
Use the information provided by the requirer charm to provide LDAP related information for the requirer charm to connect and authenticate to the LDAP server
Listen to the custom juju event
LdapRequestedEventto offer LDAP related information in the integration
from charmlibs.interfaces.ldap import (
LdapProvider,
LdapRequestedEvent,
)
class ProviderCharm(CharmBase):
# LDAP provider charm.
def __init__(self, *args):
super().__init__(*args)
self.ldap_provider = LdapProvider(self)
self.framework.observe(
self.ldap_provider.on.ldap_requested,
self._on_ldap_requested,
)
def _on_ldap_requested(self, event: LdapRequestedEvent) -> None:
# Consume the information provided by the requirer charm
requirer_data = event.data
# Prepare the LDAP related information using the requirer's data
ldap_data = ...
# Update the integration data
self.ldap_provider.update_relations_app_data(
relation.id,
ldap_data,
)
As shown above, the library offers custom juju events to handle specific situations, which are listed below:
ldap_requested: event emitted when the requirer charm is requesting the LDAP related information in order to connect and authenticate to the LDAP server.
- class LdapProvider(charm: CharmBase, relation_name: str = 'ldap')¶
Bases:
_LdapInterface- on¶
- get_bind_password(relation_id: int) str | None¶
Retrieve the bind account password for a given integration.
- update_relations_app_data(
- data: LdapProviderBaseData | LdapProviderData,
- /,
- relation_id: int | None = None,
An API for the provider charm to provide the LDAP related information.
- class LdapProviderData(
- *,
- urls: list[str],
- ldaps_urls: list[str],
- base_dn: str,
- starttls: Annotated[bool, Strict(strict=True)],
- bind_dn: str,
- bind_password: str,
- bind_password_secret: str | None = None,
- auth_method: Literal['simple'],
Bases:
LdapProviderBaseData
- class LdapReadyEvent( )¶
Bases:
RelationEventAn event when the LDAP related information is ready.
- class LdapRequestedEvent(handle: Handle, relation: Relation)¶
Bases:
RelationEventAn event emitted when the LDAP integration is built.
- property data: LdapRequirerData | None¶
- class LdapRequirer(
- charm: CharmBase,
- relation_name: str = 'ldap',
- *,
- data: LdapRequirerData | None = None,
Bases:
_LdapInterfaceAn LDAP requirer to consume data delivered by an LDAP provider charm.
- on¶
- consume_ldap_relation_data( ) LdapProviderData | None¶
Consume the LDAP related information from the application databag.
- ready(relation_id: int | None = None) bool¶
Check if the resource has been created.
This function can be used to check if the Provider answered with data in the charm code when outside an event callback.
- Parameters:
relation_id (int, optional) – When provided the check is done only for the relation id provided, otherwise the check is done for all relations
- Returns:
True or False
- Raises:
IndexError – If relation_id is provided but that relation does not exist
-
)¶
Bases:
RelationEventAn event when the LDAP integration is unavailable.