szaszm commented on code in PR #1895:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1895#discussion_r1848123396


##########
extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp:
##########
@@ -2033,4 +2009,224 @@ Parameter Context Name: c-context
   CHECK(value == "5");
 }
 
+TEST_CASE("Parameter providers can be used for parameter values", 
"[YamlConfiguration]") {
+  ConfigurationTestController test_controller;
+  core::YamlConfiguration yaml_config(test_controller.getContext());
+
+  static const std::string TEST_CONFIG_YAML =
+      R"(
+MiNiFi Config Version: 3
+Flow Controller:
+  name: flow
+Parameter Providers:
+  - id: 721e10b7-8e00-3188-9a27-476cca376978
+    name: DummyParameterProvider
+    type: DummyParameterProvider
+    Properties:
+      Dummy1 Value: value1
+      Dummy2 Value: value2
+      Dummy3 Value: value3
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+  name: DummyProcessor
+  class: org.apache.nifi.processors.DummyProcessor
+  max concurrent tasks: 1
+  scheduling strategy: TIMER_DRIVEN
+  scheduling period: 1 sec
+  auto-terminated relationships list: [success]
+  Properties:
+    Simple Property: "#{dummy1}"
+    My Dynamic Property Sequence:
+    - value: "#{dummy2}"
+    - value: "#{dummy3}"
+Parameter Context Name: dummycontext
+      )";
+
+  std::unique_ptr<core::ProcessGroup> flow = 
yaml_config.getRootFromPayload(TEST_CONFIG_YAML);
+  REQUIRE(flow);
+
+  auto* proc = flow->findProcessorByName("DummyProcessor");
+  REQUIRE(proc);
+  REQUIRE(proc->getProperty("Simple Property") == "value1");
+  core::Property property("My Dynamic Property Sequence", "");
+  proc->getDynamicProperty("My Dynamic Property Sequence", property);
+  auto values = property.getValues();
+  REQUIRE(values.size() == 2);
+  CHECK(values[0] == "value2");
+  CHECK(values[1] == "value3");
+}
+
+TEST_CASE("Parameter providers can be configured to select which parameters to 
be sensitive", "[YamlConfiguration]") {
+  ConfigurationTestController test_controller;
+  auto context = test_controller.getContext();
+  auto encrypted_sensitive_property_value = 
minifi::utils::crypto::property_encryption::encrypt("#{dummy1}", 
*context.sensitive_values_encryptor);
+  core::YamlConfiguration yaml_config(context);
+
+  static const std::string TEST_CONFIG_YAML =
+      fmt::format(R"(
+MiNiFi Config Version: 3
+Flow Controller:
+  name: flowconfig
+Parameter Providers:
+  - id: 721e10b7-8e00-3188-9a27-476cca376978
+    name: DummyParameterProvider
+    type: DummyParameterProvider
+    Properties:
+      Sensitive Parameter Scope: selected
+      Sensitive Parameter List: dummy1
+      Dummy1 Value: value1
+      Dummy3 Value: value3
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+  name: DummyProcessor
+  class: org.apache.nifi.processors.DummyProcessor
+  max concurrent tasks: 1
+  scheduling strategy: TIMER_DRIVEN
+  scheduling period: 1 sec
+  auto-terminated relationships list: [success]
+  Properties:
+    Simple Property: "#{{dummy3}}"
+    Sensitive Property: {}
+Parameter Context Name: dummycontext
+      )", encrypted_sensitive_property_value);
+
+  std::unique_ptr<core::ProcessGroup> flow = 
yaml_config.getRootFromPayload(TEST_CONFIG_YAML);
+  REQUIRE(flow);
+
+  auto* proc = flow->findProcessorByName("DummyProcessor");
+  REQUIRE(proc);
+  REQUIRE(proc->getProperty("Sensitive Property") == "value1");
+  REQUIRE(proc->getProperty("Simple Property") == "value3");
+}
+
+TEST_CASE("Parameter providers can be configured to make all parameters 
sensitive", "[YamlConfiguration]") {
+  ConfigurationTestController test_controller;
+  auto context = test_controller.getContext();
+  auto encrypted_sensitive_property_value = 
minifi::utils::crypto::property_encryption::encrypt("#{dummy1}", 
*context.sensitive_values_encryptor);
+  core::YamlConfiguration yaml_config(context);
+
+  static const std::string TEST_CONFIG_YAML =
+      fmt::format(R"(
+MiNiFi Config Version: 3
+Flow Controller:
+  name: flowconfig
+Parameter Providers:
+  - id: 721e10b7-8e00-3188-9a27-476cca376978
+    name: DummyParameterProvider
+    type: DummyParameterProvider
+    Properties:
+      Sensitive Parameter Scope: all
+      Dummy1 Value: value1
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+  name: DummyProcessor
+  class: org.apache.nifi.processors.DummyProcessor
+  max concurrent tasks: 1
+  scheduling strategy: TIMER_DRIVEN
+  scheduling period: 1 sec
+  auto-terminated relationships list: [success]
+  Properties:
+    Sensitive Property: {}

Review Comment:
   Will encrypt-config conflict with a sensitive parameter reference for a 
sensitive property value? Do we encrypt the expression?



##########
libminifi/include/core/ParameterProvider.h:
##########
@@ -0,0 +1,78 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <unordered_set>
+
+#include "core/Core.h"
+#include "core/ConfigurableComponent.h"
+#include "core/ParameterContext.h"
+#include "core/PropertyDefinitionBuilder.h"
+
+namespace org::apache::nifi::minifi::core {
+
+struct ParameterGroup {
+  std::string name;
+  std::unordered_map<std::string, std::string> parameters;
+};
+
+enum class SensitiveParameterScopeOptions {
+  none,
+  all,
+  selected
+};
+
+struct ParameterProviderConfig {
+  SensitiveParameterScopeOptions sensitive_parameter_scope = 
SensitiveParameterScopeOptions::none;
+  std::unordered_set<std::string> sensitive_parameters;
+};
+
+class ParameterProvider : public ConfigurableComponent, public CoreComponent {
+ public:
+  using CoreComponent::CoreComponent;
+  ParameterProvider(const ParameterProvider &other) = delete;
+  ParameterProvider &operator=(const ParameterProvider &other) = delete;

Review Comment:
   I think we should add Rule of 5 special member functions.



-- 
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