1 #include "libaktualizr/config.h"
3 #include "logging/logging.h"
4 #include "utilities/config_utils.h"
5 #include "utilities/utils.h"
7 void BaseConfig::updateFromToml(
const boost::filesystem::path& filename) {
8 LOG_INFO <<
"Reading config: " << filename;
9 if (!boost::filesystem::exists(filename)) {
10 throw std::runtime_error(
"Config file " + filename.string() +
" does not exist.");
12 boost::property_tree::ptree pt;
13 boost::property_tree::ini_parser::read_ini(filename.string(), pt);
14 updateFromPropertyTree(pt);
17 void BaseConfig::updateFromDirs(
const std::vector<boost::filesystem::path>& configs) {
18 std::map<std::string, boost::filesystem::path> configs_map;
19 for (
const auto& config : configs) {
20 if (!boost::filesystem::exists(config)) {
23 if (boost::filesystem::is_directory(config)) {
24 for (
const auto& config_file : Utils::getDirEntriesByExt(config,
".toml")) {
25 configs_map[config_file.filename().string()] = config_file;
28 configs_map[config.filename().string()] = config;
31 for (
const auto& config_file : configs_map) {
32 updateFromToml(config_file.second);
36 void P11Config::updateFromPropertyTree(
const boost::property_tree::ptree& pt) {
37 CopyFromConfig(module,
"module", pt);
38 CopyFromConfig(pass,
"pass", pt);
39 CopyFromConfig(uptane_key_id,
"uptane_key_id", pt);
40 CopyFromConfig(tls_cacert_id,
"tls_cacert_id", pt);
41 CopyFromConfig(tls_pkey_id,
"tls_pkey_id", pt);
42 CopyFromConfig(tls_clientcert_id,
"tls_clientcert_id", pt);
45 void P11Config::writeToStream(std::ostream& out_stream)
const {
46 writeOption(out_stream, module,
"module");
47 writeOption(out_stream, pass,
"pass");
48 writeOption(out_stream, uptane_key_id,
"uptane_key_id");
49 writeOption(out_stream, tls_cacert_id,
"tls_ca_id");
50 writeOption(out_stream, tls_pkey_id,
"tls_pkey_id");
51 writeOption(out_stream, tls_clientcert_id,
"tls_clientcert_id");