| 958 | } |
| 959 | |
| 960 | void ConfigProcessor::savePreprocessedConfig(LoadedConfig & loaded_config, std::string preprocessed_dir |
| 961 | #if USE_SSL |
| 962 | , bool skip_zk_encryption_keys |
| 963 | #endif |
| 964 | ) |
| 965 | { |
| 966 | try |
| 967 | { |
| 968 | if (preprocessed_path.empty()) |
| 969 | { |
| 970 | fs::path preprocessed_configs_path("preprocessed_configs/"); |
| 971 | auto new_path = loaded_config.config_path; |
| 972 | if (new_path.starts_with(main_config_path)) |
| 973 | new_path.erase(0, main_config_path.size()); |
| 974 | std::replace(new_path.begin(), new_path.end(), '/', '_'); |
| 975 | |
| 976 | /// If we have config file in YAML format, the preprocessed config will inherit .yaml extension |
| 977 | /// but will contain config in XML format, so some tools like clickhouse extract-from-config won't work |
| 978 | new_path = fs::path(new_path).replace_extension(".xml").string(); |
| 979 | |
| 980 | if (preprocessed_dir.empty()) |
| 981 | { |
| 982 | if (!loaded_config.configuration->has("path")) |
| 983 | { |
| 984 | // Will use current directory |
| 985 | fs::path parent_path = fs::path(loaded_config.config_path).parent_path(); |
| 986 | preprocessed_dir = parent_path.string(); |
| 987 | fs::path fs_new_path(new_path); |
| 988 | fs_new_path.replace_filename(fs_new_path.stem().string() + PREPROCESSED_SUFFIX + fs_new_path.extension().string()); |
| 989 | new_path = fs_new_path.string(); |
| 990 | } |
| 991 | else |
| 992 | { |
| 993 | fs::path loaded_config_path(loaded_config.configuration->getString("path")); |
| 994 | preprocessed_dir = loaded_config_path / preprocessed_configs_path; |
| 995 | } |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | fs::path preprocessed_dir_path(preprocessed_dir); |
| 1000 | preprocessed_dir = (preprocessed_dir_path / preprocessed_configs_path).string(); |
| 1001 | } |
| 1002 | |
| 1003 | preprocessed_path = (fs::path(preprocessed_dir) / fs::path(new_path)).string(); |
| 1004 | auto preprocessed_path_parent = fs::path(preprocessed_path).parent_path(); |
| 1005 | if (!preprocessed_path_parent.empty()) |
| 1006 | fs::create_directories(preprocessed_path_parent); |
| 1007 | } |
| 1008 | DOMWriter writer; |
| 1009 | writer.setNewLine("\n"); |
| 1010 | writer.setIndent(" "); |
| 1011 | writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT); |
| 1012 | XMLDocumentPtr preprocessed_xml_without_hidden_elements = hideElements(loaded_config.preprocessed_xml); |
| 1013 | writer.writeNode(preprocessed_path, preprocessed_xml_without_hidden_elements); |
| 1014 | LOG_DEBUG(log, "Saved preprocessed configuration to '{}'.", preprocessed_path); |
| 1015 | } |
| 1016 | catch (Poco::Exception & e) |
| 1017 | { |
no test coverage detected