Settings & Environment
Relevant source files
The following files were used as context for generating this wiki page:
The Settings & Environment module in flext-target-ldap provides a declarative, strictly-typed configuration layer built on flext-core patterns. It is responsible for ingestion, normalization, and validation of LDAP target parameters derived from environment variables or JSON configuration files.
The system ensures that flat configuration structures typical of the Singer protocol are normalized into a canonical nested architecture suitable for the enterprise LDAP client. It leverages Pydantic for schema enforcement and provides a unified interface for connection parameters, operation modes (create, update, delete), and directory-specific attributes like Base DNs and object classes.
Sources: src/flext_target_ldap/settings.py, src/flext_target_ldap/_utilities/settings.py, src/flext_target_ldap/api.py
Configuration Architecture
The configuration logic is centered around the FlextTargetLdapSettings class, which inherits from FlextSettingsBase. This architecture separates raw input ingestion from the structured internal representation used by the LDAP client.
Settings Normalization
A critical component of the architecture is the normalize_flat_settings validator. Since many Singer integrations provide a flat list of settings (e.g., host, port, bind_dn at the top level), this logic detects flat structures and encapsulates them into a nested connection object defined by m.Ldap.ConnectionConfig.
Environment Variables
Configuration can be driven by environment variables using a specific prefix defined in the constants.
| Variable Prefix | Purpose | Source File |
|---|---|---|
FLEXT_TARGET_LDAP_ | Standard prefix for all target settings | src/flext_target_ldap/_constants/base.py:19 |
Core Configuration Options
The following table summarizes the primary configuration fields available in FlextTargetLdapSettings.
| Field | Type | Default | Description |
|---|---|---|---|
connection | ConnectionConfig | N/A | Nested LDAP server connection details |
base_dn | NonEmptyStr | N/A | Base Distinguished Name for operations |
search_filter | str | (objectClass=*) | Filter used for directory searches |
search_scope | Ldap3SearchScope | SUBTREE | LDAP search depth (BASE, ONELEVEL, SUBTREE) |
batch_size | BatchSize | 1000 | Max entries per batch operation |
create_missing_entries | bool | True | Whether to add new entries to LDAP |
update_existing_entries | bool | True | Whether to update entries on DN conflict |
delete_removed_entries | bool | False | Whether to delete entries missing from source |
object_classes | StrSequence | ("top",) | Default classes for new entries |
Sources: src/flext_target_ldap/settings.py:102-171, src/flext_target_ldap/_constants/base.py:22-25
LDAP Connection Model
Connection settings are resolved into a ConnectionConfig model. The FlextTargetLdapClient uses this model to establish sessions with the directory server.
Validation Logic
Validation occurs at multiple stages to ensure the integrity of the target configuration.
Programmatic Validation
The utility module provides standalone functions to validate raw dictionaries against the canonical settings model, returning a Result type to handle failures gracefully.
def validate_ldap_target_config(
settings: t.JsonMapping,
) -> p.Result[FlextTargetLdapSettings]:
"""Validate raw target settings with the canonical settings model."""
return u.try_(
lambda: FlextTargetLdapSettings.model_validate(settings),
catch=(ValueError, TypeError, RuntimeError),
op_name="Configuration validation",
)
Sources: src/flext_target_ldap/_utilities/settings.py:23-32
CLI Validation
During CLI execution, the FlextTargetLdap facade validates configuration immediately after loading from a file path.
Testing Environment
The test suite uses an extended settings class TestsFlextTargetLdapSettings which injects a Tests namespace and provides safe defaults for unit and integration testing.
- Default Test Host:
localhost - Default Test Port:
389 - Default Test Base DN:
dc=example,dc=com
Sources: tests/settings.py:15-39
Summary
The Settings & Environment system in flext-target-ldap provides a robust foundation for LDAP data integration. By enforcing a nested ConnectionConfig via normalization and utilizing strict Pydantic validation, the system ensures that the target behaves predictably across different LDAP server implementations and Singer stream configurations.