linotp.lib.config.parsing module

This module provides an interface to parse linotp config key-value pairs into a structured ConfigTree

exception linotp.lib.config.parsing.ConfigNotRecognized(key, message=None)

Bases: Exception

This exception should be raised by config parser functions, when the parser isn’t responsible for the supplied type of config entry.

Parameters
  • key – The config key that was supplied to the parser

  • message – Custom message (optional, generic message on default)

class linotp.lib.config.parsing.ConfigTree

Bases: dict

A dictionary-like object, that processes config key-value pairs with a series of parsers.

Usage:

>>> tree = ConfigTree
>>> tree.add_parser('resolvers', parse_resolver)
>>> for key, value in config_dict.items():
>>>     tree.consume_entry(key, value)
classmethod add_parser(target, func)

Adds a parser function for the config tree.

Parameters
  • target – A string identifier for the first set of child nodes of this tree (e.g. ‘resolvers’, ‘realms’, etc) Multiple parsers for the same string identifier can exist.

  • func – A parser function that asks for the composite key of the config entry and the value and returns a tuple (object_id, attr_updates) where object_id is a unique identifier inside the target scope (such as a resolver name) and attr_updates is a dictionary consisting of key-value-pairs where each keys is an attribute name and each value its value.

Warning

The order in which the parsers are added is relevant. Later parsers have a higher priority

consume_entry(composite_key, value)

Integrates a config pair of a composite key and value into the tree.

Parameters
  • composite_key – A composite key from the config (such as ‘linotp.Policy.mypolicy.scope’)

  • value – The associated value

Raises

ConfigNotRecognized – If none of the defined parsers recognized the config pair

pretty()

Returns a pretty print of the tree

linotp.lib.config.parsing.parse_config(config_dict)

Translates a flat config_dict into a hierarchical ConfigTree

Parameters

config_dict – The config dictionary retrieved from the low-level typing API

Returns

ConfigTree object

linotp.lib.config.parsing.parse_deprecated_enc(composite_key, value)

Parses soon to be deprecated ‘enclinotp’ config entries

::warning: does a very generic match. should be added last to the

internal config tree parser list

linotp.lib.config.parsing.parse_system_config(composite_key, value)

Parses system config entries

::warning: does a very generic match. should be added last to the

internal config tree parser list