Leosac  0.7.0
OpenSourceAccessControl
RemoteConfigCollector.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <boost/property_tree/ptree.hpp>
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 #include <zmqpp/zmqpp.hpp>
28 
29 namespace Leosac
30 {
52 {
53  public:
65  RemoteConfigCollector(zmqpp::context_t &ctx, const std::string &remote_endpoint,
66  const std::string &remote_pk);
67  virtual ~RemoteConfigCollector() = default;
68 
73 
74  using ModuleConfigMap = std::map<std::string, boost::property_tree::ptree>;
75 
76  using FileNameContentList = std::list<std::pair<std::string, std::string>>;
80  using ModuleAdditionalFiles = std::map<std::string, FileNameContentList>;
81 
92  bool fetch_config(std::string *error_str) noexcept;
93 
98  const std::list<std::string> &modules_list() const noexcept;
99 
103  const ModuleConfigMap &modules_config() const noexcept;
104 
108  const boost::property_tree::ptree &module_config(const std::string &name) const;
109 
113  const boost::property_tree::ptree &general_config() const;
114 
115  const FileNameContentList &additional_files(const std::string module) const;
116 
117  uint64_t remote_version() const;
118 
119  private:
123  bool fetch_general_config();
124 
128  bool fetch_module_list();
129 
133  bool fetch_module_config(const std::string &module_name);
134 
138  bool fetch_modules_config();
139 
144  bool fetch_remote_config_version(uint64_t &version);
145 
147  std::string remote_pk_;
148 
152  zmqpp::poller_t poller_;
153  zmqpp::socket_t sock_;
154 
156 
157  uint64_t remote_version_;
158 
164  boost::property_tree::ptree general_config_;
165  std::list<std::string> module_list_;
167 
168  // those 2 boolean are here to enforce the correct use of the object.
169  // Call fetch_config() then access various config item.
170 
172  bool succeed_;
173 };
174 }
ModuleConfigMap config_map_
Map module name to their config tree.
virtual ~RemoteConfigCollector()=default
const boost::property_tree::ptree & module_config(const std::string &name) const
Returns the configuration for one specific module, identified by name.
This is the header file for a generated source file, GitSHA1.cpp.
std::list< std::string > module_list_
bool fetch_modules_config()
Fetch the conf for all modules (relying on fetch_module_config()).
STL namespace.
bool fetch_general_config()
Send the GENERAL_CONFIG command to the remote, and wait for response.
bool fetch_remote_config_version(uint64_t &version)
Fetch the version of the remote configuration.
const std::list< std::string > & modules_list() const noexcept
Return the list of modules that are loaded on the remote host.
boost::property_tree::ptree general_config_
bool fetch_module_list()
Sends the MODULE_LIST command.
RemoteConfigCollector & operator=(const RemoteConfigCollector &)=delete
std::list< std::pair< std::string, std::string > > FileNameContentList
const boost::property_tree::ptree & general_config() const
Returns the tree for the general configuration option.
bool fetch_config(std::string *error_str) noexcept
Fetch the complete remote configuration.
std::map< std::string, FileNameContentList > ModuleAdditionalFiles
Map module name to a list of (file_name, file_content)
bool fetch_module_config(const std::string &module_name)
Sends the MODULE_CONFIG command for the module whose name is module_name.
std::map< std::string, boost::property_tree::ptree > ModuleConfigMap
const FileNameContentList & additional_files(const std::string module) const
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...
This class provides an API to collect the configuration of a remote Leosac unit.
const ModuleConfigMap & modules_config() const noexcept
Returns a reference to modules and their configuration.
zmqpp::poller_t poller_
Poll on the socket.