mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-05 16:50:34 +00:00
refactor(engine): fix variable / function shadowing
Improve variable names in the code surrounding the changes. Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
@@ -485,7 +485,7 @@ template <typename T> inline nlohmann::json sequence_to_json_array(const T& seq)
|
||||
return ret;
|
||||
}
|
||||
|
||||
nlohmann::json falco_engine::describe_rule(std::string *rule, const std::vector<std::shared_ptr<sinsp_plugin>>& plugins) const
|
||||
nlohmann::json falco_engine::describe_rule(std::string *rule_name, const std::vector<std::shared_ptr<sinsp_plugin>>& plugins) const
|
||||
{
|
||||
// use previously-loaded collector definitions and the compiled
|
||||
// output of rules, macros, and lists.
|
||||
@@ -496,7 +496,7 @@ nlohmann::json falco_engine::describe_rule(std::string *rule, const std::vector<
|
||||
|
||||
// use collected and compiled info to print a json output
|
||||
nlohmann::json output;
|
||||
if(!rule)
|
||||
if(!rule_name)
|
||||
{
|
||||
// Store required engine version
|
||||
auto required_engine_version = m_rule_collector->required_engine_version();
|
||||
@@ -527,51 +527,51 @@ nlohmann::json falco_engine::describe_rule(std::string *rule, const std::vector<
|
||||
|
||||
// Store information about rules
|
||||
nlohmann::json rules_array = nlohmann::json::array();
|
||||
for(const auto& r : m_last_compile_output->rules)
|
||||
for(const auto& rule : m_last_compile_output->rules)
|
||||
{
|
||||
auto info = m_rule_collector->rules().at(r.name);
|
||||
nlohmann::json rule;
|
||||
get_json_details(rule, r, *info, plugins);
|
||||
rules_array.push_back(std::move(rule));
|
||||
auto info = m_rule_collector->rules().at(rule.name);
|
||||
nlohmann::json details;
|
||||
get_json_details(details, rule, *info, plugins);
|
||||
rules_array.push_back(std::move(details));
|
||||
}
|
||||
output["rules"] = std::move(rules_array);
|
||||
|
||||
// Store information about macros
|
||||
nlohmann::json macros_array = nlohmann::json::array();
|
||||
for(const auto &m : m_last_compile_output->macros)
|
||||
for(const auto ¯o : m_last_compile_output->macros)
|
||||
{
|
||||
auto info = m_rule_collector->macros().at(m.name);
|
||||
nlohmann::json macro;
|
||||
get_json_details(macro, m, *info, plugins);
|
||||
macros_array.push_back(std::move(macro));
|
||||
auto info = m_rule_collector->macros().at(macro.name);
|
||||
nlohmann::json details;
|
||||
get_json_details(details, macro, *info, plugins);
|
||||
macros_array.push_back(std::move(details));
|
||||
}
|
||||
output["macros"] = std::move(macros_array);
|
||||
|
||||
// Store information about lists
|
||||
nlohmann::json lists_array = nlohmann::json::array();
|
||||
for(const auto &l : m_last_compile_output->lists)
|
||||
for(const auto &list : m_last_compile_output->lists)
|
||||
{
|
||||
auto info = m_rule_collector->lists().at(l.name);
|
||||
nlohmann::json list;
|
||||
get_json_details(list, l, *info, plugins);
|
||||
lists_array.push_back(std::move(list));
|
||||
auto info = m_rule_collector->lists().at(list.name);
|
||||
nlohmann::json details;
|
||||
get_json_details(details, list, *info, plugins);
|
||||
lists_array.push_back(std::move(details));
|
||||
}
|
||||
output["lists"] = std::move(lists_array);
|
||||
}
|
||||
else
|
||||
{
|
||||
// build json information for just the specified rule
|
||||
auto ri = m_rule_collector->rules().at(*rule);
|
||||
auto ri = m_rule_collector->rules().at(*rule_name);
|
||||
if(ri == nullptr || ri->unknown_source)
|
||||
{
|
||||
throw falco_exception("Rule \"" + *rule + "\" is not loaded");
|
||||
throw falco_exception("Rule \"" + *rule_name + "\" is not loaded");
|
||||
}
|
||||
auto r = m_rules.at(ri->name);
|
||||
auto rule = m_rules.at(ri->name);
|
||||
|
||||
nlohmann::json rule;
|
||||
get_json_details(rule, *r, *ri, plugins);
|
||||
nlohmann::json details;
|
||||
get_json_details(details, *rule, *ri, plugins);
|
||||
nlohmann::json rules_array = nlohmann::json::array();
|
||||
rules_array.push_back(std::move(rule));
|
||||
rules_array.push_back(std::move(details));
|
||||
output["rules"] = std::move(rules_array);
|
||||
}
|
||||
|
||||
@@ -688,13 +688,13 @@ void falco_engine::get_json_details(
|
||||
|
||||
void falco_engine::get_json_details(
|
||||
nlohmann::json& out,
|
||||
const falco_macro& m,
|
||||
const falco_macro& macro,
|
||||
const rule_loader::macro_info& info,
|
||||
const std::vector<std::shared_ptr<sinsp_plugin>>& plugins) const
|
||||
{
|
||||
nlohmann::json macro_info;
|
||||
|
||||
macro_info["name"] = m.name;
|
||||
macro_info["name"] = macro.name;
|
||||
macro_info["condition"] = info.cond;
|
||||
out["info"] = std::move(macro_info);
|
||||
|
||||
@@ -717,9 +717,9 @@ void falco_engine::get_json_details(
|
||||
compiled_details.known_lists.insert(l.name);
|
||||
}
|
||||
filter_details_resolver().run(ast.get(), details);
|
||||
filter_details_resolver().run(m.condition.get(), compiled_details);
|
||||
filter_details_resolver().run(macro.condition.get(), compiled_details);
|
||||
|
||||
out["details"]["used"] = m.used;
|
||||
out["details"]["used"] = macro.used;
|
||||
out["details"]["macros"] = sequence_to_json_array(details.macros);
|
||||
out["details"]["lists"] = sequence_to_json_array(details.lists);
|
||||
out["details"]["condition_operators"] = sequence_to_json_array(compiled_details.operators);
|
||||
@@ -727,11 +727,11 @@ void falco_engine::get_json_details(
|
||||
|
||||
// Store event types
|
||||
nlohmann::json events;
|
||||
get_json_evt_types(events, "", m.condition.get());
|
||||
get_json_evt_types(events, "", macro.condition.get());
|
||||
out["details"]["events"] = std::move(events);
|
||||
|
||||
// Store compiled condition
|
||||
out["details"]["condition_compiled"] = libsinsp::filter::ast::as_string(m.condition.get());
|
||||
out["details"]["condition_compiled"] = libsinsp::filter::ast::as_string(macro.condition.get());
|
||||
|
||||
// Compute the plugins that are actually used by this macro.
|
||||
// Note: macros have no specific source, we need to set an empty list of used
|
||||
|
Reference in New Issue
Block a user