configfile
This module provides functionality for managing and loading application configuration files, default settings, and SSL-related configurations. It includes utilities for locating, reading, and processing configuration files, as well as handling SSL certificates and protocols for various server types.
It houses the CONFIG object that's used throughout Merlin's codebase.
default_config_info()
Returns information about Merlin's default configurations.
This function gathers and returns key details about the current configuration of the Merlin application, including the location of the configuration file, debug mode status, the Merlin home directory, and whether the Merlin home directory exists.
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary containing the following keys:
|
Source code in merlin/config/configfile.py
find_config_file(path=None)
Locate the Merlin application configuration file (app.yaml).
This function searches for the configuration file based on a given directory or,
if no directory is provided, uses a fallback sequence:
1. Check for app.yaml in the current working directory.
2. Check if CONFIG_PATH_FILE exists and points to a valid config file.
3. Check for app.yaml in the MERLIN_HOME directory.
If a path is explicitly provided, the function checks only that directory
for app.yaml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
A specific directory to look for |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The full path to the |
Source code in merlin/config/configfile.py
get_cert_file(server_type, config, cert_name, cert_path)
Determines the SSL certificate file for a given server configuration.
This function checks if an SSL certificate file is specified in the server configuration. If the file does not exist, it attempts to locate the certificate in an optional certificate path. If the certificate file cannot be found, an error is logged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_type
|
str
|
The type of server (e.g., Broker, Results Backend) for logging purposes. |
required |
config
|
Config
|
The server configuration object containing certificate details. |
required |
cert_name
|
str
|
The name of the certificate attribute in the configuration. |
required |
cert_path
|
str
|
An optional directory path to search for the certificate file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The absolute path to the certificate file if found, otherwise |
Source code in merlin/config/configfile.py
get_config(path=None)
Loads a Merlin configuration file and returns a dictionary containing the configuration data.
This function locates the configuration file using the provided path or default search locations,
loads the configuration data, and applies default values where necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The directory path to search for the configuration file.
If |
None
|
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary containing all the configuration data, including broker, results backend, and task manager settings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the configuration file cannot be found and it's not a local run. |
Source code in merlin/config/configfile.py
get_default_config()
Creates a minimal default configuration for local mode.
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
A configuration dictionary with essential default values. |
Source code in merlin/config/configfile.py
get_ssl_entries(server_type, server_name, server_config, cert_path)
Retrieves SSL configuration entries for a given server.
This function checks for SSL certificate files and other SSL-related settings in the server configuration. It builds and returns a dictionary containing the necessary data to manage SSL certificates and protocols for the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_type
|
str
|
The type of server (e.g., Broker, Results Backend) for logging purposes. |
required |
server_name
|
str
|
The name of the server, used for output and mapping SSL configurations. |
required |
server_config
|
Config
|
The server configuration object containing SSL settings. |
required |
cert_path
|
str
|
An optional directory path to search for certificate files. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Union[str, VerifyMode]]
|
A dictionary containing SSL configuration entries, including:
|
Source code in merlin/config/configfile.py
initialize_config(path=None, local_mode=False)
Initializes and returns the Merlin configuration.
This function can be used to explicitly initialize the configuration when needed, rather than relying on the module-level CONFIG constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Optional[str]
|
Path to look for configuration file |
None
|
local_mode
|
bool
|
Whether to use local mode (no config file required) |
False
|
Returns:
| Type | Description |
|---|---|
Config
|
The initialized configuration object |
Source code in merlin/config/configfile.py
is_debug()
Determines whether the application is running in debug mode.
This function checks the environment variable MERLIN_DEBUG. If the variable
exists and its value is set to 1, debug mode is enabled.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Source code in merlin/config/configfile.py
is_local_mode()
Checks if Merlin is running in local mode.
Returns:
| Type | Description |
|---|---|
bool
|
True if running in local mode, False otherwise. |
load_config(filepath)
Reads a Merlin YAML configuration file and returns its contents as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
The path to the YAML configuration file. |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary containing the contents of the YAML file or None if file doesn't exist. |
Source code in merlin/config/configfile.py
load_default_celery(config)
Initializes the default Celery configuration within the provided configuration object.
This function ensures that the celery section of the configuration exists and sets
default values for specific Celery-related settings if they are not already defined.
These defaults include omit_queue_tag, queue_tag, and override.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict
|
The configuration object where the Celery settings will be initialized. |
required |
Source code in merlin/config/configfile.py
load_defaults(config)
Loads default configuration values into the provided configuration dictionary.
This function initializes default values for various configuration sections,
including user-related settings and Celery-specific settings, by calling
set_username_and_vhost and load_default_celery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict
|
The configuration dictionary to be updated with default values. |
required |
Source code in merlin/config/configfile.py
merge_sslmap(server_ssl, ssl_map)
Updates the keys of the server_ssl dictionary based on the ssl_map for specific server types.
This function modifies the server_ssl dictionary by replacing its keys with the corresponding
keys from the ssl_map when the server type requires specialized key names (e.g., rediss or mysql).
If a key in server_ssl is not found in ssl_map, it remains unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_ssl
|
Dict[str, Union[str, VerifyMode]]
|
The dictionary constructed in |
required |
ssl_map
|
Dict[str, str]
|
A dictionary mapping standard SSL keys to server-specific keys. |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
A new dictionary with updated keys based on the |
Source code in merlin/config/configfile.py
process_ssl_map(server_name)
Processes and returns a mapping of SSL-related configuration keys specific to certain server types (e.g., Redis and MySQL).
This function generates a dictionary mapping standard SSL configuration keys
(e.g., keyfile, certfile, ca_certs, cert_reqs) to server-specific key names
required by Redis (rediss) or MySQL server configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_name
|
str
|
The name of the server (e.g., "rediss", "mysql") used to determine the appropriate SSL key mappings. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
A dictionary containing the SSL key mappings for the given server type. Returns an empty
dictionary if the server type is not |
Source code in merlin/config/configfile.py
set_local_mode(enable=True)
Sets Merlin to run in local mode, which doesn't require a configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable
|
bool
|
True to enable local mode, False to disable it. |
True
|
Source code in merlin/config/configfile.py
set_username_and_vhost(config)
Ensures that broker.username and broker.vhost default values are set in the
configuration if they are not already defined.
This function checks the config object for the presence of broker.username
and broker.vhost. If either is missing, it sets their default values using
the current system username. This prevents other parts of the code from having
to handle missing values for these fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict
|
The configuration object containing the |
required |