Leosac  0.8.0
Open Source Access Control
Leosac::RemoteConfigCollector Class Reference

This class provides an API to collect the configuration of a remote Leosac unit. More...

#include <RemoteConfigCollector.hpp>

+ Collaboration diagram for Leosac::RemoteConfigCollector:

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
 
RemoteConfigCollectoroperator= (const RemoteConfigCollector &)=delete
 
RemoteConfigCollectoroperator= (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 ModuleConfigMapmodules_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 FileNameContentListadditional_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_
 

Detailed Description

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.

Consistency concerns (and solutions):

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.

Member Typedef Documentation

◆ FileNameContentList

using Leosac::RemoteConfigCollector::FileNameContentList = std::list<std::pair<std::string, std::string> >

Definition at line 76 of file RemoteConfigCollector.hpp.

◆ ModuleAdditionalFiles

Map module name to a list of (file_name, file_content)

Definition at line 80 of file RemoteConfigCollector.hpp.

◆ ModuleConfigMap

using Leosac::RemoteConfigCollector::ModuleConfigMap = std::map<std::string, boost::property_tree::ptree>

Definition at line 74 of file RemoteConfigCollector.hpp.

Constructor & Destructor Documentation

◆ RemoteConfigCollector() [1/3]

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.

Parameters
ctxthe zeromq context to create a socket.
remote_endpointthe endpoint (tcp://ip:port) of the unit we want to collect config.
remote_pkthe public key of the remote. Provide some security, and avoid connecting to a unwanted server.

Definition at line 33 of file RemoteConfigCollector.cpp.

◆ ~RemoteConfigCollector()

virtual Leosac::RemoteConfigCollector::~RemoteConfigCollector ( )
virtualdefault

◆ RemoteConfigCollector() [2/3]

Leosac::RemoteConfigCollector::RemoteConfigCollector ( const RemoteConfigCollector )
delete

◆ RemoteConfigCollector() [3/3]

Leosac::RemoteConfigCollector::RemoteConfigCollector ( RemoteConfigCollector &&  )
delete

Member Function Documentation

◆ additional_files()

const RemoteConfigCollector::FileNameContentList & RemoteConfigCollector::additional_files ( const std::string  module) const

Definition at line 246 of file RemoteConfigCollector.cpp.

◆ fetch_config()

bool RemoteConfigCollector::fetch_config ( std::string *  error_str)
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.

◆ fetch_general_config()

bool RemoteConfigCollector::fetch_general_config ( )
private

Send the GENERAL_CONFIG command to the remote, and wait for response.

Definition at line 111 of file RemoteConfigCollector.cpp.

◆ fetch_module_config()

bool RemoteConfigCollector::fetch_module_config ( const std::string &  module_name)
private

Sends the MODULE_CONFIG command for the module whose name is module_name.

Definition at line 156 of file RemoteConfigCollector.cpp.

◆ fetch_module_list()

bool RemoteConfigCollector::fetch_module_list ( )
private

Sends the MODULE_LIST command.

Definition at line 135 of file RemoteConfigCollector.cpp.

◆ fetch_modules_config()

bool RemoteConfigCollector::fetch_modules_config ( )
private

Fetch the conf for all modules (relying on fetch_module_config()).

Definition at line 205 of file RemoteConfigCollector.cpp.

◆ fetch_remote_config_version()

bool RemoteConfigCollector::fetch_remote_config_version ( uint64_t &  version)
private

Fetch the version of the remote configuration.

Parameters
versionstore the version into the reference.

Definition at line 254 of file RemoteConfigCollector.cpp.

◆ general_config()

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.

◆ module_config()

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.

◆ modules_config()

const RemoteConfigCollector::ModuleConfigMap & RemoteConfigCollector::modules_config ( ) const
noexcept

Returns a reference to modules and their configuration.

Definition at line 222 of file RemoteConfigCollector.cpp.

◆ modules_list()

const std::list< std::string > & RemoteConfigCollector::modules_list ( ) const
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.

◆ operator=() [1/2]

RemoteConfigCollector& Leosac::RemoteConfigCollector::operator= ( const RemoteConfigCollector )
delete

◆ operator=() [2/2]

RemoteConfigCollector& Leosac::RemoteConfigCollector::operator= ( RemoteConfigCollector &&  )
delete

◆ remote_version()

uint64_t RemoteConfigCollector::remote_version ( ) const

Definition at line 267 of file RemoteConfigCollector.cpp.

Member Data Documentation

◆ additional_files_

ModuleAdditionalFiles Leosac::RemoteConfigCollector::additional_files_
private

Definition at line 166 of file RemoteConfigCollector.hpp.

◆ config_map_

ModuleConfigMap Leosac::RemoteConfigCollector::config_map_
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.

◆ first_call_

bool Leosac::RemoteConfigCollector::first_call_
private

Definition at line 171 of file RemoteConfigCollector.hpp.

◆ general_config_

boost::property_tree::ptree Leosac::RemoteConfigCollector::general_config_
private

Definition at line 164 of file RemoteConfigCollector.hpp.

◆ module_list_

std::list<std::string> Leosac::RemoteConfigCollector::module_list_
private

Definition at line 165 of file RemoteConfigCollector.hpp.

◆ mstimeout_

long Leosac::RemoteConfigCollector::mstimeout_
private

Definition at line 155 of file RemoteConfigCollector.hpp.

◆ poller_

zmqpp::poller_t Leosac::RemoteConfigCollector::poller_
private

Poll on the socket.

Definition at line 152 of file RemoteConfigCollector.hpp.

◆ remote_endpoint_

std::string Leosac::RemoteConfigCollector::remote_endpoint_
private

Definition at line 146 of file RemoteConfigCollector.hpp.

◆ remote_pk_

std::string Leosac::RemoteConfigCollector::remote_pk_
private

Definition at line 147 of file RemoteConfigCollector.hpp.

◆ remote_version_

uint64_t Leosac::RemoteConfigCollector::remote_version_
private

Definition at line 157 of file RemoteConfigCollector.hpp.

◆ sock_

zmqpp::socket_t Leosac::RemoteConfigCollector::sock_
private

Definition at line 153 of file RemoteConfigCollector.hpp.

◆ succeed_

bool Leosac::RemoteConfigCollector::succeed_
private

Definition at line 172 of file RemoteConfigCollector.hpp.


The documentation for this class was generated from the following files: