LDAP Entry Model
Relevant source files
The following files were used as context for generating this wiki page:
The LDAP Entry Model is a core component of the flext-tap-ldif project, designed to represent, validate, and process directory entries extracted from LDIF (LDAP Data Interchange Format) files. It serves as the primary data structure for converting raw LDIF text into structured Singer-compatible records for data integration pipelines.
This model facilitates the parsing of complex LDAP attributes, handling of Distinguished Names (DNs), and management of object classes. It integrates closely with the flext-ldif parsing infrastructure to ensure technical accuracy and format compliance during the extraction process.
Sources: src/flext_tap_ldif/_models/entry.py:1-12, src/flext_tap_ldif/tap.py:15-20
Architecture and Components
The entry model is implemented using Pydantic-based enforced models, providing strict type checking and validation for all LDAP data points. The architecture separates the logical representation of an entry from the utilities used to process and convert it into external formats.
Core Data Structure: LdifEntry
The LdifEntry class represents a single directory object. It includes the mandatory Distinguished Name (DN), a mapping of attributes, and metadata regarding its source location and processing status.
The diagram above shows the structure of the LdifEntry model and its primary fields.
Sources: src/flext_tap_ldif/_models/entry.py:15-110
Data Model Fields
| Field | Type | Description |
|---|---|---|
dn | str | The Distinguished Name of the LDAP entry. |
attributes | Mapping[str, Sequence[str]] | Key-value pairs representing LDAP attributes and their values. |
object_classes | Sequence[str] | List of object classes associated with the entry. |
line_number | int | The source line number in the LDIF file where the entry begins. |
source_file | str | None | Path to the source LDIF file. |
entry_type | str | Defaults to "entry", used to distinguish from change records. |
extracted_at | datetime | Timestamp of when the record was extracted. |
validation_errors | Sequence[str] | List of errors encountered during entry validation. |
Sources: src/flext_tap_ldif/_models/entry.py:35-68
Data Flow and Processing
The transformation of raw LDIF lines into a validated LdifEntry involves multiple stages of parsing, normalization, and validation.
This flowchart illustrates the sequence of processing raw data into a structured model.
Sources: src/flext_tap_ldif/_utilities/data_processing.py:20-60, src/flext_tap_ldif/_utilities/processor.py:90-110
Attribute Normalization
LDIF attributes are normalized to ensure compatibility with downstream JSON schemas. This process includes converting names to lowercase and replacing non-alphanumeric characters with underscores. If an attribute name begins with a digit, it is prefixed with attr_.
Sources: src/flext_tap_ldif/_utilities/data_processing.py:82-92
Attribute Resolution
The model provides helper methods to interact with attributes in a case-insensitive manner:
resolve_attribute_values(name): Returns all values for a given attribute name regardless of case.resolve_first_attribute_value(name): Returns the first value found for the specified attribute.
Sources: src/flext_tap_ldif/_models/entry.py:92-105
Validation Logic
The LdifEntry model employs an after validator to enforce structural integrity:
- DN Verification: Ensures the Distinguished Name is not empty.
- Object Class Synchronization: If
object_classesare provided but theobjectClassattribute is missing from the main attributes mapping, the validator automatically populates theobjectClassattribute to maintain consistency.
Sources: src/flext_tap_ldif/_models/entry.py:107-118
Validation Metrics
The project tracks the success of these operations via the LdifValidationResult model, which monitors the ratio of valid to invalid entries processed from a source file.
| Metric | Description |
|---|---|
total_entries | Total count of entries found in the LDIF source. |
valid_entries | Number of entries that passed Pydantic validation. |
invalid_entries | Number of entries containing validation errors. |
Sources: src/flext_tap_ldif/_models/record.py:15-50
Summary of Integration
The LDAP Entry Model acts as the intermediary between the raw file parsing handled by FlextTapLdifUtilitiesProcessor and the Singer output generated by FlextTapLdif. By enforcing a strict schema through LdifEntry, the system ensures that LDAP data is cleanly mapped to JSON-compatible structures while preserving critical metadata like line numbers and source file paths.
Sources: src/flext_tap_ldif/tap.py:65-80, src/flext_tap_ldif/_utilities/processor.py:95-120