Also check for users.xml elements in config.xml

This commit is contained in:
Alexey Milovidov 2020-06-04 23:33:19 +03:00
parent a89ce20d38
commit 02e14f9fe8

View File

@ -214,7 +214,7 @@ void Server::defineOptions(Poco::Util::OptionSet & options)
/// Check that there is no user-level settings at the top level in config. /// Check that there is no user-level settings at the top level in config.
/// This is a common source of mistake (user don't know where to write user-level setting). /// This is a common source of mistake (user don't know where to write user-level setting).
void checkForIncorrectSettings(const Poco::Util::AbstractConfiguration & config, const std::string & path) void checkForUserSettingsAtTopLevel(const Poco::Util::AbstractConfiguration & config, const std::string & path)
{ {
if (config.getBool("skip_check_for_incorrect_settings", false)) if (config.getBool("skip_check_for_incorrect_settings", false))
return; return;
@ -236,6 +236,21 @@ void checkForIncorrectSettings(const Poco::Util::AbstractConfiguration & config,
} }
} }
void checkForUsersNotInMainConfig(
const Poco::Util::AbstractConfiguration & config,
const std::string & config_path,
const std::string & users_config_path,
Poco::Logger * log)
{
if (config.getBool("skip_check_for_incorrect_settings", false))
return;
if (config.has("users") || config.has("profiles") || config.has("quotas"))
LOG_ERROR(log, "The <users>, <profiles> and <quotas> elements should be located in users config file: {} not in main config {}."
" Also note that you should place configuration changes to the appropriate *.d directory like 'users.d'.",
users_config_path, config_path);
}
int Server::main(const std::vector<std::string> & /*args*/) int Server::main(const std::vector<std::string> & /*args*/)
{ {
@ -296,7 +311,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
config().add(loaded_config.configuration.duplicate(), PRIO_DEFAULT, false); config().add(loaded_config.configuration.duplicate(), PRIO_DEFAULT, false);
} }
checkForIncorrectSettings(config(), config_path); checkForUserSettingsAtTopLevel(config(), config_path);
const auto memory_amount = getMemoryAmount(); const auto memory_amount = getMemoryAmount();
@ -510,7 +525,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
main_config_zk_changed_event, main_config_zk_changed_event,
[&](ConfigurationPtr config) [&](ConfigurationPtr config)
{ {
checkForIncorrectSettings(*config, config_path); checkForUserSettingsAtTopLevel(*config, config_path);
// FIXME logging-related things need synchronization -- see the 'Logger * log' saved // FIXME logging-related things need synchronization -- see the 'Logger * log' saved
// in a lot of places. For now, disable updating log configuration without server restart. // in a lot of places. For now, disable updating log configuration without server restart.
@ -540,6 +555,10 @@ int Server::main(const std::vector<std::string> & /*args*/)
if (Poco::File(config_dir + users_config_path).exists()) if (Poco::File(config_dir + users_config_path).exists())
users_config_path = config_dir + users_config_path; users_config_path = config_dir + users_config_path;
} }
if (users_config_path != config_path)
checkForUsersNotInMainConfig(config(), config_path, users_config_path, log);
auto users_config_reloader = std::make_unique<ConfigReloader>( auto users_config_reloader = std::make_unique<ConfigReloader>(
users_config_path, users_config_path,
include_from_path, include_from_path,
@ -549,7 +568,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
[&](ConfigurationPtr config) [&](ConfigurationPtr config)
{ {
global_context->setUsersConfig(config); global_context->setUsersConfig(config);
checkForIncorrectSettings(*config, users_config_path); checkForUserSettingsAtTopLevel(*config, users_config_path);
}, },
/* already_loaded = */ false); /* already_loaded = */ false);