Options
All
  • Public
  • Public/Protected
  • All
Menu

Class YamlConfigReader

Config reader that reads configuration from YAML file.

The reader supports parameterization using Handlebars template engine.

Configuration parameters

  • path: path to configuration file
  • parameters: this entire section is used as template parameters
  • ...
see

IConfigReader

see

FileConfigReader

Example

======== config.yml ======
key1: "{{KEY1_VALUE}}"
key2: "{{KEY2_VALUE}}"
===========================

let configReader = new YamlConfigReader("config.yml");

let parameters = ConfigParams.fromTuples("KEY1_VALUE", 123, "KEY2_VALUE", "ABC");
configReader.readConfig("123", parameters, (err, config) => {
    // Result: key1=123;key2=ABC
});

Hierarchy

Implements

  • IConfigurable

Index

Constructors

constructor

Methods

configure

  • configure(config: ConfigParams): void

getPath

  • getPath(): string

Protected parameterize

  • parameterize(config: string, parameters: ConfigParams): string
  • Parameterized configuration template given as string with dynamic parameters.

    The method uses Handlebars template engine: https://handlebarsjs.com

    Parameters

    • config: string

      a string with configuration template to be parameterized

    • parameters: ConfigParams

      dynamic parameters to inject into the template

    Returns string

    a parameterized configuration string.

readConfig

  • readConfig(correlationId: string, parameters: ConfigParams, callback: function): void
  • Reads configuration and parameterize it with given values.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • parameters: ConfigParams

      values to parameters the configuration or null to skip parameterization.

    • callback: function

      callback function that receives configuration or error.

        • (err: any, config: ConfigParams): void
        • Parameters

          • err: any
          • config: ConfigParams

          Returns void

    Returns void

readObject

  • readObject(correlationId: string, parameters: ConfigParams): any
  • Reads configuration file, parameterizes its content and converts it into JSON object.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • parameters: ConfigParams

      values to parameters the configuration.

    Returns any

    a JSON object with configuration.

setPath

  • setPath(path: string): void

Static readConfig

  • readConfig(correlationId: string, path: string, parameters: ConfigParams): ConfigParams
  • Reads configuration from a file, parameterize it with given values and returns a new ConfigParams object.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • path: string
    • parameters: ConfigParams

      values to parameters the configuration or null to skip parameterization.

    Returns ConfigParams

Static readObject

  • readObject(correlationId: string, path: string, parameters: ConfigParams): any
  • Reads configuration file, parameterizes its content and converts it into JSON object.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • path: string
    • parameters: ConfigParams

      values to parameters the configuration.

    Returns any

    a JSON object with configuration.

Generated using TypeDoc