decisionengine.framework.config package

Subpackages

Submodules

decisionengine.framework.config.ChannelConfigHandler module

Manager of channel configurations.

The ChannelConfigHandler manages only channel configurations and not the global decision-engine configuration. It is responsible for loading channel configuration files and validating that the channels have the correct configuration artifacts.

class decisionengine.framework.config.ChannelConfigHandler.ChannelConfigHandler(global_config, channel_config_dir)[source]

Bases: object

_load_channel(channel_name, path)[source]
get_channels()[source]
load_all_channels()[source]

Load all channel configurations inside the stored channel-configuration directory.

Any cached configurations will be dropped prior to reloading.

load_channel(channel_name)[source]

Load a single configuration for a channel with the supplied name.

The behavior is to read a configuration file whose path is:

<cached channel config. dir>/{channel_name}.jsonnet

where the cached channel-configuration directory was stored whenever the ChannelConfigHandler object was created, and {channel_name} is the value of the supplied method argument.

print_channel_config(channel)[source]
decisionengine.framework.config.ChannelConfigHandler._check_keys(channel_conf_dict)[source]

check that channel config has mandatory keys :type data: dict

decisionengine.framework.config.ChannelConfigHandler._make_de_logger(global_config)[source]

decisionengine.framework.config.ValidConfig module

ValidConfig represents a valid JSON document.

The decision engine requires each of its configuration files to be valid JSON. This is achieved by either supplying a valid Jsonnet or JSON document upfront.

Vetting of a file for JSON validity happens upon construction of a ‘ValidConfig’ object. A fully constructed ‘ValidConfig’ object thus corresponds to a valid JSON document.

class decisionengine.framework.config.ValidConfig.ValidConfig(filename, jpathdirs=None)[source]

Bases: UserDict

ValidConfig represents a valid JSON configuration in the form of a dictionary.

In addition to the normal dictionary operations, users may call ‘dump()’ to print out in a string form the JSON configuration.

_abc_impl = <_abc._abc_data object>
dump()[source]

Print dictionary data to a valid JSON string.

decisionengine.framework.config.ValidConfig._config_from_file(config_file, jpaths=None)[source]

decisionengine.framework.config.policies module

Decision-engine default configuration policies.

For the decision-engine process, the configuration policies are:

  • The global configuration file must be named ‘decision_engine.jsonnet’ and it must reside in (a) a directory that can be accessed through the ‘CONFIG_PATH’ environment variable, or (b) the /etc/decisionengine directory.

  • All channel configurations must reside in (a) a directory accessible through the ‘CHANNEL_CONFIG_PATH’ environment variable, or (b) a ‘config.d’ subdirectory of the /etc/decisionengine directory.

The utilities provided in this module provide simple means of accessing the configuration artifacts according to the policies listed above. Please consult the documentation for each function below for more detailed information.

decisionengine.framework.config.policies.channel_config_dir(parent_dir=None)[source]

Retrieve the channel configuration directory as a pathlib.Path object.

This function returns a path object according to the following precedence rules:

  1. If the ‘parent_dir’ argument is provided, the returned path object will correspond to ‘{parent_dir}/config.d’.

  2. If the ‘CHANNEL_CONFIG_PATH’ environment variable has been set, the returned path object will correspond to ${CHANNEL_CONFIG_PATH}.

  3. If neither 1 or 2 apply, the returned path object corresponds to ‘{global_config_dir()}/config.d’ (see documentation for ‘global_config_dir()’).

Regardless of the precedence rule used, the returned path object must be a valid directory or an exception will be raised–i.e. if the ‘parent_dir’ argument is supplied, and the resulting path object is not a valid directory, the function will exit with an exception and not attempt rule 2 or 3.

decisionengine.framework.config.policies.global_config_dir()[source]

Retrieve global configuration dir as pathlib.Path object.

This is the directory that houses the ‘decision_engine.jsonnet’ global configuration file.

This function checks that the ‘CONFIG_PATH’ variable has been set or will use /etc/decisionengine otherwise. If the path exists as a directory, then the directory path is returned as a string; otherwise an exception is raised.

decisionengine.framework.config.policies.global_config_file(parent_dir=None)[source]

Return the pathlib.Path object corresponding to the global configuration.

If supplied, the ‘parent_dir’ is assumed to be the full path corresponding to a directory containing the ‘decision_engine.jsonnet’ file. If not provided, the global configuration directory is determined based on the behavior of the ‘global_config_dir()’ function.

An exception is raised if no ‘decision_engine.jsonnet’ file is found.

decisionengine.framework.config.policies.valid_dir(path, scope)[source]

Throws if the supplied path object is not a directory, otherwise returns the path object.

Module contents