From e930f40b5df66f4c6608d8b70a61c3f008971ea7 Mon Sep 17 00:00:00 2001 From: Andrea Terzolo Date: Thu, 4 Jan 2024 18:04:46 +0100 Subject: [PATCH] cleanup(falco_engine): remove unused methods Signed-off-by: Andrea Terzolo --- userspace/engine/falco_engine.cpp | 70 ------------------------------- userspace/engine/falco_engine.h | 17 +------- 2 files changed, 1 insertion(+), 86 deletions(-) diff --git a/userspace/engine/falco_engine.cpp b/userspace/engine/falco_engine.cpp index af73cec7251..189efa41adc 100644 --- a/userspace/engine/falco_engine.cpp +++ b/userspace/engine/falco_engine.cpp @@ -177,15 +177,6 @@ void falco_engine::list_fields(std::string &source, bool verbose, bool names_onl } } -void falco_engine::load_rules(const std::string &rules_content, bool verbose, bool all_events) -{ - static const std::string no_name = "N/A"; - - std::unique_ptr res = load_rules(rules_content, no_name); - - interpret_load_result(res, no_name, rules_content, verbose); -} - std::unique_ptr falco_engine::load_rules(const std::string &rules_content, const std::string &name) { rule_loader::configuration cfg(rules_content, m_sources, name); @@ -257,44 +248,6 @@ std::unique_ptr falco_engine::load_rules(const std::string &rules_c return std::move(cfg.res); } -void falco_engine::load_rules_file(const std::string &rules_filename, bool verbose, bool all_events) -{ - std::string rules_content; - - read_file(rules_filename, rules_content); - - std::unique_ptr res = load_rules(rules_content, rules_filename); - - interpret_load_result(res, rules_filename, rules_content, verbose); -} - -std::unique_ptr falco_engine::load_rules_file(const std::string &rules_filename) -{ - std::string rules_content; - - try { - read_file(rules_filename, rules_content); - } - catch (falco_exception &e) - { - rule_loader::context ctx(rules_filename); - - std::unique_ptr res(new rule_loader::result(rules_filename)); - - res->add_error(load_result::LOAD_ERR_FILE_READ, e.what(), ctx); - -// Old gcc versions (e.g. 4.8.3) won't allow move elision but newer versions -// (e.g. 10.2.1) would complain about the redundant move. -#if __GNUC__ > 4 - return res; -#else - return std::move(res); -#endif - } - - return load_rules(rules_content, rules_filename); -} - void falco_engine::enable_rule(const std::string &substring, bool enabled, const std::string &ruleset) { uint16_t ruleset_id = find_ruleset_id(ruleset); @@ -955,29 +908,6 @@ void falco_engine::read_file(const std::string& filename, std::string& contents) std::istreambuf_iterator()); } -void falco_engine::interpret_load_result(std::unique_ptr& res, - const std::string& rules_filename, - const std::string& rules_content, - bool verbose) -{ - falco::load_result::rules_contents_t rc = {{rules_filename, rules_content}}; - - if(!res->successful()) - { - // The output here is always the full e.g. "verbose" output. - throw falco_exception(res->as_string(true, rc).c_str()); - } - - if(verbose && res->has_warnings()) - { - // Here, verbose controls whether to additionally - // "log" e.g. print to stderr. What's logged is always - // non-verbose so it fits on a single line. - // todo(jasondellaluce): introduce a logging callback in Falco - fprintf(stderr, "%s\n", res->as_string(false, rc).c_str()); - } -} - static bool check_plugin_requirement_alternatives( const std::vector& plugins, const rule_loader::plugin_version_info::requirement_alternatives& alternatives, diff --git a/userspace/engine/falco_engine.h b/userspace/engine/falco_engine.h index 1ca7ec67157..a13e58ebe00 100644 --- a/userspace/engine/falco_engine.h +++ b/userspace/engine/falco_engine.h @@ -74,15 +74,8 @@ class falco_engine void list_fields(std::string &source, bool verbose, bool names_only, bool markdown) const; // - // Load rules either directly or from a filename. + // Load rules and returns a result object. // - void load_rules_file(const std::string &rules_filename, bool verbose, bool all_events); - void load_rules(const std::string &rules_content, bool verbose, bool all_events); - - // - // Identical to above, but returns a result object instead of - // throwing exceptions on error. - std::unique_ptr load_rules_file(const std::string &rules_filename); std::unique_ptr load_rules(const std::string &rules_content, const std::string &name); // @@ -296,13 +289,6 @@ class falco_engine // Throws falco_exception if the file can not be read void read_file(const std::string& filename, std::string& contents); - // For load_rules methods that throw exceptions on error, - // interpret a load_result and throw an exception if needed. - void interpret_load_result(std::unique_ptr& res, - const std::string& rules_filename, - const std::string& rules_content, - bool verbose); - indexed_vector m_sources; const falco_source* find_source(std::size_t index) const; @@ -387,4 +373,3 @@ class falco_engine std::string m_extra; bool m_replace_container_info; }; -