Skip to content

Commit

Permalink
cleanup(falco_engine): remove unused methods
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Jan 4, 2024
1 parent 4a1fe2f commit e930f40
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 86 deletions.
70 changes: 0 additions & 70 deletions userspace/engine/falco_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<load_result> res = load_rules(rules_content, no_name);

interpret_load_result(res, no_name, rules_content, verbose);
}

std::unique_ptr<load_result> falco_engine::load_rules(const std::string &rules_content, const std::string &name)
{
rule_loader::configuration cfg(rules_content, m_sources, name);
Expand Down Expand Up @@ -257,44 +248,6 @@ std::unique_ptr<load_result> 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<load_result> res = load_rules(rules_content, rules_filename);

interpret_load_result(res, rules_filename, rules_content, verbose);
}

std::unique_ptr<load_result> 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<rule_loader::result> 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);
Expand Down Expand Up @@ -955,29 +908,6 @@ void falco_engine::read_file(const std::string& filename, std::string& contents)
std::istreambuf_iterator<char>());
}

void falco_engine::interpret_load_result(std::unique_ptr<load_result>& 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<falco_engine::plugin_version_requirement>& plugins,
const rule_loader::plugin_version_info::requirement_alternatives& alternatives,
Expand Down
17 changes: 1 addition & 16 deletions userspace/engine/falco_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<falco::load_result> load_rules_file(const std::string &rules_filename);
std::unique_ptr<falco::load_result> load_rules(const std::string &rules_content, const std::string &name);

//
Expand Down Expand Up @@ -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<falco::load_result>& res,
const std::string& rules_filename,
const std::string& rules_content,
bool verbose);

indexed_vector<falco_source> m_sources;

const falco_source* find_source(std::size_t index) const;
Expand Down Expand Up @@ -387,4 +373,3 @@ class falco_engine
std::string m_extra;
bool m_replace_container_info;
};

0 comments on commit e930f40

Please sign in to comment.