Domain Models
Relevant source files
The following files were used as context for generating this wiki page:
Domain Models in the FLEXT-LDIF library form the core business logic layer, structured according to Clean Architecture and Domain-Driven Design (DDD) principles. These models represent LDAP entities, value objects, and schema definitions, ensuring type safety and RFC compliance across the enterprise LDIF processing pipeline.
The models are organized into a flat façade via FlextLdifModels for cross-project access, utilizing MRO (Method Resolution Order) inheritance to aggregate internal definitions. The primary scope includes handling standard LDIF content, change records, server-specific metadata preservation, and schema validation.
Sources: src/flext_ldif/models.py:1-25, src/README.md:30-45
Core Architecture and Hierarchy
The domain layer is structured into specialized namespaces that inherit from flext-core base models (e.g., FrozenModel, DynamicModel, Entity). This ensures that domain objects are either immutable value objects or entities with clear identity and validation rules.
The façade structure allows for unified access to diverse models like entries, results, and collections while maintaining logical separation in the source code.
Sources: src/flext_ldif/models.py:27-44, src/flext_ldif/_models/domain_entry.py:1-15
LDIF Entry Models
The Entry model is the central entity in the system. It represents a single LDIF record, which can either be a standard content record or a change record (changetype: add, delete, modify, etc.).
Entry Data Structure
An entry is composed of a Distinguished Name (DN), a set of attributes, and extensive metadata. It utilizes Pydantic validators to ensure RFC 2849 compliance during instantiation.
| Field | Type | Description |
|---|---|---|
dn | DN | None | The Distinguished Name (Required per RFC 2849 §2). |
attributes | Attributes | None | Container for attribute-value pairs. |
record_kind | RecordKind | Discriminator for CONTENT vs CHANGE records. |
metadata | ServerMetadata | Container for server-specific data and audit trails. |
changetype | LdifChangeType | Operation type for change records (add, delete, etc.). |
Sources: src/flext_ldif/_models/domain_entry.py:236-320
RFC Validation Flow
The Entry model performs automatic validation during initialization, capturing RFC violations without necessarily rejecting the entry, which allows for "loss-aware" round-trip processing.
Server Metadata and Preservation
The ServerMetadata model (within FlextLdifModelsDomainMetadata) provides a universal container for preserving server-specific data that is not part of the standard LDIF specification. This is critical for migrations between different LDAP implementations (e.g., OID to OUD).
Key Metadata Components
- ValidationMetadata: Tracks RFC violations, errors, and warnings detected during the lifecycle.
- WriteOptions: Configuration for output generation, such as base64 encoding binary attributes or sorting entries.
- OriginalFormatDetails: Stores details like original DN line formatting and spacing to ensure perfect round-trips.
- ConversionHistory: An audit trail mapping every transformation step, timestamped and categorized by operation.
Sources: src/flext_ldif/_models/domain_metadata.py:34-190
Schema Models
Schema models represent LDAP attribute types and object classes according to RFC 4512 and RFC 4517. These are used to validate entries and to perform schema-driven migrations.
Schema Feature Summary
| Component | Source Model | Key Responsibility |
|---|---|---|
| SchemaAttribute | FlextLdifModelsDomainSchema.SchemaAttribute | RFC 4512 attribute types (SUP, EQUALITY, SYNTAX). |
| Syntax | FlextLdifModelsDomainSchema.Syntax | RFC 4517 attribute syntaxes and regex validation. |
| SchemaObjectClass | FlextLdifModelsDomainSchema.SchemaObjectClass | Kind (STRUCTURAL, ABSTRACT) and attribute requirements. |
Sources: src/flext_ldif/_models/domain_schema.py:155-220
Processing Results and Statistics
The library generates detailed results and statistics for both individual entries and batch operations.
Entry Statistics
The EntryStatistics model tracks the lifecycle of an individual entry during processing. It records:
- Whether the entry was parsed, validated, filtered, or written.
- Specific attributes added, removed, or modified.
- Confidence scores for category assignment (e.g., users, groups).
Sources: src/flext_ldif/_models/domain_entry.py:33-100
Aggregated Results
Batch operations return a Statistics object containing high-level metrics across a set of processed entries.
# Aggregated metrics for batch operations
class Statistics(m.FrozenModel):
total_entries: int
processed_entries: int
failed_entries: int
schema_entries: int
user_entries: int
success_rate: float
processing_duration: float
Sources: src/flext_ldif/_models/results.py:69-125
Collection Models
The FlextLdifModelsCollections namespace provides specialized containers for grouped LDIF data.
- DynamicCounts: A dynamic model used for tracking frequencies (e.g., objectClass distribution or rejection reasons).
- SchemaContent: A frozen model that aggregates
SchemaAttributeandSchemaObjectClassdefinitions extracted from an LDIF stream. - FlexibleCategories: A dynamic mapping of category names (e.g., "users", "hierarchy") to sequences of
Entryobjects.
Sources: src/flext_ldif/_models/collections.py:22-115
Summary
The Domain Models in FLEXT-LDIF serve as a robust, type-safe foundation for LDAP data manipulation. By separating core entities like Entry and SchemaAttribute from infrastructure metadata, the architecture enables complex migrations and strict RFC validation while ensuring data integrity and round-trip fidelity.
Sources: src/README.md:20-40, src/flext_ldif/models.py:10-25