szaszm commented on code in PR #1725: URL: https://github.com/apache/nifi-minifi-cpp/pull/1725#discussion_r1523587236
########## encrypt-config/FlowConfigEncryptor.cpp: ########## @@ -0,0 +1,174 @@ +/** + * 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 "FlowConfigEncryptor.h" + +#include "core/extension/ExtensionManager.h" +#include "core/FlowConfiguration.h" +#include "core/flow/AdaptiveConfiguration.h" +#include "core/ProcessGroup.h" +#include "core/RepositoryFactory.h" +#include "core/repository/VolatileContentRepository.h" +#include "Defaults.h" +#include "Utils.h" +#include "utils/file/FileSystem.h" +#include "utils/Id.h" + +namespace minifi = org::apache::nifi::minifi; + +namespace { +enum class Type { + Processor, + ControllerService +}; + +struct SensitiveProperty { + Type type; + minifi::utils::Identifier component_id; + std::string component_name; + std::string property_name; + std::string property_display_name; +}; +} // namespace + +namespace magic_enum::customize { +template<> +constexpr customize_t enum_name<Type>(Type type) noexcept { + switch (type) { + case Type::Processor: return "Processor"; + case Type::ControllerService: return "Controller service"; + } + return invalid_tag; +} +} // namespace magic_enum::customize + +namespace { +std::vector<SensitiveProperty> listSensitiveProperties(const minifi::core::ProcessGroup &process_group) { + std::vector<SensitiveProperty> sensitive_properties; + + std::vector<minifi::core::Processor *> processors; + process_group.getAllProcessors(processors); + for (const auto *processor : processors) { + gsl_Expects(processor); + for (const auto& [_, property] : processor->getProperties()) { + if (property.isSensitive()) { + sensitive_properties.push_back(SensitiveProperty{ + .type = Type::Processor, + .component_id = processor->getUUID(), + .component_name = processor->getName(), + .property_name = property.getName(), + .property_display_name = property.getDisplayName()}); + } + } + } + + for (const auto* controller_service_node : process_group.getAllControllerServices()) { + gsl_Expects(controller_service_node); + const auto* controller_service = controller_service_node->getControllerServiceImplementation(); + gsl_Expects(controller_service); + for (const auto& [_, property] : controller_service->getProperties()) { + if (property.isSensitive()) { + sensitive_properties.push_back(SensitiveProperty{ + .type = Type::ControllerService, + .component_id = controller_service->getUUID(), + .component_name = controller_service->getName(), + .property_name = property.getName(), + .property_display_name = property.getDisplayName()}); + } + } + } + + return sensitive_properties; +} + +template<typename Func> +void encryptSensitiveValuesInFlowConfigImpl( + const minifi::encrypt_config::EncryptionKeys& keys, const std::filesystem::path& minifi_home, const std::filesystem::path& flow_config_path, Func create_overrides) { + const auto configure = std::make_shared<minifi::Configure>(); + configure->setHome(minifi_home); + configure->loadConfigureFile(DEFAULT_NIFI_PROPERTIES_FILE); + + bool encrypt_whole_flow_config_file = (configure->get(minifi::Configure::nifi_flow_configuration_encrypt) | minifi::utils::andThen(minifi::utils::string::toBool)).value_or(false); + auto encryptor = encrypt_whole_flow_config_file ? minifi::utils::crypto::EncryptionProvider::create(minifi_home) : std::nullopt; + auto filesystem = std::make_shared<minifi::utils::file::FileSystem>(encrypt_whole_flow_config_file, encryptor); + + minifi::core::extension::ExtensionManager::get().initialize(configure); + + minifi::core::flow::AdaptiveConfiguration adaptive_configuration{minifi::core::ConfigurationContext{ + .flow_file_repo = minifi::core::createRepository("flowfilerepository"), + .content_repo = std::make_shared<minifi::core::repository::VolatileContentRepository>(), Review Comment: Would this work with passing null or NoopRepository? I don't think we need repositories for modifying the config. -- 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org