martinzink commented on code in PR #1926:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1926#discussion_r2001000555
##########
libminifi/src/core/flow/StructuredConfiguration.cpp:
##########
@@ -789,114 +785,88 @@ void
StructuredConfiguration::parsePropertyValueSequence(const std::string& prop
logger_->log_debug("Found property {}", property_name);
- if (!component.updateProperty(property_name, rawValueString)) {
- auto proc = dynamic_cast<core::Connectable*>(&component);
- if (proc) {
- logger_->log_warn("Received property {} with value {} but is not one
of the properties for {}. Attempting to add as dynamic property.",
property_name, rawValueString, proc->getName());
- if (!component.updateDynamicProperty(property_name, rawValueString))
{
- logger_->log_warn("Unable to set the dynamic property {}",
property_name);
- } else {
- logger_->log_warn("Dynamic property {} has been set",
property_name);
- }
+ const auto append_prop_result = component.appendProperty(property_name,
rawValueString);
+ if (!append_prop_result && append_prop_result.error() ==
make_error_code(PropertyErrorCode::NotSupportedProperty)) {
+ logger_->log_warn("Received property {} with value {} but is not one
of the properties for {}. Attempting to add as dynamic property.",
property_name, rawValueString, component.getName());
+ if (!component.appendDynamicProperty(property_name, rawValueString)) {
+ logger_->log_warn("Unable to set the dynamic property {}",
property_name);
+ } else {
+ logger_->log_warn("Dynamic property {} has been set", property_name);
}
}
}
}
}
-PropertyValue
StructuredConfiguration::getValidatedProcessorPropertyForDefaultTypeInfo(const
core::Property& property_from_processor, const Node& property_value_node,
+std::optional<std::string>
StructuredConfiguration::getReplacedParametersValueOrDefault(const
std::string_view property_name,
+ const bool is_sensitive,
+ const std::optional<std::string_view> default_value,
+ const Node& property_value_node,
ParameterContext* parameter_context) {
- using state::response::Value;
- PropertyValue defaultValue;
- defaultValue = property_from_processor.getDefaultValue();
- const std::type_index defaultType = defaultValue.getTypeInfo();
try {
- PropertyValue coercedValue = defaultValue;
- auto int64_val = property_value_node.getInt64();
- if (defaultType == Value::INT64_TYPE && int64_val) {
- coercedValue = gsl::narrow<int64_t>(int64_val.value());
- } else if (defaultType == Value::UINT64_TYPE && int64_val) {
- coercedValue = gsl::narrow<uint64_t>(int64_val.value());
- } else if (defaultType == Value::UINT32_TYPE && int64_val) {
- coercedValue = gsl::narrow<uint32_t>(int64_val.value());
- } else if (defaultType == Value::INT_TYPE && int64_val) {
- coercedValue = gsl::narrow<int>(int64_val.value());
- } else if (defaultType == Value::BOOL_TYPE &&
property_value_node.getBool()) {
- coercedValue = property_value_node.getBool().value();
+ std::unique_ptr<core::ParameterTokenParser> token_parser;
+ std::string property_value_string;
+ if (is_sensitive) {
+ property_value_string =
utils::crypto::property_encryption::decrypt(property_value_node.getScalarAsString().value(),
sensitive_values_encryptor_);
+ token_parser =
std::make_unique<core::SensitiveParameterTokenParser>(std::move(property_value_string),
sensitive_values_encryptor_);
} else {
- std::string property_value_string;
- std::unique_ptr<core::ParameterTokenParser> token_parser;
- if (property_from_processor.isSensitive()) {
- property_value_string =
utils::crypto::property_encryption::decrypt(property_value_node.getScalarAsString().value(),
sensitive_values_encryptor_);
- token_parser =
std::make_unique<core::SensitiveParameterTokenParser>(property_value_string,
sensitive_values_encryptor_);
- } else {
- property_value_string =
property_value_node.getScalarAsString().value();
- token_parser =
std::make_unique<core::NonSensitiveParameterTokenParser>(property_value_string);
- }
- property_value_string =
token_parser->replaceParameters(parameter_context);
- coercedValue = property_value_string;
+ property_value_string = property_value_node.getScalarAsString().value();
+ token_parser =
std::make_unique<core::NonSensitiveParameterTokenParser>(std::move(property_value_string));
}
- return coercedValue;
+ auto replaced_property_value_string =
token_parser->replaceParameters(parameter_context);
+ return replaced_property_value_string;
} catch (const utils::crypto::EncryptionError& e) {
logger_->log_error("Fetching property failed with a decryption error: {}",
e.what());
throw;
} catch (const ParameterException& e) {
- logger_->log_error("Error while substituting parameters in property '{}':
{}", property_from_processor.getName(), e.what());
+ logger_->log_error("Error while substituting parameters in property '{}':
{}", property_name, e.what());
throw;
} catch (const std::exception& e) {
logger_->log_error("Fetching property failed with an exception of {}",
e.what());
- logger_->log_error("Invalid conversion for field {}. Value {}",
property_from_processor.getName(), property_value_node.getDebugString());
+ logger_->log_error("Invalid conversion for field {}. Value {}",
property_name, property_value_node.getDebugString());
} catch (...) {
- logger_->log_error("Invalid conversion for field {}. Value {}",
property_from_processor.getName(), property_value_node.getDebugString());
+ logger_->log_error("Invalid conversion for field {}. Value {}",
property_name, property_value_node.getDebugString());
}
- return defaultValue;
+ return default_value | utils::transform([](const std::string_view def_value)
{ return std::string{def_value}; });
}
-void StructuredConfiguration::parseSingleProperty(const std::string&
property_name, const Node& property_value_node, core::ConfigurableComponent&
processor,
+void StructuredConfiguration::parseSingleProperty(const std::string&
property_name, const Node& property_value_node, core::ConfigurableComponent&
component,
ParameterContext* parameter_context) {
- core::Property myProp(property_name, "", "");
- processor.getProperty(property_name, myProp);
-
- PropertyValue coercedValue =
getValidatedProcessorPropertyForDefaultTypeInfo(myProp, property_value_node,
parameter_context);
+ auto my_prop = component.getPropertyReference(property_name);
+ const bool is_sensitive = my_prop ? my_prop->is_sensitive : false;
+ const std::optional<std::string_view> default_value = my_prop ?
my_prop->default_value : std::nullopt;
- bool property_set = false;
- try {
- property_set = processor.setProperty(myProp, coercedValue);
- } catch(const utils::internal::InvalidValueException&) {
- auto component = dynamic_cast<core::CoreComponent*>(&processor);
- if (component == nullptr) {
- logger_->log_error("processor was not a CoreComponent for property
'{}'", property_name);
- } else {
- logger_->log_error("Invalid value was set for property '{}' creating
component '{}'", property_name, component->getName());
- }
- throw;
+ const auto value_to_set = getReplacedParametersValueOrDefault(property_name,
is_sensitive, default_value, property_value_node, parameter_context);
+ if (!value_to_set) {
+ return;
}
- if (!property_set) {
- const auto rawValueString = coercedValue.getValue()->getStringValue();
- auto proc = dynamic_cast<core::Connectable*>(&processor);
- if (proc) {
- logger_->log_warn("Received property {} but is not one of the properties
for {}. Attempting to add as dynamic property.", property_name,
proc->getName());
- if (!processor.setDynamicProperty(property_name, rawValueString)) {
- logger_->log_warn("Unable to set the dynamic property {}",
property_name);
- } else {
- logger_->log_warn("Dynamic property {} has been set", property_name);
- }
+ if (my_prop) {
+ const auto prop_set = component.setProperty(property_name, *value_to_set);
+ if (!prop_set) {
+ logger_->log_error("Invalid value was set for property '{}' creating
component '{}'", property_name, component.getName());
+ raiseComponentError(component.getName(), "", prop_set.error().message());
Review Comment:
We shouldnt get NotSupported here because we previously check if the
property is supported.
--
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]