dodo
0.0.1
A C++ library to create containerized Linux services
|
Singleton interface to a (read-only) deployment configuration, combining data from the deployment configuration file, environment variables and some operating system attributes such as the CPU count, RAM and virtual memory size. More...
#include <config.hpp>
Public Types | |
typedef std::list< std::string > | KeyPath |
Used by getValue, enable use of list initializers as path specification, eg. More... | |
Public Member Functions | |
Config (const Config &)=delete | |
Disallow the copy constructor as this is a singleton. More... | |
bool | exists (const KeyPath &keypath) const |
Return true if the KeyPath exists. More... | |
std::string | getAppName () const |
Return the application name. More... | |
std::string | getConfigPath () const |
Return the path of the configuration file. More... | |
void | getDecryptedValue (const KeyPath &keypath, Bytes &decrypted) |
Get the decrypted value from KeyPath - decrypted using the secret from getSecret(). More... | |
std::string | getSecret () const |
Get the application secret. More... | |
template<typename T > | |
T | getValue (const KeyPath &keypath) const |
Get the value at keypath. More... | |
Config & | operator= (const Config &)=delete |
Disallow assignment from another Config, as this is a singleton. More... | |
void | readConfig () |
Read the configuration file. More... | |
Static Public Member Functions | |
static std::string | flattenKeyPath (const KeyPath &keypath) |
Transform a keypath to a string with ":" as seperator between levels. More... | |
static Config * | getConfig () |
return the singleton. More... | |
static Config * | initialize (const std::string path) |
Initialize the singleton. More... | |
Static Public Attributes | |
static const Config::KeyPath | config_dodo = {"dodo"} |
The dodo root node. More... | |
static const Config::KeyPath | config_dodo_common = {"dodo","common"} |
The dodo.common node. More... | |
static const Config::KeyPath | config_dodo_common_application = {"dodo","common","application"} |
The dodo.common.application node. More... | |
static const Config::KeyPath | config_dodo_common_application_name = {"dodo","common","application","name"} |
The dodo.common.application.name node. More... | |
static const Config::KeyPath | config_dodo_common_application_secret = {"dodo","common","application","secret"} |
The dodo.common.application.secret node. More... | |
static const Config::KeyPath | config_dodo_common_application_secret_env = {"dodo","common","application","secret","env"} |
The dodo.common.application.secret.env node. More... | |
static const Config::KeyPath | config_dodo_common_application_secret_file = {"dodo","common","application","secret","file"} |
The dodo.common.application.secret.file node. More... | |
static const Config::KeyPath | config_dodo_common_logger = {"dodo","common","logger"} |
The dodo.common.logger node. More... | |
static const Config::KeyPath | config_dodo_common_logger_console = {"dodo","common","logger","console"} |
The dodo.common.logger.console node. More... | |
static const Config::KeyPath | config_dodo_common_logger_console_level = {"dodo","common","logger","console","level"} |
The dodo.common.logger.console.level node. More... | |
static const Config::KeyPath | config_dodo_common_logger_file = {"dodo","common","logger","file"} |
The dodo.common.logger.file node. More... | |
static const Config::KeyPath | config_dodo_common_logger_file_directory = {"dodo","common","logger","file","directory"} |
The dodo.common.logger.file.directory node. More... | |
static const Config::KeyPath | config_dodo_common_logger_file_level = {"dodo","common","logger","file","level"} |
The dodo.common.logger.file.level node. More... | |
static const Config::KeyPath | config_dodo_common_logger_file_max_file_trail = {"dodo","common","logger","file","max-file-trail"} |
The dodo.common.logger.file.max-file-trail node. More... | |
static const Config::KeyPath | config_dodo_common_logger_file_max_size_mib = {"dodo","common","logger","file","max-size-mib"} |
The dodo.common.logger.file.max-size-mib node. More... | |
static const Config::KeyPath | config_dodo_common_logger_syslog = {"dodo","common","logger","syslog"} |
The dodo.common.logger.syslog node. More... | |
static const Config::KeyPath | config_dodo_common_logger_syslog_facility = {"dodo","common","logger","syslog","facility"} |
The dodo.common.logger.syslog.facility node. More... | |
static const Config::KeyPath | config_dodo_common_logger_syslog_level = {"dodo","common","logger","syslog","level"} |
The dodo.common.logger.syslog.level node. More... | |
Protected Member Functions | |
Config (const std::string path) | |
Constructor called by initialize(). More... | |
virtual | ~Config () |
Destructor. More... | |
void | checkConfig () |
Check for required elements in the config file. More... | |
Protected Attributes | |
std::string | secret_ |
The encryption secret / key. More... | |
YAML::Node | yaml_ |
The root YAML node. More... | |
Static Protected Attributes | |
static Config * | config_ = nullptr |
The singleton pointer. More... | |
static std::string | path_ = "" |
The path to the configuration file. More... | |
Friends | |
class | Application |
Application::~Application() will destruct this singleton. More... | |
Singleton interface to a (read-only) deployment configuration, combining data from the deployment configuration file, environment variables and some operating system attributes such as the CPU count, RAM and virtual memory size.
As multiple threads may be reading and modifying the configuration data, access must be serialized. However, as the data is exposed as a reference to a YAML::Node, this class cannot control serialization transparently. Developers know when they are done reading or writing the configuration data. For example
Definition at line 52 of file config.hpp.
typedef std::list<std::string> dodo::common::Config::KeyPath |
Used by getValue, enable use of list initializers as path specification, eg.
on this YAML
would set s to "foo". A KeyPath cannot index into arrays.
Definition at line 68 of file config.hpp.
|
delete |
Disallow the copy constructor as this is a singleton.
Referenced by initialize().
|
protected |
Constructor called by initialize().
path | The path to the configuration file. |
Definition at line 57 of file config.cpp.
References path_, and readConfig().
|
inlineprotectedvirtual |
Destructor.
Definition at line 228 of file config.hpp.
|
protected |
Check for required elements in the config file.
Definition at line 73 of file config.cpp.
References config_dodo, config_dodo_common, config_dodo_common_application, config_dodo_common_application_name, config_dodo_common_application_secret, config_dodo_common_application_secret_env, config_dodo_common_application_secret_file, config_dodo_common_logger, config_dodo_common_logger_console, config_dodo_common_logger_console_level, config_dodo_common_logger_file, config_dodo_common_logger_file_directory, config_dodo_common_logger_file_level, config_dodo_common_logger_syslog, config_dodo_common_logger_syslog_level, exists(), dodo::common::fileReadString(), flattenKeyPath(), path_, secret_, and throw_Exception.
Referenced by readConfig().
|
inline |
Return true if the KeyPath exists.
keypath | The KeyPath to check. |
Definition at line 201 of file config.hpp.
References yaml_.
Referenced by checkConfig(), dodo::common::Logger::getFileParams(), and dodo::common::Logger::Logger().
|
static |
Transform a keypath to a string with ":" as seperator between levels.
keypath | The KeyPath to flatten. |
Definition at line 127 of file config.cpp.
Referenced by checkConfig(), getDecryptedValue(), and getValue().
|
inline |
Return the application name.
Definition at line 174 of file config.hpp.
Referenced by dodo::common::Application::Application(), dodo::common::Logger::formatMessage(), dodo::common::Logger::getFileParams(), and dodo::common::Logger::log().
|
static |
return the singleton.
Exception | when |
Definition at line 68 of file config.cpp.
References config_, and throw_Exception.
Referenced by dodo::common::Logger::formatMessage(), dodo::common::Logger::getFileParams(), dodo::common::Logger::log(), and dodo::common::Logger::Logger().
|
inline |
Return the path of the configuration file.
Definition at line 162 of file config.hpp.
References path_.
Get the decrypted value from KeyPath - decrypted using the secret from getSecret().
keypath | The KeyPath to the the value for. |
decrypted | Receives the decrypted Bytes. |
Definition at line 136 of file config.cpp.
References dodo::common::DataCrypt::decrypt(), flattenKeyPath(), getSecret(), path_, throw_Exception, and yaml_.
|
inline |
Get the application secret.
Definition at line 180 of file config.hpp.
References secret_.
Referenced by getDecryptedValue().
|
inline |
Get the value at keypath.
keypath | The KeyPath to get the value for. |
Definition at line 187 of file config.hpp.
References flattenKeyPath(), path_, throw_Exception, and yaml_.
Referenced by dodo::common::Logger::getFileParams(), and dodo::common::Logger::Logger().
|
static |
Initialize the singleton.
Once initialize is called, subsequent calls to getConfig() will return the same pointer as returned by this function.
path | The path to the configuration file. |
Definition at line 62 of file config.cpp.
References Config(), config_, and throw_Exception.
Referenced by dodo::common::Application::Application().
Disallow assignment from another Config, as this is a singleton.
void dodo::common::Config::readConfig | ( | ) |
Read the configuration file.
Definition at line 117 of file config.cpp.
References checkConfig(), path_, throw_Exception, and yaml_.
Referenced by Config().
|
friend |
Application::~Application() will destruct this singleton.
Definition at line 258 of file config.hpp.
|
staticprotected |
The singleton pointer.
Definition at line 238 of file config.hpp.
Referenced by getConfig(), initialize(), and dodo::common::Application::~Application().
|
static |
|
static |
|
static |
The dodo.common.application node.
Definition at line 77 of file config.hpp.
Referenced by checkConfig().
|
static |
The dodo.common.application.name node.
Definition at line 80 of file config.hpp.
Referenced by checkConfig().
|
static |
The dodo.common.application.secret node.
Definition at line 83 of file config.hpp.
Referenced by checkConfig().
|
static |
The dodo.common.application.secret.env node.
Definition at line 89 of file config.hpp.
Referenced by checkConfig().
|
static |
The dodo.common.application.secret.file node.
Definition at line 86 of file config.hpp.
Referenced by checkConfig().
|
static |
|
static |
The dodo.common.logger.console node.
Definition at line 95 of file config.hpp.
Referenced by checkConfig().
|
static |
The dodo.common.logger.console.level node.
Definition at line 98 of file config.hpp.
Referenced by checkConfig(), and dodo::common::Logger::Logger().
|
static |
The dodo.common.logger.file node.
Definition at line 101 of file config.hpp.
Referenced by checkConfig(), and dodo::common::Logger::Logger().
|
static |
The dodo.common.logger.file.directory node.
Definition at line 107 of file config.hpp.
Referenced by checkConfig(), and dodo::common::Logger::getFileParams().
|
static |
The dodo.common.logger.file.level node.
Definition at line 104 of file config.hpp.
Referenced by checkConfig(), and dodo::common::Logger::getFileParams().
|
static |
The dodo.common.logger.file.max-file-trail node.
Definition at line 113 of file config.hpp.
Referenced by dodo::common::Logger::getFileParams().
|
static |
The dodo.common.logger.file.max-size-mib node.
Definition at line 110 of file config.hpp.
Referenced by dodo::common::Logger::getFileParams().
|
static |
The dodo.common.logger.syslog node.
Definition at line 116 of file config.hpp.
Referenced by checkConfig(), and dodo::common::Logger::Logger().
|
static |
The dodo.common.logger.syslog.facility node.
Definition at line 122 of file config.hpp.
Referenced by dodo::common::Logger::Logger().
|
static |
The dodo.common.logger.syslog.level node.
Definition at line 119 of file config.hpp.
Referenced by checkConfig(), and dodo::common::Logger::Logger().
|
staticprotected |
The path to the configuration file.
Definition at line 243 of file config.hpp.
Referenced by checkConfig(), Config(), getConfigPath(), getDecryptedValue(), getValue(), and readConfig().
|
protected |
The encryption secret / key.
Definition at line 253 of file config.hpp.
Referenced by checkConfig(), and getSecret().
|
protected |
The root YAML node.
Definition at line 248 of file config.hpp.
Referenced by exists(), getDecryptedValue(), getValue(), and readConfig().