17#include <userver/concurrent/async_event_source.hpp>
18#include <userver/engine/task/task_processor_fwd.hpp>
19#include <userver/formats/json/value.hpp>
20#include <userver/rcu/rcu.hpp>
21#include <userver/storages/secdist/provider.hpp>
22#include <userver/utils/fast_pimpl.hpp>
24USERVER_NAMESPACE_BEGIN
34class SecdistModule
final {
36 static const T& Get(
const SecdistConfig& config);
37 static std::any Factory(
const formats::
json::Value& data) {
return T(data); }
40 static std::size_t index_;
79class SecdistConfig
final {
87 explicit SecdistConfig(
const Settings& settings);
90 static std::size_t Register(std::function<std::any(
const formats::
json::Value&)>&& factory) {
91 return Register(std::move(factory));
95 const T& Get()
const {
96 return detail::SecdistModule<T>::Get(*
this);
102 static std::size_t Register(std::function<std::any(
const formats::
json::Value&)>&& factory);
103 const std::any& Get(
const std::type_index& type, std::size_t index)
const;
105 template <
typename T>
106 friend class detail::SecdistModule;
108 std::vector<std::any> configs_;
117 explicit Secdist(SecdistConfig::
Settings settings);
131 template <
typename Class>
134 std::string_view name,
135 void (Class::*func)(
const storages::
secdist::SecdistConfig& secdist)
138 bool IsPeriodicUpdateEnabled()
const;
141 using EventSource =
concurrent::AsyncEventSource<
const SecdistConfig&>;
144 DoUpdateAndListen(
concurrent::FunctionId id, std::string_view name, EventSource::Function&& func);
147 utils::FastPimpl<Impl, 1280, 16> impl_;
150template <
typename Class>
153 std::string_view name,
154 void (Class::*func)(
const storages::
secdist::SecdistConfig& secdist)
156 return DoUpdateAndListen(concurrent::FunctionId(obj), name, [obj, func](
const SecdistConfig& config) {
157 (obj->*func)(config);
164const T& SecdistModule<T>::Get(
const SecdistConfig& config) {
165 return std::any_cast<
const T&>(config.Get(
typeid(T), index_));
169std::size_t SecdistModule<T>::index_ = SecdistConfig::Register<T>(&SecdistModule<T>::Factory);