This is an automated email from the ASF dual-hosted git repository. fgerlits pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit c59807878d9049915e5c32f196ad57eb32f821e1 Author: Gabor Gyimesi <[email protected]> AuthorDate: Wed Apr 13 13:57:01 2022 +0200 MINIFICPP-1796 Fix getting raw value of log properties Signed-off-by: Ferenc Gerlits <[email protected]> This closes #1301 --- .../http-curl/tests/C2DescribeManifestTest.cpp | 5 ++++ .../http-curl/tests/C2PropertiesUpdateTests.cpp | 7 +----- extensions/http-curl/tests/ConfigTestAccessor.h | 29 ++++++++++++++++++++++ extensions/http-curl/tests/HTTPHandlers.h | 2 +- libminifi/include/properties/Configure.h | 1 + libminifi/src/Configure.cpp | 29 ++++++++++++++-------- libminifi/src/FlowController.cpp | 2 +- libminifi/src/c2/C2Client.cpp | 2 +- 8 files changed, 57 insertions(+), 20 deletions(-) diff --git a/extensions/http-curl/tests/C2DescribeManifestTest.cpp b/extensions/http-curl/tests/C2DescribeManifestTest.cpp index 242800ee4..42e7d1aac 100644 --- a/extensions/http-curl/tests/C2DescribeManifestTest.cpp +++ b/extensions/http-curl/tests/C2DescribeManifestTest.cpp @@ -23,6 +23,7 @@ #include "HTTPIntegrationBase.h" #include "HTTPHandlers.h" #include "properties/Configuration.h" +#include "ConfigTestAccessor.h" class DescribeManifestHandler: public HeartbeatHandler { public: @@ -56,12 +57,16 @@ int main(int argc, char **argv) { harness.setKeyDir(args.key_dir); DescribeManifestHandler responder(harness.getConfiguration(), verified); + auto logger_properties = std::make_shared<core::logging::LoggerProperties>(); + ConfigTestAccessor::call_setLoggerProperties(harness.getConfiguration(), logger_properties); + harness.getConfiguration()->set(minifi::Configuration::nifi_rest_api_password, encrypted_value); harness.getConfiguration()->set(std::string(minifi::Configuration::nifi_rest_api_password) + ".protected", utils::crypto::EncryptionType::name()); harness.getConfiguration()->set(minifi::Configuration::nifi_server_name, "server_name"); harness.getConfiguration()->set(minifi::Configuration::nifi_framework_dir, "framework_path"); harness.getConfiguration()->set(minifi::Configuration::nifi_sensitive_props_additional_keys, std::string(minifi::Configuration::nifi_framework_dir) + ", " + std::string(minifi::Configuration::nifi_server_name)); + harness.getConfiguration()->set(minifi::Configuration::nifi_log_appender_rolling_directory, "/var/log/minifi"); harness.setUrl(args.url, &responder); harness.run(args.test_file); diff --git a/extensions/http-curl/tests/C2PropertiesUpdateTests.cpp b/extensions/http-curl/tests/C2PropertiesUpdateTests.cpp index d92497c0b..27773ddd6 100644 --- a/extensions/http-curl/tests/C2PropertiesUpdateTests.cpp +++ b/extensions/http-curl/tests/C2PropertiesUpdateTests.cpp @@ -28,6 +28,7 @@ #include "spdlog/sinks/dist_sink.h" #include "LogUtils.h" #include "properties/PropertiesFile.h" +#include "ConfigTestAccessor.h" struct PropertyChange { std::string name; @@ -116,12 +117,6 @@ namespace test { struct DummyClass3 {}; } // namespace test -struct ConfigTestAccessor { - static void call_setLoggerProperties(const std::shared_ptr<minifi::Configure>& config, std::shared_ptr<core::logging::LoggerProperties> props) { - config->setLoggerProperties(props); - } -}; - int main() { TempDirectory tmp_dir; diff --git a/extensions/http-curl/tests/ConfigTestAccessor.h b/extensions/http-curl/tests/ConfigTestAccessor.h new file mode 100644 index 000000000..e1dac61a0 --- /dev/null +++ b/extensions/http-curl/tests/ConfigTestAccessor.h @@ -0,0 +1,29 @@ +/** + * + * 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 "properties/Configure.h" +#include "core/logging/LoggerProperties.h" + +struct ConfigTestAccessor { + static void call_setLoggerProperties(const std::shared_ptr<minifi::Configure>& config, std::shared_ptr<core::logging::LoggerProperties> props) { + config->setLoggerProperties(props); + } +}; diff --git a/extensions/http-curl/tests/HTTPHandlers.h b/extensions/http-curl/tests/HTTPHandlers.h index 7bae42aed..cdba06fbe 100644 --- a/extensions/http-curl/tests/HTTPHandlers.h +++ b/extensions/http-curl/tests/HTTPHandlers.h @@ -562,7 +562,7 @@ class HeartbeatHandler : public ServerAwareHandler { std::unordered_map<std::string, std::string> config_property; if (ranges::find(disallowed_properties, property.name) == ranges::end(disallowed_properties)) { config_property.emplace("propertyName", property.name); - if (auto value = configuration_->getString(std::string(property.name))) { + if (auto value = configuration_->getRawValue(std::string(property.name))) { config_property.emplace("propertyValue", *value); } config_property.emplace("validator", property.validator->getName()); diff --git a/libminifi/include/properties/Configure.h b/libminifi/include/properties/Configure.h index 88b68787d..76d8b8fc2 100644 --- a/libminifi/include/properties/Configure.h +++ b/libminifi/include/properties/Configure.h @@ -42,6 +42,7 @@ class Configure : public Configuration, public core::AgentIdentificationProvider bool get(const std::string& key, std::string& value) const; bool get(const std::string& key, const std::string& alternate_key, std::string& value) const; std::optional<std::string> get(const std::string& key) const; + std::optional<std::string> getRawValue(const std::string& key) const; std::optional<std::string> getAgentClass() const override; std::string getAgentIdentifier() const override; diff --git a/libminifi/src/Configure.cpp b/libminifi/src/Configure.cpp index 2aa42e0b5..7067c2684 100644 --- a/libminifi/src/Configure.cpp +++ b/libminifi/src/Configure.cpp @@ -30,19 +30,14 @@ namespace nifi { namespace minifi { bool Configure::get(const std::string& key, std::string& value) const { - static constexpr std::string_view log_prefix = "nifi.log."; - if (utils::StringUtils::startsWith(key, log_prefix)) { - if (logger_properties_) { - return logger_properties_->getString(key.substr(log_prefix.length()), value); + if (auto opt_value = getRawValue(key)) { + value = *opt_value; + if (decryptor_ && isEncrypted(key)) { + value = decryptor_->decrypt(value); } - return false; - } - - bool found = getString(key, value); - if (decryptor_ && found && isEncrypted(key)) { - value = decryptor_->decrypt(value); + return true; } - return found; + return false; } bool Configure::get(const std::string& key, const std::string& alternate_key, std::string& value) const { @@ -69,6 +64,18 @@ std::optional<std::string> Configure::get(const std::string& key) const { return std::nullopt; } +std::optional<std::string> Configure::getRawValue(const std::string& key) const { + static constexpr std::string_view log_prefix = "nifi.log."; + if (utils::StringUtils::startsWith(key, log_prefix)) { + if (logger_properties_) { + return logger_properties_->getString(key.substr(log_prefix.length())); + } + return std::nullopt; + } + + return getString(key); +} + bool Configure::isEncrypted(const std::string& key) const { gsl_Expects(decryptor_); const auto encryption_marker = getString(key + ".protected"); diff --git a/libminifi/src/FlowController.cpp b/libminifi/src/FlowController.cpp index ef76b9f8c..25a1a4eb5 100644 --- a/libminifi/src/FlowController.cpp +++ b/libminifi/src/FlowController.cpp @@ -430,7 +430,7 @@ std::shared_ptr<state::response::ResponseNode> FlowController::getAgentManifest( agentInfo->setUpdatePolicyController(std::static_pointer_cast<controllers::UpdatePolicyControllerService>(getControllerService(c2::C2Agent::UPDATE_NAME)).get()); agentInfo->setAgentIdentificationProvider(configuration_); agentInfo->setConfigurationReader([this](const std::string& key){ - return configuration_->getString(key); + return configuration_->getRawValue(key); }); agentInfo->setStateMonitor(this); agentInfo->includeAgentStatus(false); diff --git a/libminifi/src/c2/C2Client.cpp b/libminifi/src/c2/C2Client.cpp index a4f7dd887..5eff01af9 100644 --- a/libminifi/src/c2/C2Client.cpp +++ b/libminifi/src/c2/C2Client.cpp @@ -117,7 +117,7 @@ void C2Client::initialize(core::controller::ControllerServiceProvider *controlle } if (agent_node != nullptr) { agent_node->setConfigurationReader([this](const std::string& key){ - return configuration_->getString(key); + return configuration_->getRawValue(key); }); } auto configuration_checksums = dynamic_cast<state::response::ConfigurationChecksums*>(response_node.get());
