Leosac
0.8.0
Open Source Access Control
|
This class provides an API to collect the configuration of a remote Leosac unit. More...
#include <RemoteConfigCollector.hpp>
Public Types | |
using | ModuleConfigMap = std::map< std::string, boost::property_tree::ptree > |
using | FileNameContentList = std::list< std::pair< std::string, std::string > > |
using | ModuleAdditionalFiles = std::map< std::string, FileNameContentList > |
Map module name to a list of (file_name, file_content) More... | |
Public Member Functions | |
RemoteConfigCollector (zmqpp::context_t &ctx, const std::string &remote_endpoint, const std::string &remote_pk) | |
Construct a new RemoteConfigCollector, this object will work for a one-time config collection. More... | |
virtual | ~RemoteConfigCollector ()=default |
RemoteConfigCollector (const RemoteConfigCollector &)=delete | |
RemoteConfigCollector (RemoteConfigCollector &&)=delete | |
RemoteConfigCollector & | operator= (const RemoteConfigCollector &)=delete |
RemoteConfigCollector & | operator= (RemoteConfigCollector &&)=delete |
bool | fetch_config (std::string *error_str) noexcept |
Fetch the complete remote configuration. More... | |
const std::list< std::string > & | modules_list () const noexcept |
Return the list of modules that are loaded on the remote host. More... | |
const ModuleConfigMap & | modules_config () const noexcept |
Returns a reference to modules and their configuration. More... | |
const boost::property_tree::ptree & | module_config (const std::string &name) const |
Returns the configuration for one specific module, identified by name. More... | |
const boost::property_tree::ptree & | general_config () const |
Returns the tree for the general configuration option. More... | |
const FileNameContentList & | additional_files (const std::string module) const |
uint64_t | remote_version () const |
Private Member Functions | |
bool | fetch_general_config () |
Send the GENERAL_CONFIG command to the remote, and wait for response. More... | |
bool | fetch_module_list () |
Sends the MODULE_LIST command. More... | |
bool | fetch_module_config (const std::string &module_name) |
Sends the MODULE_CONFIG command for the module whose name is module_name . More... | |
bool | fetch_modules_config () |
Fetch the conf for all modules (relying on fetch_module_config()). More... | |
bool | fetch_remote_config_version (uint64_t &version) |
Fetch the version of the remote configuration. More... | |
Private Attributes | |
std::string | remote_endpoint_ |
std::string | remote_pk_ |
zmqpp::poller_t | poller_ |
Poll on the socket. More... | |
zmqpp::socket_t | sock_ |
long | mstimeout_ |
uint64_t | remote_version_ |
ModuleConfigMap | config_map_ |
Map module name to their config tree. More... | |
boost::property_tree::ptree | general_config_ |
std::list< std::string > | module_list_ |
ModuleAdditionalFiles | additional_files_ |
bool | first_call_ |
bool | succeed_ |
This class provides an API to collect the configuration of a remote Leosac unit.
This class is wrapped by the Tasks::FetchRemoteConfig object. The implementation is a BLOCKING collection (with timeout), which is why one should use the Task object that wraps the collection.
Fetching the remote configuration requires multiple messages: 1 for the global configuration, and one per modules, at least. There is no "remote locking", which means that it is possible for the remote configuration to change while we are fetching it.
Fortunately, there is a global version
field that represents the version of the whole configuration. This number can only increase. What we do is similar to Optimistic Concurrency Control: we fetch the configuration version once before retrieving the configuration, then we fetch it again when we are done. If the number is the same, it means that the configuration didn't change.
Definition at line 51 of file RemoteConfigCollector.hpp.
using Leosac::RemoteConfigCollector::FileNameContentList = std::list<std::pair<std::string, std::string> > |
Definition at line 76 of file RemoteConfigCollector.hpp.
using Leosac::RemoteConfigCollector::ModuleAdditionalFiles = std::map<std::string, FileNameContentList> |
Map module name to a list of (file_name, file_content)
Definition at line 80 of file RemoteConfigCollector.hpp.
using Leosac::RemoteConfigCollector::ModuleConfigMap = std::map<std::string, boost::property_tree::ptree> |
Definition at line 74 of file RemoteConfigCollector.hpp.
RemoteConfigCollector::RemoteConfigCollector | ( | zmqpp::context_t & | ctx, |
const std::string & | remote_endpoint, | ||
const std::string & | remote_pk | ||
) |
Construct a new RemoteConfigCollector, this object will work for a one-time config collection.
ctx | the zeromq context to create a socket. |
remote_endpoint | the endpoint (tcp://ip:port) of the unit we want to collect config. |
remote_pk | the public key of the remote. Provide some security, and avoid connecting to a unwanted server. |
Definition at line 33 of file RemoteConfigCollector.cpp.
|
virtualdefault |
|
delete |
|
delete |
const RemoteConfigCollector::FileNameContentList & RemoteConfigCollector::additional_files | ( | const std::string | module | ) | const |
Definition at line 246 of file RemoteConfigCollector.cpp.
|
noexcept |
Fetch the complete remote configuration.
If this call returns true, the various parts of the configuration are available to you through this class' public methods.
This function does not throw.
If this function fails, and error_str is not nullptr, we store the reason of the failure here.
Definition at line 60 of file RemoteConfigCollector.cpp.
|
private |
Send the GENERAL_CONFIG command to the remote, and wait for response.
Definition at line 111 of file RemoteConfigCollector.cpp.
|
private |
Sends the MODULE_CONFIG command for the module whose name is module_name
.
Definition at line 156 of file RemoteConfigCollector.cpp.
|
private |
Sends the MODULE_LIST command.
Definition at line 135 of file RemoteConfigCollector.cpp.
|
private |
Fetch the conf for all modules (relying on fetch_module_config()).
Definition at line 205 of file RemoteConfigCollector.cpp.
|
private |
Fetch the version of the remote configuration.
version | store the version into the reference. |
Definition at line 254 of file RemoteConfigCollector.cpp.
const boost::property_tree::ptree & RemoteConfigCollector::general_config | ( | ) | const |
Returns the tree for the general configuration option.
Definition at line 240 of file RemoteConfigCollector.cpp.
const boost::property_tree::ptree & RemoteConfigCollector::module_config | ( | const std::string & | name | ) | const |
Returns the configuration for one specific module, identified by name.
Definition at line 229 of file RemoteConfigCollector.cpp.
|
noexcept |
Returns a reference to modules and their configuration.
Definition at line 222 of file RemoteConfigCollector.cpp.
|
noexcept |
Return the list of modules that are loaded on the remote host.
Make sure that fetch_config() was called and succeed first.
Definition at line 215 of file RemoteConfigCollector.cpp.
|
delete |
|
delete |
uint64_t RemoteConfigCollector::remote_version | ( | ) | const |
Definition at line 267 of file RemoteConfigCollector.cpp.
|
private |
Definition at line 166 of file RemoteConfigCollector.hpp.
|
private |
Map module name to their config tree.
The maps start empty and is filled by fetch_module_config();
Definition at line 163 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 171 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 164 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 165 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 155 of file RemoteConfigCollector.hpp.
|
private |
Poll on the socket.
Definition at line 152 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 146 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 147 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 157 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 153 of file RemoteConfigCollector.hpp.
|
private |
Definition at line 172 of file RemoteConfigCollector.hpp.