System Constants & Mappings
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
System Constants & Mappings in the flext-target-ldif project define the foundational configuration parameters, LDAP data interchange format (LDIF) standards, and record transformation logic required for converting Singer stream data into compliant LDAP entries. These constants ensure that output files adhere to RFC 2849 specifications, including line folding, character encoding, and attribute mapping protocols.
The system relies on a combination of typed settings via FlextTargetLdifSettings and domain models within FlextTargetLdifModels to govern the behavior of the LDIF writer and sink components. By centralizing these mappings, the target maintains consistency in how Distinguished Names (DNs) are constructed and how complex Singer record types are serialized for directory services.
Configuration Constants
The project utilizes a set of default configuration constants to manage file naming, output locations, and LDIF formatting. These are primarily defined and enforced through the settings module and target initialization.
Default Target Settings
The FlextTargetLdif class and its associated settings define the default operational environment for the target.
| Constant Key | Default Value | Description |
|---|---|---|
file_naming_pattern | {stream_name}_{timestamp}.ldif | Template for generating output filenames. |
dn_template | uid={uid},ou=users,dc=example,dc=com | Default structure for Distinguished Names. |
output_path | ./output | Default directory for LDIF file generation. |
line_length | 78 | Standard maximum line length before folding. |
encoding | utf-8 | Character encoding for output files. |
Sources: src/flext_target_ldif/target.py:35-39, src/flext_target_ldif/settings.py:38-100, src/flext_target_ldif/models.py:76-90
LDIF Format Options
Formatting constants are encapsulated within LdifFormatOptions to ensure RFC compliance during the writing process.
The diagram above shows the default format options used by the LDIF writer to ensure structural integrity of the output.
Sources: src/flext_target_ldif/models.py:53-93
Attribute Mappings & Transformations
The system provides robust mechanisms for mapping Singer record fields to LDAP attributes and transforming data types to meet LDAP requirements.
Record Transformation Logic
The RecordTransformer utility provides built-in mappings for common attributes and type conversions.
- Boolean Transformation: Converts Python booleans to LDAP strings
TRUEorFALSE. - Timestamp Transformation: Normalizes ISO timestamps to LDAP-compatible strings.
- Name Normalization: Capitalizes name components (e.g.,
cn,givenname). - Required Attributes: Automatically adds default object classes like
inetOrgPersonandpersonif missing.
Sources: src/flext_target_ldif/utilities.py:195-280
Mapping Flow
The flow below illustrates how a Singer record is processed through the attribute mapping and transformation layer before being written to the LDIF file.
Validation Rules & Constraints
System constants also define validation boundaries for configuration and data entries.
Domain Rules
Configuration must satisfy specific constraints before execution:
- Output Path: Must be non-empty and is automatically created if it does not exist.
- DN Template: Must contain
{key}placeholders and represent a valid LDAP DN structure. - LDIF Entry: Must contain at least one
objectClassand oneattribute.
Sources: src/flext_target_ldif/settings.py:102-114, src/flext_target_ldif/models.py:133-157
Encoding Constraints
The system detects characters that require Base64 encoding based on LDAP standards.
- Values starting with a space (
) or colon (:). - Non-ASCII characters.
- Control characters including newlines (
\n) or carriage returns (\r).
Sources: src/flext_target_ldif/writer.py:149-158, src/flext_target_ldif/utilities.py:126-140
Summary
System Constants & Mappings in flext-target-ldif establish the bridge between flexible Singer records and the rigid LDIF specification. Through standardized default settings, typed format options, and a comprehensive suite of attribute transformers, the system ensures that data extracted from any source can be correctly projected into an LDAP directory structure while maintaining compliance with RFC 2849 and directory service best practices.