Implements: FileConfigReader
Description
The JsonConfigReader class allows you to create a config reader that reads a configuration from a JSON file.
Important points
- The reader supports parameterization using Handlebar template engine.
Configuration parameters
- path: path to the configuration file
- parameters: this entire section is used as template parameters
- …
Constructors
Creates a new instance of the config reader.
JsonConfigReader(path: str = None)
- path: str - (optional) path to the configuration file.
Instanc methods
read_config_
Reads a configuration and parameterizes it with given values.
read_config_(correlation_id: Optional[str], parameters: ConfigParams): ConfigParams
- correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
- parameters: ConfigParams - values to parameters the configuration or None to skip parameterization.
- returns: ConfigParams - ConfigParams configuration.
read_object_
Reads a configuration file, parameterizes its content and converts it into a JSON object.
read_object_(correlation_id: Optional[str], parameters: ConfigParams): Any
- correlation_id: Optional[str] - (optional) transaction id to trace execution through a call chain.
- parameters: ConfigParams - values of the configuration parameters.
- returns: Any - a JSON object with configuration.
read_config
Reads a configuration from a file, parameterizes it with given values and returns a new ConfigParams object.
static
read_config(correlation_id: Optional[str], path: str, parameters: ConfigParams): ConfigParams
- correlation_id: Optional[str] - (optional) transaction id used to trace execution through a call chain.
- path: str - a path to configuration file.
- parameters: ConfigParams - values of the configuration parameters.
- returns: ConfigParams - ConfigParams configuration.
read_object
Reads a configuration file, parameterizes its content and converts it into a JSON object.
static
read_config(correlation_id: Optional[str], path: str, parameters: ConfigParams): Any
- correlation_id: Optional[str] - (optional) transaction id to trace execution through a call chain.
- path: str - a path to configuration file.
- parameters: ConfigParams - values of the configuration parameters.
- returns: Any - a JSON object with configuration.
Examples
{ "key1": "{{KEY1_VALUE}}", "key2": "{{KEY2_VALUE}}" }
configReader = JsonConfigReader("config.json")
parameters = ConfigParams.from_tuples("KEY1_VALUE", 123, "KEY2_VALUE", "ABC")
configReader.read_config_("123", parameters)