Leosac  0.8.0
Open Source Access Control
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 
146  std::string remote_endpoint_;
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 }
Leosac::RemoteConfigCollector::remote_version
uint64_t remote_version() const
Definition: RemoteConfigCollector.cpp:267
Leosac::RemoteConfigCollector::sock_
zmqpp::socket_t sock_
Definition: RemoteConfigCollector.hpp:153
Leosac::RemoteConfigCollector
This class provides an API to collect the configuration of a remote Leosac unit.
Definition: RemoteConfigCollector.hpp:51
zmqpp
Definition: CoreUtils.hpp:27
Leosac::RemoteConfigCollector::operator=
RemoteConfigCollector & operator=(const RemoteConfigCollector &)=delete
Leosac::RemoteConfigCollector::module_config
const boost::property_tree::ptree & module_config(const std::string &name) const
Returns the configuration for one specific module, identified by name.
Definition: RemoteConfigCollector.cpp:229
Leosac::RemoteConfigCollector::fetch_remote_config_version
bool fetch_remote_config_version(uint64_t &version)
Fetch the version of the remote configuration.
Definition: RemoteConfigCollector.cpp:254
Leosac::RemoteConfigCollector::poller_
zmqpp::poller_t poller_
Poll on the socket.
Definition: RemoteConfigCollector.hpp:152
Leosac::RemoteConfigCollector::fetch_module_config
bool fetch_module_config(const std::string &module_name)
Sends the MODULE_CONFIG command for the module whose name is module_name.
Definition: RemoteConfigCollector.cpp:156
Leosac::RemoteConfigCollector::general_config_
boost::property_tree::ptree general_config_
Definition: RemoteConfigCollector.hpp:164
Leosac::RemoteConfigCollector::fetch_module_list
bool fetch_module_list()
Sends the MODULE_LIST command.
Definition: RemoteConfigCollector.cpp:135
Leosac::RemoteConfigCollector::fetch_modules_config
bool fetch_modules_config()
Fetch the conf for all modules (relying on fetch_module_config()).
Definition: RemoteConfigCollector.cpp:205
Leosac::RemoteConfigCollector::fetch_general_config
bool fetch_general_config()
Send the GENERAL_CONFIG command to the remote, and wait for response.
Definition: RemoteConfigCollector.cpp:111
Leosac::RemoteConfigCollector::additional_files_
ModuleAdditionalFiles additional_files_
Definition: RemoteConfigCollector.hpp:166
Leosac::RemoteConfigCollector::general_config
const boost::property_tree::ptree & general_config() const
Returns the tree for the general configuration option.
Definition: RemoteConfigCollector.cpp:240
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::RemoteConfigCollector::ModuleAdditionalFiles
std::map< std::string, FileNameContentList > ModuleAdditionalFiles
Map module name to a list of (file_name, file_content)
Definition: RemoteConfigCollector.hpp:80
Leosac::RemoteConfigCollector::remote_pk_
std::string remote_pk_
Definition: RemoteConfigCollector.hpp:147
Leosac::RemoteConfigCollector::FileNameContentList
std::list< std::pair< std::string, std::string > > FileNameContentList
Definition: RemoteConfigCollector.hpp:76
Leosac::RemoteConfigCollector::fetch_config
bool fetch_config(std::string *error_str) noexcept
Fetch the complete remote configuration.
Definition: RemoteConfigCollector.cpp:60
Leosac::RemoteConfigCollector::modules_list
const std::list< std::string > & modules_list() const noexcept
Return the list of modules that are loaded on the remote host.
Definition: RemoteConfigCollector.cpp:215
Leosac::RemoteConfigCollector::first_call_
bool first_call_
Definition: RemoteConfigCollector.hpp:171
Leosac::RemoteConfigCollector::ModuleConfigMap
std::map< std::string, boost::property_tree::ptree > ModuleConfigMap
Definition: RemoteConfigCollector.hpp:74
Leosac::RemoteConfigCollector::mstimeout_
long mstimeout_
Definition: RemoteConfigCollector.hpp:155
Leosac::RemoteConfigCollector::remote_endpoint_
std::string remote_endpoint_
Definition: RemoteConfigCollector.hpp:146
Leosac::RemoteConfigCollector::config_map_
ModuleConfigMap config_map_
Map module name to their config tree.
Definition: RemoteConfigCollector.hpp:163
Leosac::RemoteConfigCollector::~RemoteConfigCollector
virtual ~RemoteConfigCollector()=default
Leosac::RemoteConfigCollector::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.
Definition: RemoteConfigCollector.cpp:33
Leosac::RemoteConfigCollector::additional_files
const FileNameContentList & additional_files(const std::string module) const
Definition: RemoteConfigCollector.cpp:246
list
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) set(LEOSAC_BIN leosac) set(LEOSAC_LIB leosac_lib) set(LEOSAC_SRCS main.cpp) set(LEOSAC_LIB_SRCS core/kernel.cpp core/CoreAPI.cpp core/config/ConfigManager.cpp core/config/RemoteConfigCollector.cpp core/config/ConfigChecker.cpp core/CoreUtils.cpp core/RemoteControl.cpp core/RemoteControlSecurity.cpp core/module_manager.cpp core/MessageBus.cpp core/Scheduler.cpp core/tasks/Task.cpp core/tasks/GenericTask.cpp core/netconfig/networkconfig.cpp core/auth/Auth.cpp core/auth/Group.cpp core/auth/ProfileMerger.cpp core/auth/SimpleAccessProfile.cpp core/auth/BaseAuthSource.cpp core/auth/AuthTarget.cpp core/auth/User.cpp core/auth/serializers/UserSerializer.cpp core/auth/serializers/GroupSerializer.cpp core/auth/serializers/UserGroupMembershipSerializer.cpp core/auth/serializers/DoorSerializer.cpp core/auth/serializers/AccessPointSerializer.cpp core/auth/serializers/ZoneSerializer.cpp core/auth/Token.cpp core/auth/UserGroupMembership.cpp core/auth/AuthSourceBuilder.cpp core/auth/ValidityInfo.cpp core/auth/Door.cpp core/auth/AccessPoint.cpp core/auth/AccessPointUpdate.cpp core/auth/AccessPointService.cpp core/auth/Zone.cpp core/credentials/Credential.cpp core/credentials/CredentialValidator.cpp core/credentials/RFIDCard.cpp core/credentials/PinCode.cpp core/credentials/RFIDCardPin.cpp core/credentials/serializers/CredentialSerializer.cpp core/credentials/serializers/RFIDCardSerializer.cpp core/credentials/serializers/PolymorphicCredentialSerializer.cpp core/credentials/serializers/PinCodeSerializer.cpp core/UserSecurityContext.cpp core/GetServiceRegistry.cpp dynlib/dynamiclibrary.cpp modules/AsioModule.cpp modules/BaseModule.cpp exception/ExceptionsTools.cpp exception/ModelException.cpp exception/EntityNotFound.cpp exception/PermissionDenied.cpp hardware/facades/FGPIO.cpp hardware/facades/FLED.cpp hardware/facades/FWiegandReader.cpp hardware/facades/FExternalServer.cpp hardware/Device.cpp hardware/GPIO.cpp hardware/RFIDReader.cpp hardware/Buzzer.cpp hardware/LED.cpp hardware/ExternalMessage.cpp hardware/ExternalServer.cpp hardware/HardwareService.cpp hardware/serializers/RFIDReaderSerializer.cpp hardware/serializers/GPIOSerializer.cpp hardware/serializers/DeviceSerializer.cpp hardware/serializers/LEDSerializer.cpp hardware/serializers/BuzzerSerializer.cpp hardware/serializers/ExternalMessageSerializer.cpp hardware/serializers/ExternalServerSerializer.cpp tools/runtimeoptions.cpp tools/signalhandler.cpp tools/unixshellscript.cpp tools/unixsyscall.cpp tools/unixfilewatcher.cpp tools/unixfs.cpp tools/version.cpp tools/Schedule.cpp tools/XmlPropertyTree.cpp tools/XmlScheduleLoader.cpp tools/ThreadUtils.cpp tools/GenGuid.cpp tools/PropertyTreeExtractor.cpp tools/log.cpp tools/DatabaseLogSink.cpp tools/ElapsedTimeCounter.cpp tools/XmlNodeNameEnforcer.cpp tools/Stacktrace.cpp tools/LogEntry.cpp tools/db/DBService.cpp tools/db/MultiplexedSession.cpp tools/db/MultiplexedTransaction.cpp tools/db/OptionalTransaction.cpp tools/db/Savepoint.cpp tools/scrypt/Random.cpp tools/scrypt/Scrypt.cpp tools/registry/ThreadLocalRegistry.cpp tools/registry/GlobalRegistry.cpp tools/JSONUtils.cpp tools/MyTime.cpp tools/SingleTimeFrame.cpp tools/serializers/ScheduleSerializer.cpp tools/serializers/ScheduleMappingSerializer.cpp tools/ScheduleMapping.cpp core/tasks/GetLocalConfigVersion.cpp core/tasks/GetRemoteConfigVersion.cpp core/tasks/FetchRemoteConfig.cpp core/tasks/SyncConfig.cpp core/tasks/RemoteControlAsyncResponse.cpp core/audit/AuditEntry.cpp core/audit/UserEvent.cpp core/audit/WSAPICall.cpp core/audit/AuditFactory.cpp core/audit/GroupEvent.cpp core/audit/UserGroupMembershipEvent.cpp core/audit/CredentialEvent.cpp core/audit/ScheduleEvent.cpp core/audit/DoorEvent.cpp core/audit/UpdateEvent.cpp core/audit/AccessPointEvent.cpp core/audit/AuditTracker.cpp core/audit/ZoneEvent.cpp core/audit/serializers/AuditSerializer.cpp core/audit/serializers/UserEventSerializer.cpp core/audit/serializers/PolymorphicAuditSerializer.cpp core/audit/serializers/WSAPICallSerializer.cpp core/audit/serializers/CredentialEventSerializer.cpp core/audit/serializers/GroupEventSerializer.cpp core/audit/serializers/ScheduleEventSerializer.cpp core/audit/serializers/DoorEventSerializer.cpp core/audit/serializers/UserGroupMembershipEventSerializer.cpp core/audit/serializers/AccessPointEventSerializer.cpp core/audit/serializers/ZoneEventSerializer.cpp core/update/UpdateService.cpp core/update/Update.cpp core/update/serializers/AccessPointUpdateSerializer.cpp core/update/serializers/UpdateSerializer.cpp core/update/serializers/UpdateDescriptorSerializer.cpp tools/db/PGSQLTracer.cpp tools/Visitor.cpp core/SecurityContext.cpp core/audit/serializers/UpdateEventSerializer.cpp hardware/serializers/BuzzerSerializer.cpp hardware/serializers/BuzzerSerializer.hpp) include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC GIT_SHA1) configure_file("$
Definition: CMakeLists.txt:1
Leosac::RemoteConfigCollector::succeed_
bool succeed_
Definition: RemoteConfigCollector.hpp:172
Leosac::RemoteConfigCollector::remote_version_
uint64_t remote_version_
Definition: RemoteConfigCollector.hpp:157
Leosac::RemoteConfigCollector::module_list_
std::list< std::string > module_list_
Definition: RemoteConfigCollector.hpp:165
Leosac::RemoteConfigCollector::modules_config
const ModuleConfigMap & modules_config() const noexcept
Returns a reference to modules and their configuration.
Definition: RemoteConfigCollector.cpp:222