Consul Parser¶
- class django_docker_helpers.config.backends.consul_parser.ConsulParser(endpoint='service', host='127.0.0.1', port=8500, scheme='http', verify=True, cert=None, kv_get_opts=None, path_separator='.', inner_parser_class=<class 'django_docker_helpers.config.backends.yaml_parser.YamlParser'>)[source]¶
Reads a whole config bundle from a consul kv key and provides the unified interface to access config options.
It assumes that config in your storage can be parsed with any simple parser, like
YamlParser
.Compared to, e.g.
EnvironmentParser
it does not have scope support by design, sinceendpoint
is a good enough scope by itself.Example:
parser = ConsulParser('my/server/config.yml', host=CONSUL_HOST, port=CONSUL_PORT) parser.get('nested.a.b', coerce_type=int)
- Parameters
endpoint (
str
) – specifies a key in consul kv storage, e.g.'services/mailer/config.yml'
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 (
Optional
[str
]) – path to certificate bundlekv_get_opts (
Optional
[Dict
]) – read config bundle with optional arguments toclient.kv.get()
path_separator (
str
) – specifies which character separates nested variables, default is'.'
inner_parser_class (
Optional
[Type
[BaseParser
]]) – use the specified parser to read config fromendpoint
key
- get(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]¶
Reads a value of
variable_path
from consul kv storage.- Parameters
variable_path (
str
) – a delimiter-separated path to a nested valuedefault (
Optional
[Any
]) – default value if there’s no object by specified pathcoerce_type (
Optional
[Type
]) – cast a type of a value to a specified onecoercer (
Optional
[Callable
]) – perform a type casting with specified callbackkwargs – additional arguments inherited parser may need
- Returns
value or default
- Raises
config.exceptions.KVStorageKeyDoestNotExist – if specified
endpoint
does not existsconfig.exceptions.KVStorageValueIsEmpty – if specified
endpoint
does not contain a config
- get_client()[source]¶
If your backend needs a client, inherit this method and use
client()
shortcut.- Returns
an instance of backend-specific client
- property inner_parser: django_docker_helpers.config.backends.base.BaseParser¶
Prepares inner config parser for config stored at
endpoint
.- Return type
- Returns
an instance of
BaseParser
- Raises
config.exceptions.KVStorageKeyDoestNotExist – if specified
endpoint
does not existsconfig.exceptions.KVStorageValueIsEmpty – if specified
endpoint
does not contain a config