diff --git a/userspace/falco/configuration.cpp b/userspace/falco/configuration.cpp index 25e1d226..1231b3ba 100644 --- a/userspace/falco/configuration.cpp +++ b/userspace/falco/configuration.cpp @@ -54,7 +54,16 @@ falco_configuration::~falco_configuration() void falco_configuration::init(string conf_filename, list &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); diff --git a/userspace/falco/configuration.h b/userspace/falco/configuration.h index 5be2b955..211a5d62 100644 --- a/userspace/falco/configuration.h +++ b/userspace/falco/configuration.h @@ -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 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(); } /**