NAME

Myriad::Config - dynamic configuration management for microservices

DESCRIPTION

Configuration support.

PACKAGE VARIABLES

DEFAULTS

The %DEFAULTS hash provides base values that will be used if no other configuration file, external storage or environment variable provides an alternative.

FULLNAME_FOR

The %FULLNAME_FOR hash maps commandline shortcuts for common parameters.

SERVICES_CONFIG

A registry of service configuration defined by the services using the config helper.

ACTIVE_SERVICES_CONFIG

A collection of Ryu::Observable instances for notifying services about updates on their configuration.

clear_key

Delete a single config the best use case for this sub is during tests.

clear_all

Delete all the config that has been parsed by this module, the best use case for this sub is during tests.

parse_subargs

A helper to resolve the correct service config

input is expected to look like:

<service_name>_[config|instance].<key>

and this sub will set the correct path to key with the provided value.

Example:

dummy_service.config.password

will end up in

$config->{services}->{dummy_service}->{config}->{password}

Takes the following parameters:

  • $subarg - the arguments as passed by the user.

  • $root - the level in which we should add the sub arg, we start from $config->{services}.

  • $value - the value that we should assign after resolving the config path.

lookup_from_args

Parse the arguments provided from the command line.

There are many modules that can parse command lines arguments but in our case we have unknown arguments - the services config - that might be passed by the user or might not and they are on top of that nested.

This sub simply start looking for a match for the arg at hand in %DEFAULTS then it searches in the shortcuts map and lastly it tries to parse it as a subarg.

Currently this sub takes into account flags (0|1) config and config written as: config=value

lookup_from_env

Try to find environment variables that start with MYRIAD_* and parse them.

lookup_from_file

Fill the config from the config file

this sub doesn't do much currently since the config structure is modelled exactly like how it should be in the file so it just read the file.

service_config

Takes a service base package and its current name and tries to resolve its config from:

1. The framework storage itself (i.e Redis or Postgres ..etc). 2. From the config parsed earlier (cmd, env, file).

and if it fails to find a required config it will throw an error.

it takes

  • pkg - The package name of the service, will be used to lookup for generic config

  • service_name - The current service name either from the registry or as it bassed by the user, useful for instance config

service_name

Check if the developer configured a name for this service. This is different from service_config because we are going to check args and ENV only looking using the default Myriad::Registry assigned name

from_storage

Tries to find the config key in the storage using Myriad::Storage.

it takes

  • service_name - The service name.

  • instance - If the service has many instances (e.g demo, production) this should the identifier.

  • key - The required config key (e.g password, username ..etc).

INHERITED METHODS

Object::Pad::UNIVERSAL

BUILDARGS

AUTHOR

Deriv Group Services Ltd. DERIV@cpan.org.

See "CONTRIBUTORS" in Myriad for full details.

LICENSE

Copyright Deriv Group Services Ltd 2020-2022. Licensed under the same terms as Perl itself.