MPT Consul Parser¶
-
class
django_docker_helpers.config.backends.mpt_consul_parser.
MPTConsulParser
(scope=None, host='127.0.0.1', port=8500, scheme='http', verify=True, cert=None, path_separator='.', consul_path_separator='/', object_deserialize_prefix='::YAML::\n', object_deserialize=<function default_yaml_object_deserialize>)[source]¶ Bases:
django_docker_helpers.config.backends.base.BaseParser
Materialized Path Tree Consul Parser.
Compared to, e.g.
ConsulParser
it does not load a whole config file from a single key, but reads every config option from a corresponding variable path.Example:
parser = MPTConsulParser(host=CONSUL_HOST, port=CONSUL_PORT, path_separator='.') parser.get('nested.a.b')
If you want to store your config with separated key paths take
mp_serialize_dict()
helper to materialize your dict.Parameters: - scope (
Optional
[str
]) – a global namespace-like variable prefix - host (
str
) – consul host, default is'127.0.0.1'
- port (
int
) – consul port, default is8500
- scheme (
str
) – consul scheme, default is'http'
- verify (
bool
) – verify certs, default isTrue
- cert – path to certificate bundle
- path_separator (
str
) – specifies which character separates nested variables, default is'.'
- consul_path_separator (
str
) – specifies which character separates nested variables in consul kv storage, default is'/'
- object_deserialize_prefix (
str
) – if object has a specified prefix, it’s deserialized withobject_deserialize
- object_deserialize (
Optional
[Callable
]) – deserializer for complex variables
-
get
(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]¶ Parameters: - variable_path (
str
) – a delimiter-separated path to a nested value - default (
Optional
[Any
]) – default value if there’s no object by specified path - coerce_type (
Optional
[Type
[+CT_co]]) – cast a type of a value to a specified one - coercer (
Optional
[Callable
]) – perform a type casting with specified callback - kwargs – additional arguments inherited parser may need
Returns: value or default
- variable_path (
- scope (