From 1b9c04878e806953a5b914f07a0543b23dabe1af Mon Sep 17 00:00:00 2001 From: "Markus Kitsinger (SwooshyCueb)" Date: Wed, 7 Sep 2022 19:12:05 -0400 Subject: [PATCH] Better handle default configuration --- libirods_rule_engine_plugin-audit_amqp.cpp | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/libirods_rule_engine_plugin-audit_amqp.cpp b/libirods_rule_engine_plugin-audit_amqp.cpp index ed76db077..4b995c78a 100644 --- a/libirods_rule_engine_plugin-audit_amqp.cpp +++ b/libirods_rule_engine_plugin-audit_amqp.cpp @@ -45,15 +45,21 @@ using ts_clock = std::chrono::system_clock; using log_re = irods::experimental::log::rule_engine; -static const std::string rule_engine_name("audit_amqp"); - // NOLINTBEGIN(cert-err58-cpp, cppcoreguidelines-avoid-non-const-global-variables) -static std::string audit_pep_regex_to_match = "audit_.*"; -static std::string audit_amqp_topic = "irods_audit_messages"; -static std::string audit_amqp_location = "localhost:5672"; -static std::string audit_amqp_user = ""; -static std::string audit_amqp_password = ""; -static std::string audit_amqp_options = ""; +static const std::string rule_engine_name("audit_amqp"); +static const std::string default_pep_regex_to_match("audit_.*"); +static const std::string default_amqp_topic("irods_audit_messages"); +static const std::string default_amqp_location("localhost:5672"); +static const std::string default_amqp_user(""); +static const std::string default_amqp_password(""); +static const std::string default_amqp_options(""); + +static std::string audit_pep_regex_to_match(default_pep_regex_to_match); +static std::string audit_amqp_topic(default_amqp_topic); +static std::string audit_amqp_location(default_amqp_location); +static std::string audit_amqp_user(default_amqp_user); +static std::string audit_amqp_password(default_amqp_password); +static std::string audit_amqp_options(default_amqp_options); static std::mutex audit_plugin_mutex; // NOLINTEND(cert-err58-cpp, cppcoreguidelines-avoid-non-const-global-variables) @@ -167,7 +173,7 @@ auto get_re_configs(const std::string& _instance_name) -> irods::error // amqp_user is optional const auto amqp_user_cfg = plugin_spec_cfg.find("amqp_user"); if (amqp_user_cfg == plugin_spec_cfg.end()) { - audit_amqp_user.clear(); + audit_amqp_user = default_amqp_user; } else { audit_amqp_user = amqp_user_cfg->get(); @@ -176,7 +182,7 @@ auto get_re_configs(const std::string& _instance_name) -> irods::error // amqp_password is optional const auto amqp_password_cfg = plugin_spec_cfg.find("amqp_password"); if (amqp_password_cfg == plugin_spec_cfg.end()) { - audit_amqp_password.clear(); + audit_amqp_password = default_amqp_password; } else { audit_amqp_password = amqp_password_cfg->get(); @@ -185,13 +191,19 @@ auto get_re_configs(const std::string& _instance_name) -> irods::error // amqp_options is optional const auto amqp_options_cfg = plugin_spec_cfg.find("amqp_options"); if (amqp_options_cfg == plugin_spec_cfg.end()) { - audit_amqp_options.clear(); + audit_amqp_options = default_amqp_options; } else { audit_amqp_options = amqp_options_cfg->get(); } } else { + audit_pep_regex_to_match = default_pep_regex_to_match; + audit_amqp_topic = default_amqp_topic; + audit_amqp_location = default_amqp_location; + audit_amqp_user = default_amqp_user; + audit_amqp_password = default_amqp_password; + audit_amqp_options = default_amqp_options; // clang-format off log_re::debug({ {"rule_engine_plugin", rule_engine_name},