mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-24 19:38:52 +00:00
refactor(engine): support string config loading and add ad-hoc methods
This is a change of direction from the current design, that imposes loading the configuration from file only, and in the object constructor. Instead, yaml_configuration objects can now be reused ad can load the YAML config from either file or string. This also makes it easier to unit test this class. Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
@@ -54,7 +54,16 @@ falco_configuration::~falco_configuration()
|
||||
void falco_configuration::init(string conf_filename, list<string> &cmdline_options)
|
||||
{
|
||||
string m_config_file = conf_filename;
|
||||
m_config = new yaml_configuration(m_config_file);
|
||||
m_config = new yaml_configuration();
|
||||
try
|
||||
{
|
||||
m_config->load_from_file(m_config_file);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << "Cannot read config file (" + m_config_file + "): " + e.what() + "\n";
|
||||
throw e;
|
||||
}
|
||||
|
||||
init_cmdline_options(cmdline_options);
|
||||
|
||||
|
@@ -35,26 +35,28 @@ limitations under the License.
|
||||
class yaml_configuration
|
||||
{
|
||||
public:
|
||||
std::string m_path;
|
||||
yaml_configuration(const std::string& path)
|
||||
/**
|
||||
* Load the YAML document represented by the input string.
|
||||
*/
|
||||
void load_from_string(const std::string& input)
|
||||
{
|
||||
m_path = path;
|
||||
YAML::Node config;
|
||||
std::vector<falco::outputs::config> outputs;
|
||||
try
|
||||
{
|
||||
m_root = YAML::LoadFile(path);
|
||||
}
|
||||
catch(const YAML::BadFile& ex)
|
||||
{
|
||||
std::cerr << "Error reading config file (" + path + "): " + ex.what() + "\n";
|
||||
throw;
|
||||
}
|
||||
catch(const YAML::ParserException& ex)
|
||||
{
|
||||
std::cerr << "Cannot read config file (" + path + "): " + ex.what() + "\n";
|
||||
throw;
|
||||
}
|
||||
m_root = YAML::Load(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the YAML document from the given file path.
|
||||
*/
|
||||
void load_from_file(const std::string& path)
|
||||
{
|
||||
m_root = YAML::LoadFile(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the internal loaded document.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
m_root = YAML::Node();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user