Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(userspace): cleanup output of ruleset validation result #2248

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions test/falco_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,6 @@ trace_files: !mux
item_name: some macro
code: LOAD_ERR_VALIDATE
message: "Undefined macro 'foo' used in filter."
validate_warnings:
- item_type: macro
item_name: some macro
code: LOAD_UNUSED_MACRO
message: "Macro not referred to by any other rule/macro"
validate_rules_file:
- rules/invalid_overwrite_macro_multiple_docs.yaml
trace_file: trace_files/cat_write.scap
Expand Down
1 change: 1 addition & 0 deletions userspace/engine/rule_loader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ void rule_loader::compiler::compile(
catch(rule_load_exception &e)
{
cfg.res->add_error(e.ec, e.msg, e.ctx);
return;
}

// print info on any dangling lists or macros that were not used anywhere
Expand Down
45 changes: 21 additions & 24 deletions userspace/falco/app_actions/validate_rules_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,30 @@ application::run_result application::validate_rules_files()
{
results.push_back(res->as_json(rc));
}
else

if(summary != "")
{
if(summary != "")
{
summary += "\n";
}
summary += "\n";
}

// Add to the summary if not successful, or successful
// with no warnings.
if(!res->successful() ||
(res->successful() && !res->has_warnings()))
{
summary += res->as_string(true, rc);
}
else
// Add to the summary if not successful, or successful
// with no warnings.
if(!res->successful() || (res->successful() && !res->has_warnings()))
{
summary += res->as_string(true, rc);
}
else
{
// If here, there must be only warnings.
// Add a line to the summary noting that the
// file was ok with warnings, without actually
// printing the warnings.
summary += filename + ": Ok, with warnings";

// If verbose is true, print the warnings now.
if(m_options.verbose)
{
// If here, there must be only warnings.
// Add a line to the summary noting that the
// file was ok with warnings, without actually
// printing the warnings.
summary += filename + ": Ok, with warnings";

// If verbose is true, print the warnings now.
if(m_options.verbose)
{
fprintf(stderr, "%s\n", res->as_string(true, rc).c_str());
}
fprintf(stderr, "%s\n", res->as_string(true, rc).c_str());
}
}
}
Expand Down