From 1deafee5f733e07165f5e40ce72c6b880a8ad749 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Thu, 8 Feb 2024 16:59:25 +0100 Subject: [PATCH] chore(userspace/falco): print a warn message if `-o includes=` is passed to cmdline. Signed-off-by: Federico Di Pierro --- userspace/falco/configuration.cpp | 9 ++++++++- userspace/falco/yaml_helper.h | 12 ++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/userspace/falco/configuration.cpp b/userspace/falco/configuration.cpp index 6f0d4635..9fd5a74a 100644 --- a/userspace/falco/configuration.cpp +++ b/userspace/falco/configuration.cpp @@ -605,5 +605,12 @@ void falco_configuration::set_cmdline_option(yaml_helper& config, const std::str throw std::logic_error("Error parsing config option \"" + opt + "\". Must be of the form key=val or key.subkey=val"); } - config.set_scalar(keyval.first, keyval.second); + if (keyval.first.rfind(yaml_helper::includes_key, 0) == 0) + { + falco_logger::log(falco_logger::level::WARNING, "Ignoring '-o " + yaml_helper::includes_key + "' directive: cannot be overridden by cmdline.\n"); + } + else + { + config.set_scalar(keyval.first, keyval.second); + } } diff --git a/userspace/falco/yaml_helper.h b/userspace/falco/yaml_helper.h index ccddf410..f0a75516 100644 --- a/userspace/falco/yaml_helper.h +++ b/userspace/falco/yaml_helper.h @@ -78,6 +78,8 @@ private: class yaml_helper { public: + inline static const std::string includes_key = "includes"; + /** * Load the YAML document represented by the input string. */ @@ -98,7 +100,7 @@ public: const auto config_folder = ppath.parent_path(); // Parse files to be included std::vector include_files; - get_sequence>(include_files, "includes"); + get_sequence>(include_files, includes_key); for(const std::string& include_file : include_files) { // If user specifies a relative include file, @@ -111,7 +113,8 @@ public: } if (include_file_path == ppath) { - throw std::runtime_error("Config error: 'includes' directive tried to recursively include main config file: " + path + "."); + throw std::runtime_error( + "Config error: '" + includes_key + "' directive tried to recursively include main config file: " + path + "."); } if (std::filesystem::exists(include_file_path) && std::filesystem::is_regular_file(include_file_path)) { @@ -124,9 +127,10 @@ public: * (that use load_from_file_int recursively). */ const auto &key = n.first.Scalar(); - if (key == "includes") + if (key == includes_key) { - throw std::runtime_error("Config error: 'includes' directive in included config file " + include_file + "."); + throw std::runtime_error( + "Config error: '" + includes_key + "' directive in included config file " + include_file + "."); } // We allow to override keys. // We don't need to use `get_node()` here,