diff --git a/unit_tests/engine/test_rule_loader.cpp b/unit_tests/engine/test_rule_loader.cpp index 042f55d09c7..74d1696d4cb 100644 --- a/unit_tests/engine/test_rule_loader.cpp +++ b/unit_tests/engine/test_rule_loader.cpp @@ -190,7 +190,7 @@ TEST_F(engine_loader_test, rule_override_append) ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; // Here we don't use the deprecated `append` flag, so we don't expect the warning. - ASSERT_FALSE(check_warning_message(WARNING_APPEND_MESSAGE)); + ASSERT_FALSE(check_warning_message(WARNING_APPEND)); auto rule_description = m_engine->describe_rule(&rule_name, {}); ASSERT_EQ(rule_description["rules"][0]["info"]["condition"].template get(), @@ -221,7 +221,7 @@ TEST_F(engine_loader_test, rule_append) ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; // We should have at least one warning because the 'append' flag is deprecated. - ASSERT_TRUE(check_warning_message(WARNING_APPEND_MESSAGE)); + ASSERT_TRUE(check_warning_message(WARNING_APPEND)); auto rule_description = m_engine->describe_rule(&rule_name, {}); ASSERT_EQ(rule_description["rules"][0]["details"]["condition_compiled"].template get(), @@ -344,9 +344,9 @@ TEST_F(engine_loader_test, rule_incorrect_append_override) ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); // We should have at least one warning because the 'append' flag is deprecated. - ASSERT_TRUE(check_warning_message(WARNING_APPEND_MESSAGE)); + ASSERT_TRUE(check_warning_message(WARNING_APPEND)); - ASSERT_TRUE(check_error_message(OVERRIDE_APPEND_ERROR_MESSAGE)); + ASSERT_TRUE(check_error_message(ERROR_OVERRIDE_APPEND)); } TEST_F(engine_loader_test, macro_override_append_before_macro_definition) @@ -872,7 +872,7 @@ TEST_F(engine_loader_test, rule_enabled_warning) )END"; ASSERT_TRUE(load_rules(rules_content, "rules.yaml")); - ASSERT_TRUE(check_warning_message(WARNING_ENABLED_MESSAGE)); + ASSERT_TRUE(check_warning_message(WARNING_ENABLED)); // The rule should be enabled at the end. EXPECT_EQ(num_rules_for_ruleset(), 1); } diff --git a/userspace/engine/rule_loader_reader.cpp b/userspace/engine/rule_loader_reader.cpp index 3210e878cfd..57ab8455a52 100644 --- a/userspace/engine/rule_loader_reader.cpp +++ b/userspace/engine/rule_loader_reader.cpp @@ -442,7 +442,7 @@ static void read_item( decode_optional_val(item, "append", has_append_flag, ctx); if(has_append_flag) { - cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_APPEND_MESSAGE, ctx); + cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_APPEND, ctx); } std::set override_append, override_replace; @@ -450,7 +450,7 @@ static void read_item( decode_overrides(item, overridable, overridable, override_append, override_replace, ctx); bool has_overrides = !override_append.empty() || !override_replace.empty(); - THROW(has_append_flag && has_overrides, OVERRIDE_APPEND_ERROR_MESSAGE, ctx); + THROW(has_append_flag && has_overrides, ERROR_OVERRIDE_APPEND, ctx); // Since a list only has items, if we have chosen to append them we can append the entire object // otherwise we just want to redefine the list. @@ -485,7 +485,7 @@ static void read_item( decode_optional_val(item, "append", has_append_flag, ctx); if(has_append_flag) { - cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_APPEND_MESSAGE, ctx); + cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_APPEND, ctx); } std::set override_append, override_replace; @@ -493,7 +493,7 @@ static void read_item( decode_overrides(item, overridable, overridable, override_append, override_replace, ctx); bool has_overrides = !override_append.empty() || !override_replace.empty(); - THROW((has_append_flag && has_overrides), OVERRIDE_APPEND_ERROR_MESSAGE, ctx); + THROW((has_append_flag && has_overrides), ERROR_OVERRIDE_APPEND, ctx); // Since a macro only has a condition, if we have chosen to append to it we can append the entire object // otherwise we just want to redefine the macro. @@ -522,7 +522,7 @@ static void read_item( decode_optional_val(item, "append", has_append_flag, ctx); if(has_append_flag) { - cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_APPEND_MESSAGE, ctx); + cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_APPEND, ctx); } std::set override_append, override_replace; @@ -534,7 +534,7 @@ static void read_item( bool has_overrides_replace = !override_replace.empty(); bool has_overrides = has_overrides_append || has_overrides_replace; - THROW((has_append_flag && has_overrides), OVERRIDE_APPEND_ERROR_MESSAGE, ctx); + THROW((has_append_flag && has_overrides), ERROR_OVERRIDE_APPEND, ctx); if(has_overrides) { @@ -694,7 +694,7 @@ static void read_item( !item["priority"].IsDefined()) { decode_val(item, "enabled", v.enabled, ctx); - cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_ENABLED_MESSAGE, ctx); + cfg.res->add_warning(falco::load_result::LOAD_DEPRECATED_ITEM, WARNING_ENABLED, ctx); collector.enable(cfg, v); } else diff --git a/userspace/engine/rule_loading_messages.h b/userspace/engine/rule_loading_messages.h index 18476b64f78..5962fb0a406 100644 --- a/userspace/engine/rule_loading_messages.h +++ b/userspace/engine/rule_loading_messages.h @@ -1,11 +1,18 @@ #pragma once -// todo: rename putting error at the beginning -#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." +//////////////// +// Warnings +//////////////// -#define WARNING_APPEND_MESSAGE "'append' key is deprecated. Add an 'append' entry (e.g. 'condition: append') under 'override' instead." +#define WARNING_APPEND "'append' key is deprecated. Add an 'append' entry (e.g. 'condition: append') under 'override' instead." -#define WARNING_ENABLED_MESSAGE "The standalone 'enabled' key usage is deprecated. The correct approach requires also a 'replace' entry under the 'override' key (i.e. 'enabled: replace')." +#define WARNING_ENABLED "The standalone 'enabled' key usage is deprecated. The correct approach requires also a 'replace' entry under the 'override' key (i.e. 'enabled: replace')." + +//////////////// +// Errors +//////////////// + +#define ERROR_OVERRIDE_APPEND "Keys 'override' and 'append: true' cannot be used together. Add an 'append' entry (e.g. 'condition: append') under 'override' instead." #define ERROR_NO_PREVIOUS_MACRO "Macro uses 'append' or 'override.condition: append' but no macro by that name already exists"