Config Infrastructure Module (tendril.utils.config)

This module provides reusable infrastructure used by the tendril instance configuration.

TODO Describe Architecture and Usage somewhere

class tendril.utils.config.ConfigElement(name, default, doc, parser=None, masked=False)[source]

Bases: object

doc_render()[source]
value
masked_value

Return a masked version of the value of the option.

If the option is not to be masked, the value is returned unchanged. If the field is to be masked, the masked value is returned. The masking algorithm is as follows:

  • If the value is not a string, it is returned unchanged.
  • If the value is a string, the first 8 characters (or 1/8 of the string, whichever is shorter) are returned, followed by ellipses and the last 8 characters (or 1/8 of the string, whichever is shorter)

(doc generated mostly by GitHub Copilot) Returns:

str: The masked value of the field.
tendril.utils.config.bool_parser(value)[source]
class tendril.utils.config.ConfigConstant(name, default, doc, parser=None, masked=False)[source]

Bases: tendril.utils.config.ConfigElement

A configuration constant. This is fully specified in the core configuration module and cannot be changed by the user or the instance administrator without modifying the code.

The value itself is constructed using eval().

value
class tendril.utils.config.ConfigOption(name, default, doc, parser=None, masked=False)[source]

Bases: tendril.utils.config.ConfigElement

A configuration option. These options can be overridden by specifying them in the instance_config and local_config_overrides files.

If specified in one of those files, the value should be the actual configuration value and not an expression. The default value specified here is used through eval().

raw_value
value

Get the value of the property.

If a parser is defined, the value returned is the result of applying the parser to the raw value of the property. Otherwise, the raw value is returned.

(doc generated mostly by GitHub Copilot)

class tendril.utils.config.ConfigOptionConstruct(name, parameters, doc)[source]

Bases: tendril.utils.config.ConfigElement

value
exception tendril.utils.config.ExternalConfigMissingError(source, filetype)[source]

Bases: Exception

exception tendril.utils.config.ExternalConfigFormatError(source, filetype)[source]

Bases: Exception

exception tendril.utils.config.ExternalConfigKeyError(source, key)[source]

Bases: Exception

exception tendril.utils.config.ConfigSourceDoesNotProvideKey(source, key)[source]

Bases: tendril.utils.config.ExternalConfigKeyError

exception tendril.utils.config.ConfigSourceDoesNotContainKey(source, key, key_path)[source]

Bases: tendril.utils.config.ExternalConfigKeyError

class tendril.utils.config.ConfigSourceBase[source]

Bases: object

get(key)[source]
class tendril.utils.config.ConfigExternalSource(path, keymap)[source]

Bases: tendril.utils.config.ConfigSourceBase

path
get(key)[source]
_get(key_path)[source]
class tendril.utils.config.ConfigExternalJSONSource(path, keymap)[source]

Bases: tendril.utils.config.ConfigExternalSource

_load_external_config()[source]

This function loads the external config file into a dictionary

The external config file is a json file that contains some configuration parameters for the application.

(doc generated mostly by GitHub Copilot)

_get(key_path)[source]

Return the value at the end of the key_path.

key_path is a string of the form ‘key1:key2:key3’ where each key is a key in a dict. This function will return the value of key3 in the dict d[key1][key2]. If key1, key2, or key3 do not exist, a ConfigSourceDoesNotContainKey error will be raised.

(doc generated mostly by GitHub Copilot)

class tendril.utils.config.ConfigExternalSources(path)[source]

Bases: tendril.utils.config.ConfigSourceBase

_load_external_sources()[source]

This method loads the external config files from the given path. It iterates over each config and determines the format of the file. If the format is JSON, it will create a ConfigExternalJSONSource object and add it to the list of sources. If the file format is not supported, it will raise an ExternalConfigFormatError.

(doc generated mostly by GitHub Copilot)

get(key)[source]

Return the value associated with the key in the configured external sources.

Returns the value associated with the key in the first source that has the key. If the key is not found in any of the sources, raise ExternalConfigKeyError.

(doc generated mostly by GitHub Copilot)

Args:
key (str): The key to search for.
Returns:
The value associated with the key.
Raises:
ExternalConfigKeyError: If the key is not found in any of
the sources.
class tendril.utils.config.ConfigManager(prefix, legacy, excluded, appname=None)[source]

Bases: object

The ConfigManager class provides a consistent interface for accessing configuration information from a variety of sources. It is intended to be a singleton.

(doc generated mostly by GitHub Copilot)

_check_depends(depends)[source]
_load_legacy(m_name)[source]
legacy
_load_configs()[source]

Load configuration elements from modules.

This method will load configuration elements from modules in the current namespace. It will respect the dependency order specified in the depends attribute of each module while loading. If any dependencies are not satisfied, the module will be skipped until it is. If a module is skipped and there are no remaining modules to load, an error will be logged.

(doc generated mostly by GitHub Copilot)

load_config_files()[source]

Loads the configuration from different sources to populate the unified config object

(doc generated mostly by GitHub Copilot)

Returns:None
INSTANCE_CONFIG
LOCAL_CONFIG
EXTERNAL_CONFIG
ENVIRONMENT_OVERRIDES
load_elements(elements, doc='')[source]

Loads the constants and/or options in the provided list into the config namespace.

Parameters:elementslist of ConfigConstant or ConfigOption or ConfigOptionConstruct
Returns:None
instance_path(path)[source]
docs
doc_render()[source]

Returns a dictionary of documentation for the options.

The dictionary is keyed by the names of the option groups. The value for each group is a dictionary keyed by the names of the options in that group.

Each option value is a dictionary with the keys:

doc
The documentation string for the option.
default
The default value for the option.
value
The value of the option after all configuration files have been read.
source
The filename of the configuration file from which the option was read, or None if the option was not read from a configuration file.

(doc generated mostly by GitHub Copilot)

json_render()[source]

Render the config as a dict suitable for JSON encoding.

The structure is as follows:

{
‘section1’: {
‘item1’: {
‘value’: ‘value1’, ‘source’: ‘source1’,

}, ‘item2’: {

‘value’: ‘value2’, ‘source’: ‘source2’,

},

}, ‘section2’: {

‘item1’: {
‘value’: ‘value1’, ‘source’: ‘source1’,

}, ‘item2’: {

‘value’: ‘value2’, ‘source’: ‘source2’,

},

},

}

(doc generated mostly by GitHub Copilot)

Returns:a dict of the config.
log_render()[source]

This method logs the rendered configuration. It loops through the sections and names of the configuration, and prints the value of each option, as well as its source (the file in which it was defined). The value is masked if the option is sensitive.

(doc generated mostly by GitHub Copilot)

tendril.utils.config.generate_constants(instance_name)[source]
tendril.utils.config.install_config(manager, instance_name)[source]