Domain Models
Relevant source files
The following files were used as context for generating this wiki page:
Domain Models in the flext-ldap project represent the core data structures and business logic entities used for enterprise LDAP operations. These models are built upon the FLEXT framework's standard model patterns, utilizing Pydantic for validation and structural integrity. They facilitate clean architecture by separating directory-specific details from high-level service logic, supporting operations ranging from basic searches to complex batch synchronizations.
The architecture follows a facade pattern where FlextLdapModels acts as the primary entry point, inheriting from flext-ldif models (m) and incorporating LDAP-specific namespaces. This hierarchy ensures that standard directory interchange format (LDIF) entities and general FLEXT entities are seamlessly integrated with LDAP-specific configurations and result sets.
Sources: src/flext_ldap/models.py:7-27, src/flext_ldap/_models/ldap.py:12-16
Model Hierarchy and Architecture
The domain models are organized into a strict hierarchy to support modularity and reuse across the FLEXT ecosystem. The FlextLdapModels class serves as a facade that composes LDAP-specific models through Method Resolution Order (MRO).
Inheritance Structure
The diagram shows how flext-ldap extends the core and LDIF model foundations to provide specialized LDAP capabilities.
Sources: src/flext_ldap/models.py:12-32
Connection and Search Models
These models define how the application interacts with LDAP servers, covering connectivity parameters and query specifications.
Connection Configuration
The ConnectionConfig model manages the parameters required to establish and maintain a connection to an LDAP server. It includes built-in validation to ensure that security protocols like SSL and StartTLS are not enabled simultaneously.
| Field | Type | Default | Description |
|---|---|---|---|
host | str | localhost | LDAP server hostname |
port | PortNumber | 389 | LDAP server port |
use_ssl | bool | False | Enable SSL (LDAPS) |
use_tls | bool | False | Enable StartTLS |
timeout | PositiveInt | c.Ldap.TIMEOUT | Connection timeout in seconds |
auto_bind | bool | True | Auto-bind on connection |
| Sources: src/flext_ldap/_models/ldap.py:19-54 |
Search Specifications
Search operations are governed by SearchOptions, which provides a structured way to define base DNs, filters, and scopes.
SearchOptions can be instantiated directly or via factory methods like base_scope, which automatically configures the search to retrieve all user attributes for a single entry.
Sources: src/flext_ldap/_models/ldap.py:65-115, tests/unit/test_models_search.py:84-90
Result and Operation Models
Operations in flext-ldap return immutable result objects that provide status information and data payloads.
Search Results
The SearchResult model encapsulates the entries returned from a directory query. It includes computed properties to group entries by their LDAP objectClass.
| Component | Description |
|---|---|
entries | A sequence of m.Ldif.Entry objects containing the data. |
search_options | A reference to the original SearchOptions used for the query. |
total_count | A computed property returning the number of entries found. |
by_objectclass | A grouping of entries organized by their primary object class. |
| Sources: src/flext_ldap/_models/ldap.py:186-258 |
Operation Results
For write operations (Add, Modify, Delete), the OperationResult model provides a standardized response format.
OperationResult is immutable (frozen) once created, ensuring the integrity of the operation status throughout the application flow.
Sources: src/flext_ldap/_models/ldap.py:171-184, tests/unit/test_models_search.py:109-122
Synchronization and Batch Models
Advanced models support data synchronization and batch processing, tracking progress and detailed metadata for entry conversions.
Batch Stats and Upserts
The system uses specialized models to track the outcome of multiple operations.
- LdapBatchStats: Provides base counters for
synced,failed, andskippedentries. - BatchUpsertResult: Aggregates per-entry
UpsertResultobjects and computes an overallsuccess_rate.
Sources: src/flext_ldap/_models/ldap.py:129-159, tests/unit/test_models_sync.py:34-40
Conversion Metadata
During synchronization, changes to entries (such as DN transformations or attribute removals) are tracked using the ConversionMetadata model.
class ConversionMetadata(m.BaseModel):
source_attributes: t.StrSequence = u.Field(default_factory=list)
source_dn: str = ""
removed_attributes: t.StrSequence = u.Field(default_factory=list)
dn_changed: bool = False
converted_dn: str = ""
Sources: src/flext_ldap/_models/ldap.py:270-282, tests/unit/test_models_sync.py:53-66
Protocol Definitions
The domain models are complemented by structural protocols defined in FlextLdapProtocols. These protocols allow services to interact with models and adapters using structural typing, ensuring that high-level logic does not depend on specific implementation details or directory libraries like ldap3.
Key protocols include:
- LdapClient: Defines the interface for CRUD and batch operations.
- SearchOptions: A structural contract for search parameters.
- Ldap3Connection: A contract for the underlying library connection objects.
Sources: src/flext_ldap/protocols.py:39-255
Conclusion
Domain Models in flext-ldap provide a robust, validated, and type-safe foundation for LDAP operations. By combining Pydantic-powered data structures with flexible structural protocols, the project achieves a clean separation between directory infrastructure and enterprise business logic. Whether managing connection parameters or tracking complex batch synchronization results, these models ensure consistency and reliability across the entire library.