patroni.postgresql.validator module

class patroni.postgresql.validator.Bool(version_from: int, version_till: Optional[int] = None)

Bases: _Transformable

transform(name: str, value: Any) Optional[Any]

Verify that provided value is valid.

Parameters:
  • name – GUC’s name

  • value – GUC’s value

Returns:

the value (sometimes clamped) or None if the value isn’t valid

class patroni.postgresql.validator.Enum(*, version_from: int, version_till: Optional[int] = None, possible_values: Tuple[str, ...])

Bases: _Transformable

property possible_values: Tuple[str, ...]
transform(name: str, value: Optional[Any]) Optional[Any]

Verify that provided value is valid.

Parameters:
  • name – GUC’s name

  • value – GUC’s value

Returns:

the value (sometimes clamped) or None if the value isn’t valid

class patroni.postgresql.validator.EnumBool(*, version_from: int, version_till: Optional[int] = None, possible_values: Tuple[str, ...])

Bases: Enum

transform(name: str, value: Optional[Any]) Optional[Any]

Verify that provided value is valid.

Parameters:
  • name – GUC’s name

  • value – GUC’s value

Returns:

the value (sometimes clamped) or None if the value isn’t valid

class patroni.postgresql.validator.Integer(*, version_from: int, version_till: Optional[int] = None, min_val: Union[int, float], max_val: Union[int, float], unit: Optional[str] = None)

Bases: Number

static parse(value: Any, unit: Optional[str]) Optional[int]

Convert provided value to unit.

exception patroni.postgresql.validator.InvalidGucValidatorsFile(value: Any)

Bases: PatroniException

Raised when reading or parsing of a YAML file faces an issue.

class patroni.postgresql.validator.Number(*, version_from: int, version_till: Optional[int] = None, min_val: Union[int, float], max_val: Union[int, float], unit: Optional[str] = None)

Bases: _Transformable

property max_val: Union[int, float]
property min_val: Union[int, float]
abstract static parse(value: Any, unit: Optional[str]) Optional[Any]

Convert provided value to unit.

transform(name: str, value: Any) Optional[Union[int, float]]

Verify that provided value is valid.

Parameters:
  • name – GUC’s name

  • value – GUC’s value

Returns:

the value (sometimes clamped) or None if the value isn’t valid

property unit: Optional[str]
class patroni.postgresql.validator.Real(*, version_from: int, version_till: Optional[int] = None, min_val: Union[int, float], max_val: Union[int, float], unit: Optional[str] = None)

Bases: Number

static parse(value: Any, unit: Optional[str]) Optional[float]

Convert provided value to unit.

class patroni.postgresql.validator.String(version_from: int, version_till: Optional[int] = None)

Bases: _Transformable

transform(name: str, value: Optional[Any]) Optional[Any]

Verify that provided value is valid.

Parameters:
  • name – GUC’s name

  • value – GUC’s value

Returns:

the value (sometimes clamped) or None if the value isn’t valid

class patroni.postgresql.validator.ValidatorFactory(validator: Dict[str, Any])

Bases: object

Factory class used to build Patroni validator objects based on the given specs.

TYPES: Dict[str, Type[_Transformable]] = {'Bool': <class 'patroni.postgresql.validator.Bool'>, 'Enum': <class 'patroni.postgresql.validator.Enum'>, 'EnumBool': <class 'patroni.postgresql.validator.EnumBool'>, 'Integer': <class 'patroni.postgresql.validator.Integer'>, 'Number': <class 'patroni.postgresql.validator.Number'>, 'Real': <class 'patroni.postgresql.validator.Real'>, 'String': <class 'patroni.postgresql.validator.String'>}
exception patroni.postgresql.validator.ValidatorFactoryInvalidSpec(value: Any)

Bases: PatroniException

Raised when a validator spec contains an invalid set of attributes.

exception patroni.postgresql.validator.ValidatorFactoryInvalidType(value: Any)

Bases: PatroniException

Raised when a validator spec contains an invalid type.

exception patroni.postgresql.validator.ValidatorFactoryNoType(value: Any)

Bases: PatroniException

Raised when a validator spec misses a type.

patroni.postgresql.validator.transform_postgresql_parameter_value(version: int, name: str, value: Any, available_gucs: CaseInsensitiveSet) Optional[Any]

Validate value of GUC name for Postgres version using parameters and available_gucs.

Parameters:
  • version – Postgres version to validate the GUC against.

  • name – name of the Postgres GUC.

  • value – value of the Postgres GUC.

  • available_gucs

    a set of all GUCs available in Postgres version. Each item is the name of a Postgres GUC. Used for a couple purposes:

    • Disallow writing GUCs to postgresql.conf that does not exist in Postgres version;

    • Avoid ignoring GUC name if it does not have a validator in parameters, but is a valid GUC in

      Postgres version.

Returns:

The return value may be one among:

  • The original value if name seems to be an extension GUC (contains a period ‘.’); or

  • None if name is a recovery GUC; or

  • value transformed to the expected format for GUC name in Postgres version using validators defined in

    parameters. Can also return None. See _transform_parameter_value().

patroni.postgresql.validator.transform_recovery_parameter_value(version: int, name: str, value: Any, available_gucs: CaseInsensitiveSet) Optional[Any]

Validate value of GUC name for Postgres version using recovery_parameters and available_gucs.

Parameters:
  • version – Postgres version to validate the recovery GUC against.

  • name – name of the Postgres recovery GUC.

  • value – value of the Postgres recovery GUC.

  • available_gucs

    a set of all GUCs available in Postgres version. Each item is the name of a Postgres GUC. Used for a couple purposes:

    • Disallow writing GUCs to recovery.conf (or postgresql.conf depending on version), that does not

      exist in Postgres version;

    • Avoid ignoring recovery GUC name if it does not have a validator in recovery_parameters, but is a

      valid GUC in Postgres version.

Returns:

value transformed to the expected format for recovery GUC name in Postgres version using validators defined in recovery_parameters. It can also return None. See _transform_parameter_value().