| 209 | } |
| 210 | |
| 211 | void Client::initialize(Poco::Util::Application & self) |
| 212 | { |
| 213 | Poco::Util::Application::initialize(self); |
| 214 | |
| 215 | const char * home_path_cstr = getenv("HOME"); // NOLINT(concurrency-mt-unsafe) |
| 216 | if (home_path_cstr) |
| 217 | home_path = home_path_cstr; |
| 218 | |
| 219 | const char * env_host = getenv("CLICKHOUSE_HOST"); // NOLINT(concurrency-mt-unsafe) |
| 220 | |
| 221 | std::optional<std::string> config_path; |
| 222 | if (config().has("config-file")) |
| 223 | config_path.emplace(config().getString("config-file")); |
| 224 | else |
| 225 | config_path = getClientConfigPath(home_path); |
| 226 | if (config_path.has_value()) |
| 227 | { |
| 228 | ConfigProcessor config_processor(*config_path); |
| 229 | auto loaded_config = config_processor.loadConfig(); |
| 230 | auto & configuration = *loaded_config.configuration; |
| 231 | |
| 232 | std::string default_host; |
| 233 | if (!hosts_and_ports.empty()) |
| 234 | default_host = hosts_and_ports.front().host; |
| 235 | else if (config().has("host")) |
| 236 | default_host = config().getString("host"); |
| 237 | else if (configuration.has("host")) |
| 238 | default_host = configuration.getString("host"); |
| 239 | else if (env_host) |
| 240 | default_host = env_host; |
| 241 | else |
| 242 | default_host = "localhost"; |
| 243 | |
| 244 | std::optional<std::string> connection_name; |
| 245 | if (config().has("connection")) |
| 246 | connection_name.emplace(config().getString("connection")); |
| 247 | |
| 248 | /// Connection credentials overrides should be set via loaded_config.configuration to have proper order. |
| 249 | auto overrides = parseConnectionsCredentials(configuration, default_host, connection_name); |
| 250 | if (overrides.hostname.has_value()) |
| 251 | configuration.setString("host", overrides.hostname.value()); |
| 252 | if (overrides.port.has_value()) |
| 253 | configuration.setInt("port", overrides.port.value()); |
| 254 | if (overrides.secure.has_value()) |
| 255 | { |
| 256 | if (overrides.secure.value()) |
| 257 | configuration.setBool("secure", true); |
| 258 | else |
| 259 | configuration.setBool("no-secure", true); |
| 260 | } |
| 261 | if (overrides.user.has_value()) |
| 262 | configuration.setString("user", overrides.user.value()); |
| 263 | if (overrides.password.has_value()) |
| 264 | configuration.setString("password", overrides.password.value()); |
| 265 | if (overrides.database.has_value()) |
| 266 | configuration.setString("database", overrides.database.value()); |
| 267 | if (overrides.history_file.has_value()) |
| 268 | { |
no test coverage detected