2019-11-09 15:33:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Access/MemoryAccessStorage.h>
|
2020-08-05 19:54:06 +00:00
|
|
|
#include <Common/ZooKeeper/Common.h>
|
2019-11-09 15:33:07 +00:00
|
|
|
|
|
|
|
|
2020-08-05 19:54:06 +00:00
|
|
|
namespace Poco::Util
|
2019-11-09 15:33:07 +00:00
|
|
|
{
|
2020-08-05 19:54:06 +00:00
|
|
|
class AbstractConfiguration;
|
2019-11-09 15:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-08-05 19:54:06 +00:00
|
|
|
class ConfigReloader;
|
|
|
|
|
2019-11-09 15:33:07 +00:00
|
|
|
/// Implementation of IAccessStorage which loads all from users.xml periodically.
|
|
|
|
class UsersConfigAccessStorage : public IAccessStorage
|
|
|
|
{
|
|
|
|
public:
|
2020-08-05 19:54:06 +00:00
|
|
|
static constexpr char STORAGE_TYPE[] = "users.xml";
|
|
|
|
using CheckSettingNameFunction = std::function<void(const std::string_view &)>;
|
|
|
|
|
|
|
|
UsersConfigAccessStorage(const String & storage_name_ = STORAGE_TYPE, const CheckSettingNameFunction & check_setting_name_function_ = {});
|
|
|
|
UsersConfigAccessStorage(const CheckSettingNameFunction & check_setting_name_function_);
|
|
|
|
~UsersConfigAccessStorage() override;
|
|
|
|
|
|
|
|
const char * getStorageType() const override { return STORAGE_TYPE; }
|
2020-08-12 14:22:37 +00:00
|
|
|
String getStoragePath() const override;
|
|
|
|
bool isStorageReadOnly() const override { return true; }
|
2019-11-09 15:33:07 +00:00
|
|
|
|
2020-08-05 19:54:06 +00:00
|
|
|
void setConfig(const Poco::Util::AbstractConfiguration & config);
|
|
|
|
|
|
|
|
void load(const String & users_config_path,
|
|
|
|
const String & include_from_path = {},
|
|
|
|
const String & preprocessed_dir = {},
|
|
|
|
const zkutil::GetZooKeeper & get_zookeeper_function = {});
|
|
|
|
void reload();
|
|
|
|
void startPeriodicReloading();
|
2019-11-09 15:33:07 +00:00
|
|
|
|
|
|
|
private:
|
2020-08-05 19:54:06 +00:00
|
|
|
void parseFromConfig(const Poco::Util::AbstractConfiguration & config);
|
|
|
|
|
2020-05-03 03:12:03 +00:00
|
|
|
std::optional<UUID> findImpl(EntityType type, const String & name) const override;
|
|
|
|
std::vector<UUID> findAllImpl(EntityType type) const override;
|
2019-11-09 15:33:07 +00:00
|
|
|
bool existsImpl(const UUID & id) const override;
|
|
|
|
AccessEntityPtr readImpl(const UUID & id) const override;
|
|
|
|
String readNameImpl(const UUID & id) const override;
|
2020-02-26 10:50:13 +00:00
|
|
|
bool canInsertImpl(const AccessEntityPtr &) const override { return false; }
|
2019-11-09 15:33:07 +00:00
|
|
|
UUID insertImpl(const AccessEntityPtr & entity, bool replace_if_exists) override;
|
|
|
|
void removeImpl(const UUID & id) override;
|
|
|
|
void updateImpl(const UUID & id, const UpdateFunc & update_func) override;
|
2020-01-29 15:51:12 +00:00
|
|
|
ext::scope_guard subscribeForChangesImpl(const UUID & id, const OnChangedHandler & handler) const override;
|
2020-05-03 03:12:03 +00:00
|
|
|
ext::scope_guard subscribeForChangesImpl(EntityType type, const OnChangedHandler & handler) const override;
|
2019-11-09 15:33:07 +00:00
|
|
|
bool hasSubscriptionImpl(const UUID & id) const override;
|
2020-05-03 03:12:03 +00:00
|
|
|
bool hasSubscriptionImpl(EntityType type) const override;
|
2019-11-09 15:33:07 +00:00
|
|
|
|
|
|
|
MemoryAccessStorage memory_storage;
|
2020-08-05 19:54:06 +00:00
|
|
|
CheckSettingNameFunction check_setting_name_function;
|
|
|
|
|
|
|
|
String path;
|
|
|
|
std::unique_ptr<ConfigReloader> config_reloader;
|
|
|
|
mutable std::mutex load_mutex;
|
2019-11-09 15:33:07 +00:00
|
|
|
};
|
|
|
|
}
|