Settings Model & Validation
Relevant source files
The following files were used as context for generating this wiki page:
The Settings Model & Validation system in flext-tap-ldif provides a robust, Pydantic-driven framework for managing runtime configuration and data integrity during LDIF file extraction. It ensures that environment variables and configuration files adhere to the expected schema before the Singer tap begins processing. The system relies on flext-core for its base settings logic and pydantic for strict type enforcement and validation.
This module encompasses not only the primary tap settings but also the internal data models used to represent LDIF entries, file metadata, and stream configurations. By centralizing validation in these models, the tap ensures that invalid data is caught early in the pipeline, maintaining high quality gates as defined in the project governance.
Sources: src/flext_tap_ldif/settings.py:15-18, src/flext_tap_ldif/models.py:20-25, README.md:38-40
Core Runtime Settings
The primary configuration interface is the FlextTapLdifSettings class. This class inherits from FlextSettingsBase and is responsible for loading settings with the FLEXT_TAP_LDIF_ environment variable prefix. It handles file paths, parsing behavior, and resource limits.
Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
file_path | str | None | None | Specific path to an LDIF file. |
directory_path | str | None | None | Directory to scan for LDIF files. |
file_pattern | str | *.ldif | Glob pattern for file discovery. |
encoding | str | utf-8 | Encoding used to read LDIF files. |
strict_parsing | bool | True | Whether to fail on parsing errors. |
max_file_size_mb | int | 1024 | Maximum allowed file size (min: 1). |
Sources: src/flext_tap_ldif/settings.py:18-47
Path Normalization Logic
The settings model includes utility methods to convert raw string inputs into structured pathlib.Path objects, facilitating safer file operations.
def normalized_file_path(self) -> Path | None:
"""Return `file_path` as `Path` when configured."""
if self.file_path is None:
return None
return Path(self.file_path)
Sources: src/flext_tap_ldif/settings.py:49-53
Domain Model Architecture
The project uses a Multi-Resource Object (MRO) mixin pattern to compose its domain models. The FlextTapLdifModels class acts as a facade, aggregating models for entries, files, batches, and records.
Model Composition
The following diagram illustrates how the TapLdif domain namespace is assembled from various internal model mixins.
Sources: src/flext_tap_ldif/models.py:20-33
Data Validation Models
Validation is enforced through Pydantic EnforcedModel instances. These models utilize model_validator decorators to ensure consistency between different fields.
LDIF File Metadata Validation
The LdifFile model tracks the state and validity of a specific file. It ensures that file sizes are non-negative and paths are present.
Entry Structure Validation
LdifEntry models represent individual records within the LDIF. They enforce that a Distinguished Name (DN) is always present and automatically synchronize objectClass attributes with the specific object_classes field.
- DN Constraint: The
dnfield cannot be empty. - Attribute Sync: If
object_classesare provided, they are automatically injected into theattributesmapping under the keyobjectClassif not already present.
Sources: src/flext_tap_ldif/_models/entry.py:22-108
Singer Stream Configuration
The LdifStream model defines how LDIF data is mapped to Singer streams. It includes configuration for replication methods and filtering.
| Field | Description | Constraints |
|---|---|---|
stream_name | The name of the Singer stream. | Required |
tap_stream_id | Unique ID for the tap stream. | Required |
replication_method | Strategy for data extraction. | Defaults to FULL_TABLE |
batch_size | Number of records per batch. | From constants |
filter_object_classes | List of classes to include. | Optional sequence |
Sources: src/flext_tap_ldif/_models/file_stream.py:15-88
Validation Reporting
Validation results are captured in the LdifValidationResult model, which provides a summary of processing success and identifies critical errors.
Summary Logic
Models provide computed properties to generate JSON-compatible summaries for CLI output or logging. For example, LdifValidationResult calculates a success_rate and checks for "critical" severity in error lists.
Sources: src/flext_tap_ldif/_models/record.py:53-83