Kea 2.7.5
|
Configuration Manager. More...
#include <d_cfg_mgr.h>
Public Member Functions | |
DCfgMgrBase (ConfigPtr context) | |
Constructor. | |
virtual | ~DCfgMgrBase () |
Destructor. | |
virtual std::string | getConfigSummary (const uint32_t selection)=0 |
Returns configuration summary in the textual format. | |
ConfigPtr & | getContext () |
Fetches the configuration context. | |
isc::data::ConstElementPtr | redactConfig (isc::data::ConstElementPtr const &config) const |
Redact the configuration. | |
isc::data::ConstElementPtr | simpleParseConfig (isc::data::ConstElementPtr config, bool check_only=false, const std::function< void()> &post_config_cb=nullptr) |
Acts as the receiver of new configurations. | |
Protected Member Functions | |
virtual ConfigPtr | createNewContext ()=0 |
Abstract factory which creates a context instance. | |
virtual std::list< std::list< std::string > > | jsonPathsToRedact () const |
Return a list of all paths that contain passwords or secrets. | |
virtual isc::data::ConstElementPtr | parse (isc::data::ConstElementPtr config, bool check_only) |
Parses actual configuration. | |
void | resetContext () |
Replaces existing context with a new, empty context. | |
virtual void | setCfgDefaults (isc::data::ElementPtr mutable_config) |
Adds default values to the given config. | |
void | setContext (ConfigPtr &context) |
Update the current context. | |
Configuration Manager.
DCfgMgrBase is an abstract class that provides the mechanisms for managing an application's configuration. This includes services for parsing sets of configuration values, storing the parsed information in its converted form, and retrieving the information on demand. It is intended to be the worker class which is handed a set of configuration values to process by upper application management layers.
This class allows two configuration methods:
The class presents a public method for receiving new configurations, parseConfig. This method coordinates the parsing effort as follows:
The above structuring ensures that global parameters are parsed first making them available during subsequent object element parsing. The order in which the object elements are processed is either:
This allows a derivation to specify the order in which its elements are parsed if there are dependencies between elements.
To parse a given element, its id along with the element itself, is passed into the virtual method, parseElement
. Derivations are expected to converts the element into application specific object(s), thereby isolating the CPL from application details.
In the event that an error occurs, parsing is halted and the configuration context is restored from backup.
See isc::d2::D2CfgMgr and isc::d2::D2Process for example use of this approach.
This approach assumes usage of isc::data::SimpleParser paradigm. It does not use any intermediate storage, does not use parser pointers, does not enforce parsing order.
Here's the expected control flow order:
See isc::agent::CtrlAgentCfgMgr and isc::agent::CtrlAgentProcess for example use of this approach.
Definition at line 108 of file d_cfg_mgr.h.
isc::process::DCfgMgrBase::DCfgMgrBase | ( | ConfigPtr | context | ) |
Constructor.
context | is a pointer to the configuration context the manager will use for storing parsed results. |
throws | DCfgMgrBaseError if context is null |
Definition at line 37 of file d_cfg_mgr.cc.
References setContext().
|
virtual |
Destructor.
Definition at line 41 of file d_cfg_mgr.cc.
|
protectedpure virtual |
Abstract factory which creates a context instance.
This method is used at the beginning of configuration process to create a fresh, empty copy of the derivation-specific context. This new context will be populated during the configuration process and will replace the existing context provided the configuration process completes without error.
Implemented in isc::agent::CtrlAgentCfgMgr, isc::d2::D2CfgMgr, and isc::netconf::NetconfCfgMgr.
Referenced by resetContext().
|
pure virtual |
Returns configuration summary in the textual format.
This method returns the brief text describing the current configuration. It may be used for logging purposes, e.g. whn the new configuration is committed to notify a user about the changes in configuration.
selection | Bitfield which describes the parts of the configuration to be returned. |
Implemented in isc::agent::CtrlAgentCfgMgr, isc::d2::D2CfgMgr, and isc::netconf::NetconfCfgMgr.
Referenced by simpleParseConfig().
|
inline |
Fetches the configuration context.
Definition at line 151 of file d_cfg_mgr.h.
Referenced by isc::agent::CtrlAgentCfgMgr::getCtrlAgentCfgContext(), isc::d2::D2CfgMgr::getD2CfgContext(), and isc::d2::D2CfgMgr::parse().
|
protectedvirtual |
Return a list of all paths that contain passwords or secrets.
Used in isc::process::Daemon::redactConfig to only make copies and only redact configuration subtrees that contain passwords or secrets.
This method needs to be overridden in each process that has a distinct configuration structure.
Reimplemented in isc::agent::CtrlAgentCfgMgr, isc::d2::D2CfgMgr, and isc::netconf::NetconfCfgMgr.
Definition at line 68 of file d_cfg_mgr.cc.
Referenced by redactConfig().
|
protectedvirtual |
Parses actual configuration.
This method is expected to be implemented in derived classes that employ SimpleParser paradigm (i.e. they call simpleParseConfig rather than parseConfig from their configure method).
Implementations that do not employ this method may provide dummy implementation.
config | the Element tree structure that describes the configuration. |
check_only | false for normal configuration, true when verifying only |
Reimplemented in isc::agent::CtrlAgentCfgMgr, isc::d2::D2CfgMgr, and isc::netconf::NetconfCfgMgr.
Definition at line 157 of file d_cfg_mgr.cc.
References isc_throw.
Referenced by simpleParseConfig().
ConstElementPtr isc::process::DCfgMgrBase::redactConfig | ( | isc::data::ConstElementPtr const & | config | ) | const |
Redact the configuration.
This method replaces passwords and secrets by asterisks. By default it follows all subtrees at the exception of user contexts. Please derive the method to allow a reasonable performance by following only subtrees where the syntax allows the presence of passwords and secrets.
config | the Element tree structure that describes the configuration. |
Definition at line 60 of file d_cfg_mgr.cc.
References jsonPathsToRedact(), and isc::process::redactConfig().
Referenced by simpleParseConfig().
|
protected |
Replaces existing context with a new, empty context.
Definition at line 45 of file d_cfg_mgr.cc.
References createNewContext(), and setContext().
Referenced by simpleParseConfig().
|
protectedvirtual |
Adds default values to the given config.
Provides derivations a means to add defaults to a configuration Element map prior to parsing it.
mutable_config | - configuration to which defaults should be added |
Reimplemented in isc::d2::D2CfgMgr.
Definition at line 153 of file d_cfg_mgr.cc.
|
protected |
Update the current context.
Replaces the existing context with the given context.
context | Pointer to the new context. |
DCfgMgrBaseError | if context is NULL. |
Definition at line 51 of file d_cfg_mgr.cc.
References isc_throw.
Referenced by DCfgMgrBase(), and resetContext().
isc::data::ConstElementPtr isc::process::DCfgMgrBase::simpleParseConfig | ( | isc::data::ConstElementPtr | config, |
bool | check_only = false, | ||
const std::function< void()> & | post_config_cb = nullptr ) |
Acts as the receiver of new configurations.
This method is similar to what parseConfig did, execept it employs the simple parser paradigm: no intermediate storage, no parser pointers no distinction between params_map and objects_map, parse order (if needed) can be enforced in the actual implementation by calling specific parsers first. See isc::agent::CtrlAgentCfgMgr::parse for example.
If check_only is true, the actual parsing is done to check if the configuration is sane, but is then reverted.
config | set of configuration elements to be parsed |
check_only | true if the config is to be checked only, but not applied |
post_config_cb | Callback to be executed after the usual parsing stage. This can be specified as a C++ lambda which configures other parts of the system based on the parsed configuration information. The callback should throw an exception to signal an error. This method will catch this exception and place an exception string within the result returned. |
Definition at line 74 of file d_cfg_mgr.cc.
References isc::config::answerToText(), isc::process::Daemon::configureLogger(), isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::log::DBGLVL_COMMAND, isc::process::DCTL_CONFIG_CHECK_COMPLETE, isc::process::DCTL_CONFIG_COMPLETE, isc::process::DCTL_CONFIG_START, isc::process::dctl_logger, isc::process::DCTL_PARSER_FAIL, getConfigSummary(), LOG_DEBUG, LOG_ERROR, LOG_INFO, parse(), isc::config::parseAnswer(), redactConfig(), and resetContext().