octodns.record.validator
Classes
|
Base class for record-level validators. |
|
Base class for value-level validators. |
- class octodns.record.validator.ValidatorRegistry[source]
Bases:
object- log = <Logger Record (WARNING)>
- class octodns.record.validator.RecordValidator(id, sets=None)[source]
Bases:
objectBase class for record-level validators.
Subclasses override
validateto return a list of reason strings describing any validation failures. An empty list indicates the record is valid.record_clsis the concrete Record subclass being validated and gives validators access to class-level attributes (_type,_value_type, etc.) when needed. Attributes consulted only by a validator should live on the validator instance (self);record_clsis only the right home for state that’s shared across the record and its validators.Every validator instance has a non-empty
id— a short, stable, kebab-case identifier used to reference the validator in the registry (e.g. for config-driven disabling). Built-ins are constructed at import time with their well-known id (e.g.NameValidator('name')). Config-registered validators receive their config key asidautomatically. Underscore-prefixed ids (e.g._values-type) are reserved for framework-internal bridge validators that must always run.- __init__(id, sets=None)[source]
- Parameters:
id – Non-empty identifier for this validator instance. Used to look up the validator in the registry and to reference it in config (for enabling/disabling, etc.).
sets – Iterable of set names this validator belongs to, or
None(the default) to always activate regardless ofmanager.enabled. Pass an explicit set such assets={'legacy'}to opt into set-based filtering.
- validate(record_cls, name, fqdn, data)[source]
Validate a record’s non-value attributes.
- Parameters:
record_cls (type) – The concrete
Recordsubclass being validated. Validators that need access to record class-level attributes (e.g._type,_value_type) should read them fromrecord_cls. Per-instance configuration should live onself, not onrecord_cls.name (str) – The record’s name relative to its zone (
''for the zone root). Alreadyidna_encode’d.fqdn (str) – The record’s fully-qualified domain name (
name+ zone name).data (dict) – The raw record config dict (as loaded from YAML/JSON) including
ttl,type,value/values, and any type-specific fields likedynamic,geo, oroctodns.
- Returns:
A list of human-readable reason strings describing validation failures. Must return an empty list when the record is valid. Reasons from multiple validators are concatenated by the caller, so each reason must stand alone without context from the others.
- Return type:
Notes
Implementations must not raise on invalid input — all failures are reported via the returned list. Reason strings are surfaced verbatim in
ValidationErrormessages, so phrasing and punctuation should be stable across releases.
- class octodns.record.validator.ValueValidator(id, sets=None)[source]
Bases:
objectBase class for value-level validators.
Subclasses override
validateto return a list of reason strings describing any validation failures. An empty list indicates the value is valid.value_clsis the concrete value class being validated. Per-instance configuration should live on the validator instance (self);value_clsis only the right home for state that’s shared across the value class and its validators.Every validator instance has a non-empty
id— a short, stable, kebab-case identifier used to reference the validator in the registry (e.g. for config-driven disabling). Built-ins are constructed at import time with their well-known id (e.g.MxValueValidator('mx-value')). Config-registered validators receive their config key asidautomatically. Underscore-prefixed ids are reserved for framework-internal bridge validators that must always run.- __init__(id, sets=None)[source]
- Parameters:
id – Non-empty identifier for this validator instance. Used to look up the validator in the registry and to reference it in config (for enabling/disabling, etc.).
sets – Iterable of set names this validator belongs to, or
None(the default) to always activate regardless ofmanager.enabled. Pass an explicit set such assets={'legacy'}to opt into set-based filtering.
- validate(value_cls, data, _type)[source]
Validate a record’s rdata values.
- Parameters:
value_cls (type) – The concrete value class being validated (e.g.
MxValue,_Ipv4Value). Validators that need access to value class-level attributes (e.g.VALID_ALGORITHMS,_address_type) should read them fromvalue_cls. Per-instance configuration should live onself, not onvalue_cls.data (list | tuple | str | dict) – The rdata to validate. For multi-value record types this is a list/tuple of value dicts or strings; for single-value types it may be a bare value. Most validators iterate
datadirectly — when a validator needs to accept either form it should normalize withif not isinstance(data, (list, tuple)): data = (data,)._type (str) – The record type string (e.g.
'MX','A'). Passed through to helpers like_check_target_formatwhich format it into their reason strings.
- Returns:
A list of human-readable reason strings describing validation failures. Must return an empty list when the values are valid. Reasons from multiple validators are concatenated by the caller, so each reason must stand alone without context from the others.
- Return type:
Notes
Implementations must not raise on invalid input — all failures are reported via the returned list. Reason strings are surfaced verbatim in
ValidationErrormessages, so phrasing and punctuation should be stable across releases.