cleanup(rule_loader): add a common log message

Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
This commit is contained in:
Andrea Terzolo
2024-01-03 12:40:19 +01:00
committed by poiana
parent 447a251e16
commit 7cac2833b2
3 changed files with 7 additions and 5 deletions

View File

@@ -283,7 +283,7 @@ TEST_F(engine_loader_test, rule_incorrect_append_override)
std::string rule_name = "failing_rule"; std::string rule_name = "failing_rule";
ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("'override' and 'append: true' cannot be used together") != std::string::npos); ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find(OVERRIDE_APPEND_ERROR_MESSAGE) != std::string::npos);
} }
TEST_F(engine_loader_test, rule_override_without_rule) TEST_F(engine_loader_test, rule_override_without_rule)

View File

@@ -448,7 +448,7 @@ static void read_item(
if(append == true && has_overrides) if(append == true && has_overrides)
{ {
THROW(true, "Keys 'override' and 'append: true' cannot be used together.", ctx); THROW(true, OVERRIDE_APPEND_ERROR_MESSAGE, ctx);
} }
// Since a list only has items, if we have chosen to append them we can append the entire object // Since a list only has items, if we have chosen to append them we can append the entire object
@@ -490,7 +490,7 @@ static void read_item(
if(append == true && has_overrides) if(append == true && has_overrides)
{ {
THROW(true, "Keys 'override' and 'append: true' cannot be used together.", ctx); THROW(true, OVERRIDE_APPEND_ERROR_MESSAGE, ctx);
} }
// Since a macro only has a condition, if we have chosen to append to it we can append the entire object // Since a macro only has a condition, if we have chosen to append to it we can append the entire object
@@ -528,8 +528,7 @@ static void read_item(
bool has_overrides_replace = !override_replace.empty(); bool has_overrides_replace = !override_replace.empty();
bool has_overrides = has_overrides_append || has_overrides_replace; bool has_overrides = has_overrides_append || has_overrides_replace;
THROW((has_append_flag && has_overrides), THROW((has_append_flag && has_overrides), OVERRIDE_APPEND_ERROR_MESSAGE, ctx);
"Keys 'override' and 'append: true' cannot be used together. Add an append entry (e.g. 'condition: append') under override instead.", ctx);
if(has_overrides) if(has_overrides)
{ {

View File

@@ -23,6 +23,9 @@ limitations under the License.
#include "version.h" #include "version.h"
#include "falco_engine_version.h" #include "falco_engine_version.h"
// Error message used when both 'override' and 'append' are specified.
#define OVERRIDE_APPEND_ERROR_MESSAGE "Keys 'override' and 'append: true' cannot be used together. Add an append entry (e.g. 'condition: append') under override instead."
namespace rule_loader namespace rule_loader
{ {