Library Constants
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The flext-ldap library utilizes a centralized, hierarchical constant system to ensure consistency across core logic, models, and testing suites. These constants define the operational boundaries of the LDAP client, including network defaults, protocol-level attribute names, search scopes, and server detection markers. By consolidating these values, the library provides a single source of truth for enterprise LDAP operations.
The constants are primarily organized within the FlextLdapConstants class (aliased as c), which extends the base constants from flext-ldif and flext-core. This structure allows for domain-specific LDAP values to coexist with universal framework settings, facilitating clear namespace separation for components like Search Operations and Server Detection.
Sources: src/flext_ldap/constants.py:17-38, examples/README.md:27-35
Core Operational Constants
Operational constants define the default behavior of the LDAP connection and the lifecycle of directory operations. This includes default ports (389), retry logic (5 retries with 1.0s delay), and batch processing sizes (100).
Connection Defaults
| Constant | Type | Default Value | Description |
|---|---|---|---|
PORT | int | 389 | Default LDAP non-SSL port. |
TIMEOUT | int | 30 | Default timeout from flext-core. |
AUTO_BIND | bool | True | Automatic bind during connection. |
DEFAULT_MAX_RETRIES | int | 5 | Retries for transient failures. |
BATCH_SIZE | int | 100 | Default entries per batch operation. |
Sources: src/flext_ldap/constants.py:44-59
Operation Metadata
The library tracks distinct operation types and statuses through string-based enumerations to facilitate reporting and state management.
The status flow reflects the lifecycle of an LDAP request handled by the OperationExecutor.
Sources: src/flext_ldap/constants.py:61-75, src/flext_ldap/constants.py:107-113
Search and Operational Constants
Search constants provide the parameters necessary for querying directory information, specifically mapping high-level scopes to protocol-specific integer values required by the underlying ldap3 library.
Search Scopes Mapping
The library supports BASE, ONELEVEL, and SUBTREE scopes, defaulting to SUBTREE for broad discovery.
| SearchScope | ldap3 Integer Value | Description |
|---|---|---|
BASE | 0 | Query only the specific DN. |
ONELEVEL | 1 | Query immediate children of the base DN. |
SUBTREE | 2 | Query the base DN and all subordinates. |
Sources: src/flext_ldap/constants.py:146-169
Protocol Attributes
Constants define essential protocol attributes used during entry manipulation and parsing.
ALL_ATTRIBUTES:*OBJECT_CLASS:objectClassDN:dnCOMMON_NAME:cn
Sources: src/flext_ldap/constants.py:98-105
Server Type Detection Constants
To support universal operations across different LDAP implementations (e.g., OpenLDAP, Active Directory, Oracle Unified Directory), the library uses RootDSE detection markers. The ROOT_DSE_DETECTION_ORDER defines the sequence in which server vendors are evaluated.
This diagram illustrates the hierarchical detection logic driven by RootDSE constants.
Sources: src/flext_ldap/constants.py:183-197
Detection Markers
Markers are grouped by server type and analyzed against RootDSE attributes: vendorName, vendorVersion, namingContexts, and supportedExtension.
| Server Type | Extension Marker | Context Marker |
|---|---|---|
OPENLDAP | openldap | - |
OID | oracle, oid | oracle |
AD | microsoft, windows | microsoft, windows |
DS389 | 389, dirsrv | - |
Sources: src/flext_ldap/constants.py:199-216
Test and Mocking Constants
The TestsFlextLdapConstants class in the testing suite provides a flat namespace for data-driven testing. It includes mock DNs, specific error patterns for transient vs. infrastructure failures, and specific scenarios for server detection overrides.
Error Pattern Categories
| Category | Example Patterns |
|---|---|
TRANSIENT | connection refused, timeout, ldap bind failed |
INFRASTRUCTURE | broken pipe, session terminated by server, ldapserverdownerror |
Sources: tests/constants.py:126-146
Test Scenarios for MRO Dispatch
The library uses DETECTION_FROM_ATTRIBUTES_SCENARIOS to validate the MRO (Method Resolution Order) dispatch of server detection logic. This ensures that vendor strings like "Oracle Corporation" correctly map to the internal oid type.
Sources: tests/constants.py:182-198, tests/unit/test_utilities.py:382-392
Conclusion
Library Constants in flext-ldap serve as the foundation for its enterprise-grade operational stability. By defining strict mappings for search scopes, centralizing server implementation markers, and providing a robust set of test constants, the library ensures that LDAP interactions remain predictable and server-agnostic across different directory environments.