LDAP Target Implementation
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The LDAP Target Implementation is a specialized data loading module designed to synchronize directory information from Singer-compatible sources into an LDAP directory server. It leverages the flext-core and flext-ldap frameworks to provide a structured, schema-aware approach to managing LDAP entries, including users, groups, and organizational units.
The implementation functions as a Singer Target, processing standard JSONL streams (SCHEMA, RECORD, and STATE messages) and translating them into LDAP operations such as Add, Modify, and Delete. It supports advanced features like DN (Distinguished Name) template construction, attribute mapping, and configurable object classes.
Sources: src/flext_target_ldap/api.py:15-30, README.md:9-12
Architecture and Components
The system follows a tiered architecture consisting of a public facade, specialized sinks for different data types, and a low-level LDAP client for server communication.
Core Components
- FlextTargetLdap (Facade): The main entry point that coordinates the initialization of the orchestrator, DI container, and sink resolution.
- Sinks (Stream Handlers): Specialized classes (
FlextTargetLdapUsersSink,FlextTargetLdapGroupsSink, etc.) that handle stream-specific logic for attribute transformation and DN generation. - FlextTargetLdapClient: A wrapper around the
flext-ldapAPI that manages connections, LDIF entry building, and execution of LDAP operations.
Component Relationship
The following diagram illustrates the relationship between the primary classes in the implementation.
Data Flow and Record Processing
The target processes Singer messages from stdin. When a RECORD message is received, it is routed to the appropriate sink based on the stream name.
Processing Logic
- Input Reading: The
run_climethod reads JSONL lines from standard input. - Sink Selection: The target selects a sink (e.g.,
UsersSink) based on thestreamfield. - DN Construction: The sink generates a unique Distinguished Name (DN) for the record using either a provided
dnfield or by interpolating RDN attributes (likeuidorcn) with thebase_dn. - Attribute Building: Source fields are mapped to LDAP attributes based on the
attribute_mappingconfiguration. - Persistence: The client attempts an
ADDoperation. If the entry exists andupdate_existing_entriesis enabled, it falls back to aMODIFYoperation.
Configuration and Settings
Configuration is managed through the FlextTargetLdapSettings class, which supports both flat Singer-style configuration and nested object structures.
Key Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
connection | Object | - | Host, port, and credentials for the LDAP server. |
base_dn | String | - | The base DN under which entries are created. |
user_rdn_attribute | String | uid | Attribute used to form the RDN for user entries. |
create_missing_entries | Boolean | True | Whether to create entries that don't exist. |
update_existing_entries | Boolean | True | Whether to update entries if they already exist. |
attribute_mapping | Map | {} | Mapping of Singer fields to LDAP attributes. |
object_classes | List | ["top"] | Default object classes for new entries. |
Sources: src/flext_target_ldap/settings.py:85-150, src/flext_target_ldap/_constants/base.py:20-45
Sink Specializations
The implementation provides specialized sinks to handle the unique requirements of common LDAP object types.
Users Sink (FlextTargetLdapUsersSink)
- RDN Logic: Defaults to using
uidfor the Relative Distinguished Name. - Object Classes: Automatically includes
inetOrgPerson,organizationalPerson,person, andtop. - Field Mapping: Maps common Singer fields like
emailtomailandfirst_nametogivenName.
Groups Sink (FlextTargetLdapGroupsSink)
- RDN Logic: Defaults to using
cn(Common Name). - Object Classes: Includes
groupOfNamesandtop. - Member Management: Maps the
memberssource field to the LDAPmemberattribute.
Sources: src/flext_target_ldap/_models/sinks.py:266-310, src/flext_target_ldap/_models/sinks.py:345-380
LDAP Client Operations
The FlextTargetLdapClient interacts with the LDAP server using the flext-ldap API. It encapsulates the complexities of LDIF (LDAP Data Interchange Format) generation.
Conclusion
The LDAP Target Implementation provides a robust, extensible framework for loading data into LDAP directories. By utilizing specialized sinks and a centralized configuration model, it ensures that data is transformed accurately according to LDAP schema requirements while maintaining compatibility with the Singer ecosystem.