martinzink commented on code in PR #2063:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2063#discussion_r2517630506


##########
core-framework/include/core/VariableRegistry.h:
##########
@@ -40,53 +43,37 @@ class VariableRegistryImpl : public virtual 
VariableRegistry {
 
   ~VariableRegistryImpl() override = default;
 
-  bool getConfigurationProperty(const std::string &property, std::string 
&value) const override {
-    auto prop = variable_registry_.find(property);
-    if (prop != variable_registry_.end()) {
-      value = prop->second;
-      return true;
+  [[nodiscard]] std::optional<std::string> getConfigurationProperty(const 
std::string_view key) const override {
+    const auto it = variable_registry_.find(key);
+    if (it == variable_registry_.end()) {
+      return std::nullopt;
     }
-    return false;
+    return it->second;
   }
 
  protected:
   void loadVariableRegistry() {
-    std::string registry_values;
-
-    auto options = configuration_->getConfiguredKeys();
-    std::string white_list_opt = "minifi.variable.registry.whitelist", 
white_list;
-    std::string black_list_opt = "minifi.variable.registry.blacklist", 
black_list;
+    gsl_Assert(configuration_);
+    auto options = configuration_->get("minifi.variable.registry.whitelist")
+        .transform([](std::string&& list) { return 
utils::string::split(std::move(list), ","); })
+        .value_or(configuration_->getConfiguredKeys());
 
-    // only allow those in the white liset
-    if (configuration_->get(white_list_opt, white_list)) {
-      options = utils::string::split(white_list, ",");
-    }
-
-    for (const auto &opt : options) {
-      if (opt.find("password") != std::string::npos)
-        options.erase(std::remove(options.begin(), options.end(), opt), 
options.end());
-    }
+    const auto black_listed_options = 
configuration_->get("minifi.variable.registry.blacklist")
+        .transform([](std::string&& list) { return 
utils::string::split(std::move(list), ","); });
 
-    // even if a white list is configured, remove the black listed fields
-
-    if (configuration_->get(black_list_opt, black_list)) {
-      auto bl_opts = utils::string::split(black_list, ",");
-      for (const auto &opt : bl_opts) {
-        options.erase(std::remove(options.begin(), options.end(), opt), 
options.end());
-      }
-    }
+    auto not_password = [](const std::string& s) { return 
!s.contains("password"); };
+    auto not_blacklisted = [&black_listed_options](const std::string& s) { 
return !(black_listed_options && std::ranges::contains(*black_listed_options, 
s)); };
 
-    for (const auto &opt : options) {
-      std::string value;
-      if (configuration_->get(opt, value)) {
-        variable_registry_[opt] = value;

Review Comment:
   This was UB, due to erase invalidating the iterator



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to