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


##########
libminifi/src/core/flow/StructuredConfiguration.cpp:
##########
@@ -191,23 +192,80 @@ void 
StructuredConfiguration::parseParameterContexts(const Node& parameter_conte
     uuid = id;
     auto parameter_context = std::make_unique<ParameterContext>(name, uuid);
     parameter_context->setDescription(getOptionalField(parameter_context_node, 
schema_.description, ""));
+    
parameter_context->setParameterProvider(getOptionalField(parameter_context_node,
 schema_.parameter_provider, ""));
     for (const auto& parameter_node : 
parameter_context_node[schema_.parameters]) {
       checkRequiredField(parameter_node, schema_.name);
       checkRequiredField(parameter_node, schema_.value);
       checkRequiredField(parameter_node, schema_.sensitive);
       auto parameter_name = parameter_node[schema_.name].getString().value();
       auto parameter_value = parameter_node[schema_.value].getString().value();
       auto sensitive = parameter_node[schema_.sensitive].getBool().value();
+      auto provided = 
parameter_node[schema_.provided].getBool().value_or(false);
       auto parameter_description = getOptionalField(parameter_node, 
schema_.description, "");
       if (sensitive) {
         parameter_value = 
utils::crypto::property_encryption::decrypt(parameter_value, 
sensitive_values_encryptor_);
       }
-      parameter_context->addParameter(Parameter{parameter_name, 
parameter_description, sensitive, parameter_value});
+      parameter_context->addParameter(Parameter{
+        .name = parameter_name,
+        .description = parameter_description,
+        .sensitive = sensitive,
+        .provided = provided,
+        .value = parameter_value});
     }
 
     parameter_contexts_.emplace(name, 
gsl::make_not_null(std::move(parameter_context)));
   }
+}
+
+void StructuredConfiguration::parseParameterProvidersNode(const Node& 
parameter_providers_node) {
+  if (!parameter_providers_node || !parameter_providers_node.isSequence()) {
+    return;
+  }
+  for (const auto& parameter_provider_node : parameter_providers_node) {
+    checkRequiredField(parameter_provider_node, schema_.name);
 
+    auto type = getRequiredField(parameter_provider_node, schema_.type);
+    logger_->log_debug("Using type {} for parameter provider node", type);
+
+    std::string fullType = type;
+    auto lastOfIdx = type.find_last_of('.');
+    if (lastOfIdx != std::string::npos) {
+      lastOfIdx++;  // if a value is found, increment to move beyond the .
+      type = type.substr(lastOfIdx);
+    }

Review Comment:
   Good point, extracted the utility in 
https://github.com/apache/nifi-minifi-cpp/pull/1895/commits/59232bff0daaff05f1416b7ab45db3545fc8d651



##########
libminifi/src/parameter-providers/EnvironmentVariableParameterProvider.cpp:
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.
+ */
+#include "parameter-providers/EnvironmentVariableParameterProvider.h"
+#include "core/Resource.h"
+#include "utils/Environment.h"
+#include "Exception.h"
+#include "range/v3/view/filter.hpp"
+#include "utils/RegexUtils.h"
+
+namespace org::apache::nifi::minifi::parameter_providers {
+
+std::string EnvironmentVariableParameterProvider::readParameterGroupName() 
const {
+  auto parameter_group_name = getProperty(ParameterGroupName);
+  if (!parameter_group_name || parameter_group_name.value().empty()) {
+    throw core::ParameterException("Parameter Group Name is required");
+  }
+  logger_->log_debug("Building Parameter Context with name: {}", 
parameter_group_name.value());
+  return parameter_group_name.value();
+}
+
+EnvironmentVariableInclusionStrategyOptions 
EnvironmentVariableParameterProvider::readEnvironmentVariableInclusionStrategy()
 const {
+  auto env_variable_inclusion_strategy_str = 
getProperty(EnvironmentVariableInclusionStrategy);
+  if (!env_variable_inclusion_strategy_str) {
+    throw core::ParameterException("Environment Variable Inclusion Strategy is 
required");
+  }
+  auto env_variable_inclusion_strategy = 
magic_enum::enum_cast<EnvironmentVariableInclusionStrategyOptions>(*env_variable_inclusion_strategy_str);
+  if (!env_variable_inclusion_strategy) {
+    throw core::ParameterException("Environment Variable Inclusion Strategy 
has invalid value: '" + *env_variable_inclusion_strategy_str + "'");
+  }
+  logger_->log_debug("Environment Variable Inclusion Strategy: {}", 
*env_variable_inclusion_strategy_str);
+  return env_variable_inclusion_strategy.value();
+}
+
+void 
EnvironmentVariableParameterProvider::filterEnvironmentVariablesByCommaSeparatedList(std::unordered_map<std::string,
 std::string>& environment_variables) const {
+  std::unordered_set<std::string> included_environment_variables;
+  if (auto incuded_environment_variables_str = 
getProperty(IncludeEnvironmentVariables)) {
+    for (const auto& included_environment_variable : 
minifi::utils::string::split(*incuded_environment_variables_str, ",")) {

Review Comment:
   Updated in 
https://github.com/apache/nifi-minifi-cpp/pull/1895/commits/59232bff0daaff05f1416b7ab45db3545fc8d651



##########
libminifi/src/utils/Environment.cpp:
##########
@@ -27,9 +27,16 @@
 #include <mutex>
 #include <vector>
 #include <iostream>
+#include <unordered_map>
 
 #include "utils/gsl.h"
 
+// Apple doesn't provide the environ global variable
+#if defined(__APPLE__) && !defined(environ)
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())

Review Comment:
   Removed the macro in 
https://github.com/apache/nifi-minifi-cpp/pull/1895/commits/59232bff0daaff05f1416b7ab45db3545fc8d651
 Unfortunately it cannot be a `constexpr`.



##########
libminifi/test/unit/JsonFlowSerializerTests.cpp:
##########
@@ -731,19 +732,173 @@ TEST_CASE("The encrypted flow configuration cannot be 
decrypted with an incorrec
   core::flow::AdaptiveConfiguration 
json_configuration_before{configuration_context};
 
   const auto schema = core::flow::FlowSchema::getNiFiFlowJson();
-  const auto config_json_with_nifi_schema = 
utils::string::join_pack(config_json_with_nifi_schema_part_1, 
config_json_with_nifi_schema_part_2);
+  const auto config_json_with_nifi_schema = 
minifi::utils::string::join_pack(config_json_with_nifi_schema_part_1, 
config_json_with_nifi_schema_part_2);
   const auto process_group_before = 
json_configuration_before.getRootFromPayload(config_json_with_nifi_schema);
   REQUIRE(process_group_before);
 
   rapidjson::Document doc;
   rapidjson::ParseResult res = doc.Parse(config_json_with_nifi_schema.data(), 
config_json_with_nifi_schema.size());
   REQUIRE(res);
   const auto flow_serializer = core::json::JsonFlowSerializer{std::move(doc)};
-  std::string config_json_encrypted = 
flow_serializer.serialize(*process_group_before, schema, encryption_provider, 
{});
+  std::string config_json_encrypted = 
flow_serializer.serialize(*process_group_before, schema, encryption_provider, 
{}, {});
 
-  const utils::crypto::Bytes different_secret_key = 
utils::string::from_hex("ea55b7d0edc22280c9547e4d89712b3fae74f96d82f240a004fb9fbd0640eec7");
-  configuration_context.sensitive_values_encryptor = 
utils::crypto::EncryptionProvider{different_secret_key};
+  const minifi::utils::crypto::Bytes different_secret_key = 
minifi::utils::string::from_hex("ea55b7d0edc22280c9547e4d89712b3fae74f96d82f240a004fb9fbd0640eec7");
+  configuration_context.sensitive_values_encryptor = 
minifi::utils::crypto::EncryptionProvider{different_secret_key};
 
   core::flow::AdaptiveConfiguration 
json_configuration_after{configuration_context};
-  
REQUIRE_THROWS_AS(json_configuration_after.getRootFromPayload(config_json_encrypted),
 utils::crypto::EncryptionError);
+  
REQUIRE_THROWS_AS(json_configuration_after.getRootFromPayload(config_json_encrypted),
 minifi::utils::crypto::EncryptionError);
 }
+
+TEST_CASE("Parameter provider generated parameter context is serialized 
correctly") {

Review Comment:
   I would keep them separate, as the second test checks that the old parameter 
value was not overriden, while the first test checks for the newly set test 
value gathered from the environment variable.



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