Skip to content

Commit

Permalink
Better handle default configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SwooshyCueb committed Sep 12, 2022
1 parent 3a6ddbe commit 1b9c048
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions libirods_rule_engine_plugin-audit_amqp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<std::string>();
Expand All @@ -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<std::string>();
Expand All @@ -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<std::string>();
}
}
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},
Expand Down

0 comments on commit 1b9c048

Please sign in to comment.