Common Utilities
Relevant source files
The following files were used as context for generating this wiki page:
The Common Utilities module within flext-target-ldap provides a unified suite of domain-specific tools for mapping Singer protocol data to LDAP directory operations. It follows the FLEXT unified class pattern, integrating functionality from flext_ldap and flext_meltano to handle schema generation, type coercion, and configuration validation.
This module serves as the foundational bridge between the incoming Singer stream data (Users, Groups, Organizational Units) and the technical requirements of an LDAP backend, such as Distinguished Name (DN) construction and object class assignment.
Sources: src/flext_target_ldap/utilities.py:15-22, src/flext_target_ldap/api.py:12-28
Domain Utilities (TargetLdap)
The core utility logic is encapsulated within the TargetLdap nested namespace of the FlextTargetLdapUtilities class. This structure separates Singer-specific protocol utilities from general LDAP directory operations.
Singer Catalog Generation
The utilities include a canonical builder for the Singer catalog, defining the expected schemas for standard LDAP streams.
| Stream ID | Required Fields | Key Properties |
|---|---|---|
users | username | email, first_name, last_name, phone, department, title |
groups | name | description, members (array) |
organizational_units | name | description |
Sources: src/flext_target_ldap/utilities.py:32-75
Type Conversion and Extraction
The TypeConversion helper provides static methods to coerce Singer settings into typed Python structures required by the LDAP client.
- Attribute Mapping: Extracts and normalizes mappings between Singer record fields and LDAP attributes from the target configuration.
- Object Class Extraction: Resolves object class sequences from either record-level metadata or global target settings, falling back to a default
topclass if none are provided.
Sources: src/flext_target_ldap/utilities.py:77-104
System Architecture and Data Flow
The utilities interact with the facade and sink models to facilitate the transformation of raw JSONL records into LDAP-compliant operations.
The diagram illustrates how the Utilities namespace provides the logic for attribute extraction and catalog definition used by the Sinks during record processing.
Sources: src/flext_target_ldap/api.py:76-96, src/flext_target_ldap/_models/sinks.py:102-125
LDAP Connection Management
Utilities are used to standardize the connection configuration passed to the LDAP client. This includes mapping configuration keys to specific LDAP parameters such as host, port, SSL usage, and bind credentials.
connection_config = {
c.TargetLdap.KEY_HOST: self._target.settings.get(c.TargetLdap.KEY_HOST, c.TargetLdap.DEFAULT_HOST),
c.TargetLdap.KEY_PORT: self._target.settings.get(c.TargetLdap.KEY_PORT, c.Ldap.PORT),
c.TargetLdap.KEY_USE_SSL: self._target.settings.get(c.TargetLdap.KEY_USE_SSL, c.Ldap.DEFAULT_USE_SSL),
c.TargetLdap.KEY_BIND_DN: self._target.settings.get(c.TargetLdap.KEY_BIND_DN, c.TargetLdap.DEFAULT_BIND_DN),
c.TargetLdap.KEY_PASSWORD: self._target.settings.get(c.TargetLdap.KEY_PASSWORD, c.TargetLdap.DEFAULT_BIND_PASSWORD),
}
Sources: src/flext_target_ldap/_models/sinks.py:157-175
Test Utilities
The project includes a dedicated TestsFlextTargetLdapUtilities class that extends both the project utilities and the FlextTestsUtilities base. This provides specialized methods for creating mock LDAP configurations and recording delegated sink calls during unit and integration testing.
- Mock Config Builder:
build_mock_ldap_configgenerates standard settings payloads for test environments. - ProcessTarget Stub: A specialized class used to record and verify that delegated sink calls reach the target correctly.
Sources: tests/utilities.py:19-58
Export and Lazy Loading
To optimize performance, the utilities are part of a lazy-loading strategy. The _LAZY_IMPORTS map ensures that utility components, including the FlextTargetLdapClient and FlextTargetLdapServiceRuntime, are only loaded into the namespace when explicitly accessed.
The Common Utilities ensure that the flext-target-ldap project maintains a strict separation of concerns, providing reusable logic for Singer-to-LDAP translation while adhering to the standard FLEXT architectural patterns.