Extensibility and Customization
Relevant source files
The following files were used as context for generating this wiki page:
Extensibility and customization in flext-target-ldap are achieved through a modular architecture that allows developers to override default behaviors for LDAP entry creation, attribute mapping, and data transformation. The system leverages the FLEXT ecosystem's unified model standards, providing flexible interfaces for defining how Singer stream records are translated into LDAP-compliant directory entries.
The customization framework primarily centers on specialized Sink classes and declarative configuration settings. By extending base classes or providing custom transformation rules, users can adapt the target to support various LDAP schemas and organizational requirements.
Modular Sink Architecture
The project employs a hierarchical sink structure where FlextTargetLdapBaseSink provides the foundational logic for LDAP operations, and specialized subclasses handle specific object types such as Users, Groups, and Organizational Units.
Custom Sink Implementation
Developers can extend the system by creating new sink classes that inherit from FlextTargetLdapBaseSink. This allows for overriding critical methods like build_dn, build_attributes, and get_object_classes to suit specific directory structures.
The diagram shows the inheritance hierarchy used to customize record processing for different LDAP object types.
Sources: src/flext_target_ldap/_models/sinks.py:108-111, src/flext_target_ldap/api.py:73-77
Sink Selection Logic
The FlextTargetLdap facade dynamically routes incoming Singer streams to the appropriate sink class based on the stream name. If no specialized sink is found, the system defaults to the base sink, ensuring fallback extensibility for generic LDAP objects.
Sources: src/flext_target_ldap/api.py:71-89
Declarative Attribute Mapping
Customization of field translation is handled through the attribute_mapping configuration and the AttributeMapping model. This allows for mapping Singer source fields to target LDAP attributes without modifying core code.
Mapping Configuration
The AttributeMapping entity supports business rule validation, ensuring that field names and LDAP attributes conform to required formats.
| Field | Type | Description |
|---|---|---|
singer_field_name | String | The source field name from Singer data. |
ldap_attribute_name | String | The target LDAP attribute name. |
is_required | Boolean | Whether the attribute is mandatory. |
transformation_rule | String | Optional rule (e.g., 'lowercase', 'trim'). |
default_value | String | Value used if the source field is missing. |
Sources: src/flext_target_ldap/models.py:44-64
Business Rule Validation
The mapping engine validates that LDAP attribute names are alphanumeric with hyphens and that transformation rules match a set of allowed values including lowercase, uppercase, trim, and normalize.
Sources: src/flext_target_ldap/models.py:71-105
Data Transformation Engine
The transformation engine allows for pattern-based replacement of source data before it is written to the directory. This is particularly useful for normalizing data across different systems.
Transformation Rules
Users can define TransformationRule objects that apply regex patterns to source values.
The flow demonstrates how transformation rules are applied to source data before persistence.
Sources: src/flext_target_ldap/models.py:227-247
Flexible Configuration and Validation
The configuration layer is designed to be highly customizable through environment variables and JSON settings. The FlextTargetLdapSettings class uses a model_validator to normalize flat Singer settings into a canonical nested structure.
Environment-Based Customization
The settings model uses an environment prefix TARGET_LDAP_ (or similar defined in constants) to allow runtime overrides of connection parameters, search filters, and batch sizes.
Sources: src/flext_target_ldap/settings.py:34-36
Dynamic DN Construction
DN construction can be customized at the sink level. For example, the FlextTargetLdapUsersSink allows configuring which attribute serves as the RDN (Relative Distinguished Name), defaulting to uid.
def build_dn(self, record: t.TargetLdap.RecordPayload) -> p.Result[str]:
rdn_attr = str(self._target.settings.get("user_rdn_attribute", "uid"))
uid = record.get(rdn_attr)
if not uid:
return r[str].fail(f"No value found for RDN attribute '{rdn_attr}'")
base_dn = self._target.settings.get("base_dn", "dc=example,dc=com")
return r[str].ok(f"{rdn_attr}={uid},{base_dn}")
Sources: src/flext_target_ldap/_models/sinks.py:317-324
Summary
flext-target-ldap provides a robust framework for extensibility through its hierarchical sink architecture, declarative attribute mapping, and regex-based transformation rules. By implementing custom sinks or providing detailed configuration via FlextTargetLdapSettings, developers can tailor the LDAP loading process to specific organizational directory schemas and validation requirements.