flexmeasures.utils.config_utils

Reading in configuration

Functions

flexmeasures.utils.config_utils.are_required_settings_complete(app) bool

Check if all settings we expect are not None. Return False if they are not. Printout helpful advice.

flexmeasures.utils.config_utils.check_app_env(env: str | None)
flexmeasures.utils.config_utils.configure_logging()

Configure and register logging

flexmeasures.utils.config_utils.find_flexmeasures_cfg() str | None

Try to find a flexmeasures.cfg file in the home or instance directories. Return the path if found, else None.

flexmeasures.utils.config_utils.get_config_warnings(app) tuple[list[str], list[str]]

return missing settings and the warnings for them.

flexmeasures.utils.config_utils.get_configuration_keys(app) list[str]

Collect all members of DefaultConfig who are not in-built fields or callables.

flexmeasures.utils.config_utils.get_flexmeasures_env(app, cfg_location) str | None

Determine which flexmeasures_env should be used, trying various ways in decreasing importance.

flexmeasures.utils.config_utils.normalize_trusted_hosts(app: Flask) None

Turn a comma-separated TRUSTED_HOSTS string into a list, and an empty one into None.

Werkzeug matches a plain string as a single host, so “a.example.com,b.example.com” would silently match nothing. It also trusts every host when the list is empty, just as when the setting is unset, so an empty value (e.g. TRUSTED_HOSTS=”” in a container env file) becomes None. Otherwise it would disable host validation while passing as configured, suppressing the warning.

flexmeasures.utils.config_utils.parse_bool_env(value: str) bool

Parse a boolean setting from a (case-insensitive) environment variable string.

“true”, “1”, “yes” and “on” count as True; anything else is False. Surrounding whitespace is ignored.

flexmeasures.utils.config_utils.read_config(app: Flask, custom_path_to_config: str | None)

Read configuration from various expected sources, complain if not setup correctly.

flexmeasures.utils.config_utils.read_custom_config(app: Flask, suggested_path_to_config, path_to_config_home, path_to_config_instance) str

Read in a custom config file and env vars. For the config, there are two fallback options, tried in a specific order: If no custom path is suggested, we’ll try the path in the home dir first, then in the instance dir.

Return the path to the config file.

flexmeasures.utils.config_utils.read_env_vars(app: Flask)

Read in what we support as environment settings. At the moment, these are: - All required and warnable variables - Logging and debugging settings - access tokens - plugins (handled in plugin utils) - json compactness - two-factor authentication (SECURITY_TOTP_SECRETS is handled in app_utils.set_totp_secrets)

Settings whose default is a boolean are parsed as booleans (env values are strings, and e.g. “False” is truthy).