Configuration & Settings
Relevant source files
The following files were used as context for generating this wiki page:
The configuration and settings system for flext-target-ldif provides a robust, typed infrastructure for managing how Singer records are transformed and written into LDAP Data Interchange Format (LDIF) files. It leverages the flext-core foundation, specifically utilizing Pydantic-based models to ensure runtime type safety, immutability, and environment-variable-driven overrides.
The system is responsible for defining output paths, file naming conventions, Distinguished Name (DN) templates, and attribute mappings. It ensures that the target operates within Singer protocol standards while providing the flexibility needed for enterprise LDAP integrations.
Sources: src/flext_target_ldif/settings.py:1-12, src/flext_target_ldif/target.py:24-40
Configuration Architecture
The architecture centers around the FlextTargetLdifSettings class, which inherits from FlextSettingsBase. This class serves as the single source of truth for the target's operational parameters.
Settings Lifecycle and Validation
Configuration flows from the Singer orchestrator (like Meltano) into the FlextTargetLdif class. Upon initialization, default values are merged with provided settings. If validation is enabled, the system uses Pydantic's model_validate to enforce type constraints and a custom validate_domain_rules method to check for logic-specific constraints, such as ensuring output paths are not empty.
The following diagram illustrates the configuration validation and initialization flow:
Immutable Global State
Settings are defined as "frozen" using Pydantic's ConfigDict. This prevents accidental runtime mutation of the configuration. Overrides are supported via environment variables prefixed with FLEXT_TARGET_LDIF_.
Sources: src/flext_target_ldif/settings.py:24-30
Key Configuration Parameters
The configuration is divided into output management, LDIF formatting, and attribute transformation.
Output and Naming
Parameters in this category control where and how files are written.
| Option | Type | Default | Description |
|---|---|---|---|
output_file | str | output.ldif | The primary output filename. |
output_path | str | ./output | Directory where LDIF files are stored. |
file_naming_pattern | str | {stream_name}_{timestamp}.ldif | Template for generating unique filenames per stream. |
Sources: src/flext_target_ldif/settings.py:32-47, src/flext_target_ldif/target.py:32-36
LDIF Formatting Options
These settings control the technical structure of the generated LDIF records, ensuring compliance with RFC 2849.
dn_template: A string template used to construct the Distinguished Name for each record (e.g.,uid={uid},ou=users,dc=example,dc=com).line_length: Specifies the wrap length for LDIF lines, defaulting to 78.base64_encode: A boolean flag to force Base64 encoding for all attribute values.include_timestamps: Boolean to include metadata about when the entry was generated.
Sources: src/flext_target_ldif/settings.py:48-84, src/flext_target_ldif/writer.py:42-55
Attribute Mapping
The attribute_mapping field is a dictionary (t.StrMapping) that allows users to map source record fields to specific LDAP attribute names. For example, mapping email to mail.
Sources: src/flext_target_ldif/settings.py:54-59, tests/unit/test_target.py:202-210
Domain Validation Logic
The FlextTargetLdifSettings class implements mandatory business rule validation through the validate_domain_rules method. This ensures that critical fields are not just present, but contain valid data before the target starts processing records.
def validate_domain_rules(self) -> p.Result[bool]:
"""Validate required target configuration constraints."""
if not self.output_file.strip():
msg = "Output file cannot be empty"
raise ValueError(msg)
if not self.output_path.strip():
msg = "output_path cannot be empty"
raise ValueError(msg)
if not self.dn_template.strip():
msg = "DN template cannot be empty"
raise ValueError(msg)
return r[bool].ok(value=True)
Sources: src/flext_target_ldif/settings.py:86-100
Internal Model Mapping
The project uses a unified model collection, FlextTargetLdifModels, which encapsulates formatting options into a structured LdifFormatOptions class. This class provides more granular control over the LDIF generation process than the high-level settings.
Summary
The configuration system in flext-target-ldif is designed for high reliability and strictly enforces data integrity. By combining Pydantic's validation with custom domain rules, the system ensures that output LDIF files are consistent and conform to LDAP standards. The use of environment variable prefixes and frozen models makes it suitable for secure, containerized ETL workflows.