Data Models & Typing
Relevant source files
The following files were used as context for generating this wiki page:
The Data Models & Typing system in flext-tap-ldap provides a structured framework for representing LDAP directory entities, connection parameters, and stream configurations. It leverages Pydantic-based models to ensure strict validation of LDAP data during extraction and transformation processes. The system is designed to bridge the gap between raw LDAP/LDIF data and the Singer protocol requirements, utilizing specialized namespaces to organize domain events, configuration objects, and testing entities.
Sources: src/flext_tap_ldap/models.py:17-38, src/flext_tap_ldap/tap.py:21-40
Core LDAP Models
The project defines primary entities for managing LDAP interactions, focusing on connection parameters and the state of directory connections. These models inherit from flext-meltano and flext-ldap base classes to maintain consistency across the FLEXT ecosystem.
LDAP Connection Parameters
The LdapConnectionParams model defines the configuration required to establish a session with an LDAP server. It includes validation for network details, authentication credentials, and operational timeouts.
| Field | Type | Description |
|---|---|---|
host | t.NonEmptyStr | LDAP server hostname |
port | t.PortNumber | LDAP server port |
bind_dn | str | None | Bind Distinguished Name for authentication |
use_ssl | bool | Whether to enable SSL/TLS |
timeout_seconds | t.PositiveInt | Search timeout duration in seconds |
page_size | t.PositiveInt | Results per page for paged searches |
Sources: src/flext_tap_ldap/models.py:59-93
Connection Entity
The LdapConnection entity tracks the lifecycle of an LDAP connection, including unique identification and health monitoring through error logging and timestamping.
The diagram shows the LdapConnection entity which tracks connection state and metadata.
Sources: src/flext_tap_ldap/models.py:95-125
LDIF Data Processing Models
For LDIF (LDAP Data Interchange Format) processing, the tap uses a specialized utility namespace that wraps the flext-ldif library. These models handle the parsing, validation, and transformation of flat LDIF files into structured objects.
Entry Representation
The Entry class acts as a convenience wrapper for LDIF entries, managing Distinguished Names (DNs) and multi-valued attributes.
Data flow from raw LDIF text to a structured Singer-compatible record.
Sources: src/flext_tap_ldap/_utilities/_processor.py:42-132
Transformation Logic
The Transformer class applies rules to modify entry data during the sync process. This includes mapping attribute names, injecting default values, or stripping sensitive fields.
| Transformation Type | Description |
|---|---|
attribute_mappings | Renames source LDAP attributes to target names |
schema_mappings | Maps attributes with support for default values |
remove_attributes | Drops specific attributes from the final output |
add_attributes | Injects static attributes into every entry |
Sources: src/flext_tap_ldap/_utilities/_processor.py:347-458
Tap Configuration & Stream Discovery
The FlextTapLdapTap class defines the config_jsonschema, which serves as the source of truth for the tap's runtime configuration. This schema dictates how the tap discovers available streams like users, groups, and organizational_units.
The relationship between configuration and the dynamic discovery of data streams.
Sources: src/flext_tap_ldap/tap.py:65-123, src/flext_tap_ldap/ldif_streams.py:73-98
Test Models and Mocking
The project maintains a dedicated tests/models.py file to provide extended models for end-to-end and unit testing. These models extend the production entities with additional properties used to verify connection strings and search filter accuracy.
Extended Test Entities
- TestLdapSearch: Models LDAP search operations including scope (BASE, ONELEVEL, SUBTREE) and size/time limits.
- TestLdapStream: Represents a Singer stream in a test environment, including replication methods like
FULL_TABLE. - TestLdapEntry: A test-specific representation of a directory entry used for calculating attribute counts.
Sources: tests/models.py:38-120
Client Normalization Helpers
The ClientSupport utility provides static methods to ensure that data types remain consistent across different LDAP server implementations (e.g., standard LDAP vs. Oracle OID).
@staticmethod
def build_server_uri(host: str, port: int, *, use_ssl: bool) -> str:
"""Build the canonical LDAP or LDAPS server URI."""
protocol = "ldaps" if use_ssl else "ldap"
return f"{protocol}://{host}:{port}"
Sources: src/flext_tap_ldap/_utilities/client_support.py:19-27
Normalization Table
| Helper Method | Purpose | Source File |
|---|---|---|
normalize_scope | Ensures search scopes are valid LDAP constants | client_support.py:29-41 |
to_entry_mapping | Converts Ldif.Entry objects to JSON dictionaries | client_support.py:43-70 |
normalize_oracle_entry | Handles Oracle-specific attributes like orclPassword | client_support.py:94-128 |
Conclusion
The data modeling and typing architecture of flext-tap-ldap ensures that LDAP data is handled with high fidelity from the initial server connection through to the final Singer record output. By utilizing Pydantic models for validation and specialized utility classes for LDIF processing and Oracle-specific normalization, the project provides a robust foundation for enterprise-grade LDAP data extraction.