A bit better module config
This commit is contained in:
parent
647b8f3072
commit
98bfab4ba5
13 changed files with 67 additions and 45 deletions
component
|
@ -69,28 +69,36 @@ bool Config::isValid() const {
|
|||
return !getBareJID().empty() && !getPassword().empty();
|
||||
}
|
||||
|
||||
Config::Module Config::getModuleConfig(const std::string& name) const {
|
||||
std::vector<Config::Module> Config::getModules() const {
|
||||
std::vector<Module> result;
|
||||
|
||||
YAML::Node modules = root["modules"];
|
||||
if (!modules || !modules.IsMap())
|
||||
return { false };
|
||||
if (!modules || !modules.IsSequence())
|
||||
return result;
|
||||
|
||||
YAML::Node conf = modules[name];
|
||||
if (!conf || !conf.IsMap())
|
||||
return { false };
|
||||
for (const YAML::Node& module : modules) {
|
||||
if (!module.IsMap())
|
||||
continue;
|
||||
|
||||
Module result {
|
||||
conf["enabled"].as<bool>(true),
|
||||
conf["alias"].as<std::string>(name)
|
||||
};
|
||||
std::string type = module["type"].as<std::string>();
|
||||
if (type.empty())
|
||||
continue;
|
||||
|
||||
YAML::Node prm = conf["permissions"];
|
||||
if (prm.IsMap()) {
|
||||
for (const auto& node : prm) {
|
||||
Shared::Strings& list = result.permissions.emplace(node.first.as<std::string>(), Shared::Strings()).first->second;
|
||||
YAML::Node lst = node.second;
|
||||
if (lst.IsSequence())
|
||||
for (const YAML::Node& member : lst)
|
||||
list.emplace_back(member.as<std::string>());
|
||||
Module& conf = result.emplace_back(
|
||||
module["enabled"].as<bool>(true),
|
||||
type,
|
||||
module["alias"].as<std::string>(type)
|
||||
);
|
||||
|
||||
YAML::Node prm = module["permissions"];
|
||||
if (prm.IsMap()) {
|
||||
for (const auto& node : prm) {
|
||||
Shared::Strings& list = conf.permissions.emplace(node.first.as<std::string>(), Shared::Strings()).first->second;
|
||||
YAML::Node lst = node.second;
|
||||
if (lst.IsSequence())
|
||||
for (const YAML::Node& member : lst)
|
||||
list.emplace_back(member.as<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
|
@ -20,6 +21,7 @@ class Config {
|
|||
public:
|
||||
struct Module {
|
||||
bool enabled;
|
||||
std::string type;
|
||||
std::string alias;
|
||||
Shared::Permissions permissions;
|
||||
};
|
||||
|
@ -36,7 +38,7 @@ public:
|
|||
std::map<std::string, std::string> getActors() const;
|
||||
Shared::Logger::Level getLogLevel() const;
|
||||
gloox::TLSPolicy getTLSPolicy() const;
|
||||
Module getModuleConfig(const std::string& name) const;
|
||||
std::vector<Module> getModules() const;
|
||||
Shared::Responses getResponses() const;
|
||||
|
||||
void setActors(const std::map<std::string, std::string>& actors);
|
||||
|
|
|
@ -19,8 +19,9 @@ Router::Router(const Shared::Logger& logger):
|
|||
generator(std::random_device{}())
|
||||
{}
|
||||
|
||||
void Router::registerModule(const std::string& key, const std::shared_ptr<Module::Module>& module) {
|
||||
modules[key] = module;
|
||||
void Router::registerModule(const std::shared_ptr<Module::Module>& module) {
|
||||
info("Registering module " + module->name + " as " + module->alias);
|
||||
modules[module->alias] = module;
|
||||
}
|
||||
|
||||
void Router::registerActor(const std::string& key, const std::string& group) {
|
||||
|
|
|
@ -24,7 +24,7 @@ class Router : private Shared::Loggable {
|
|||
public:
|
||||
Router(const Shared::Logger& logger);
|
||||
|
||||
void registerModule(const std::string& key, const std::shared_ptr<Module::Module>& module);
|
||||
void registerModule(const std::shared_ptr<Module::Module>& module);
|
||||
void registerActor(const std::string& key, const std::string& group);
|
||||
void routeMessage(const std::string& sender, const std::string& body);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue