mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-25 20:30:47 +00:00
new(userspace,unit_tests): return loaded config filenames in config::load_from_file.
Add a debug log with the list of loaded config files. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
This commit is contained in:
committed by
poiana
parent
df220e3c3b
commit
aac9b550d3
@@ -94,9 +94,10 @@ void falco_configuration::init(const std::vector<std::string>& cmdline_options)
|
||||
void falco_configuration::init(const std::string& conf_filename, const std::vector<std::string> &cmdline_options)
|
||||
{
|
||||
yaml_helper config;
|
||||
std::vector<std::string> loaded_files;
|
||||
try
|
||||
{
|
||||
config.load_from_file(conf_filename);
|
||||
config.load_from_file(conf_filename, loaded_files);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
@@ -106,6 +107,13 @@ void falco_configuration::init(const std::string& conf_filename, const std::vect
|
||||
|
||||
init_cmdline_options(config, cmdline_options);
|
||||
load_yaml(conf_filename, config);
|
||||
|
||||
// Here we have already set up correct logging level
|
||||
falco_logger::log(falco_logger::level::DEBUG, "Loaded config filenames:\n");
|
||||
for (const auto& path : loaded_files)
|
||||
{
|
||||
falco_logger::log(falco_logger::level::DEBUG, std::string(" ") + path + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void falco_configuration::load_engine_config(const std::string& config_name, const yaml_helper& config)
|
||||
|
@@ -92,9 +92,10 @@ public:
|
||||
/**
|
||||
* Load the YAML document from the given file path.
|
||||
*/
|
||||
void load_from_file(const std::string& path)
|
||||
void load_from_file(const std::string& path, std::vector<std::string>& loaded_config_files)
|
||||
{
|
||||
m_root = load_from_file_int(path);
|
||||
loaded_config_files.clear();
|
||||
m_root = load_from_file_int(path, loaded_config_files);
|
||||
|
||||
const auto ppath = std::filesystem::path(path);
|
||||
const auto config_folder = ppath.parent_path();
|
||||
@@ -120,7 +121,7 @@ public:
|
||||
{
|
||||
if (std::filesystem::is_regular_file(include_file_path))
|
||||
{
|
||||
include_config_file(include_file_path.string());
|
||||
include_config_file(include_file_path.string(), loaded_config_files);
|
||||
}
|
||||
else if (std::filesystem::is_directory(include_file_path))
|
||||
{
|
||||
@@ -138,11 +139,11 @@ public:
|
||||
{
|
||||
falco_logger::log(falco_logger::level::WARNING, "Included config file has wrong type: " + dir_entry.path().string());
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
for (const auto &f : v)
|
||||
{
|
||||
include_config_file(f);
|
||||
}
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
for (const auto &f : v)
|
||||
{
|
||||
include_config_file(f, loaded_config_files);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -215,16 +216,17 @@ public:
|
||||
private:
|
||||
YAML::Node m_root;
|
||||
|
||||
YAML::Node load_from_file_int(const std::string& path)
|
||||
YAML::Node load_from_file_int(const std::string& path, std::vector<std::string>& loaded_config_files)
|
||||
{
|
||||
auto root = YAML::LoadFile(path);
|
||||
pre_process_env_vars(root);
|
||||
loaded_config_files.push_back(path);
|
||||
return root;
|
||||
}
|
||||
|
||||
void include_config_file(const std::string& include_file_path)
|
||||
void include_config_file(const std::string& include_file_path, std::vector<std::string>& loaded_config_files)
|
||||
{
|
||||
auto loaded_nodes = load_from_file_int(include_file_path);
|
||||
auto loaded_nodes = load_from_file_int(include_file_path, loaded_config_files);
|
||||
for(auto n : loaded_nodes)
|
||||
{
|
||||
/*
|
||||
|
Reference in New Issue
Block a user