Command Line Interface
Relevant source files
The following files were used as context for generating this wiki page:
The Command Line Interface (CLI) for flext-target-ldif serves as the primary entry point for executing the Singer Target, which transforms incoming data streams into LDAP Data Interchange Format (LDIF). It is designed to be compatible with the Singer specification, allowing it to be used within data engineering pipelines and integrated with tools like Meltano.
The CLI is exposed through standard Python entry points and wraps the core FlextTargetLdif logic. It handles configuration loading, validation via JSON schema, and the orchestration of data sinks that write to the filesystem. The interface supports standard Singer flags for configuration and state management, providing a robust mechanism for LDAP-based data warehousing and migration tasks.
Sources: pyproject.toml:57-59, src/flext_target_ldif/target.py:27-58, README.md:12-14
CLI Entry Points and Configuration
The project defines specific command-line aliases that link directly to the target's execution logic. These are managed via the project.scripts section in the build configuration.
Executable Aliases
The following commands are available once the package is installed:
flext-target-ldif: The primary canonical command.target-ldif: A shortened alias for convenience.
Both aliases invoke the cli method of the TargetLDIF class (aliased via FlextTargetLdif in implementation).
Sources: pyproject.toml:57-59, src/flext_target_ldif/target.py:53-55
Interface Architecture
The CLI flow involves initializing the target with a configuration mapping, validating that configuration against a Pydantic-based schema, and ensuring the output directory exists before processing begins.
The diagram shows the initialization and validation flow when the CLI is triggered.
Sources: src/flext_target_ldif/target.py:32-51
Configuration Parameters
The CLI accepts configuration through a JSON file or environment variables (prefixed as defined in FlextSettings). The following table outlines the key configuration parameters available to the user through the interface.
| Parameter | Type | Default | Description |
|---|---|---|---|
output_path | string | ./output | The directory where LDIF files will be written. |
file_naming_pattern | string | {stream_name}_{timestamp}.ldif | Pattern for generated filenames. |
dn_template | string | uid={uid},ou=users,dc=example,dc=com | Template for generating LDAP Distinguished Names. |
line_length | integer | 78 | Maximum length of LDIF lines before folding. |
base64_encode | boolean | false | Whether to force Base64 encoding for all attributes. |
schema_validation | boolean | true | Enables validation against the target's JSON schema. |
Sources: src/flext_target_ldif/target.py:39-43, src/flext_target_ldif/writer.py:46-53, src/flext_target_ldif/models.py:56-91
Internal Data Flow
When the CLI receives records from a Singer Tap, the data flows through the Target class to specific Sinks, and finally to the FlextTargetLdifWriter.
This sequence illustrates how the CLI orchestrates the relationship between the target, its sinks, and the underlying LDIF writer.
Sources: src/flext_target_ldif/target.py:64-75, src/flext_target_ldif/models.py:228-261, src/flext_target_ldif/writer.py:99-115
Validation and Error Handling
The CLI performs strict validation of input configuration to ensure successful LDIF generation. If output_file (when tested) or dn_template are missing or empty, the interface will raise a ValueError.
Logic for Configuration Validation
The validation process filters incoming settings against an allowed_fields set to prevent injection of unsupported parameters into the internal models.
- Required Fields:
output_pathoroutput_filemust be present. - Structure: Fields are validated using
FlextTargetLdifSettings.model_validate. - Formatting: The system ensures the
dn_templatecontains valid placeholders that can be resolved by incoming record keys.
Sources: src/flext_target_ldif/target.py:77-105, src/flext_target_ldif/utilities.py:47-65, src/flext_target_ldif/writer.py:155-161
Conclusion
The Command Line Interface provides a standardized entry point for transforming Singer streams into compliant LDIF files. By leveraging Pydantic-based configuration validation and a structured Sink/Writer architecture, it ensures that data engineers can reliably export LDAP-compatible data with configurable line wrapping, DN generation, and attribute mapping.
Sources: src/flext_target_ldif/target.py:27-30, src/flext_target_ldif/models.py:43-52