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_;
78class SecdistConfig
final {
86 explicit SecdistConfig(
const Settings& settings);
89 static std::size_t Register(
90 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);
100 void Init(
const formats::
json::Value& doc);
102 static std::size_t Register(
103 std::function<std::any(
const formats::
json::Value&)>&& factory);
104 const std::any& Get(
const std::type_index& type, std::size_t index)
const;
106 template <
typename T>
107 friend class detail::SecdistModule;
109 std::vector<std::any> configs_;
118 explicit Secdist(SecdistConfig::
Settings settings);
132 template <
typename Class>
134 Class* obj, std::string_view name,
137 bool IsPeriodicUpdateEnabled()
const;
140 using EventSource =
concurrent::AsyncEventSource<
const SecdistConfig&>;
142 concurrent::AsyncEventSubscriberScope DoUpdateAndListen(
143 concurrent::FunctionId id, std::string_view name,
144 EventSource::Function&& func);
147 utils::FastPimpl<Impl, 1280, 16> impl_;
150template <
typename Class>
152 Class* obj, std::string_view name,
153 void (Class::*func)(
const storages::
secdist::SecdistConfig& secdist)) {
154 return DoUpdateAndListen(
155 concurrent::FunctionId(obj), name,
156 [obj, func](
const SecdistConfig& config) { (obj->*func)(config); });
162const T& SecdistModule<T>::Get(
const SecdistConfig& config) {
163 return std::any_cast<
const T&>(config.Get(
typeid(T), index_));
167std::size_t SecdistModule<T>::index_ =
168 SecdistConfig::Register<T>(&SecdistModule<T>::Factory);