userver: userver/dynamic_config/client/client.hpp Source File
Loading...
Searching...
No Matches
client.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dynamic_config/client/client.hpp
4/// @brief @copybrief dynamic_config::Client
5
6#include <chrono>
7#include <optional>
8
9#include <userver/dynamic_config/value.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace clients::http {
14class Client;
15} // namespace clients::http
16
17namespace dynamic_config {
18
20 std::string service_name;
21 bool get_configs_overrides_for_service{true};
22 std::chrono::milliseconds timeout{0};
23 int retries{1};
24 std::string config_url;
25 bool append_path_to_url{true};
26 std::string stage_name;
27 bool fallback_to_no_proxy{true};
28};
29
30/// @ingroup userver_clients
31///
32/// @brief Client for the
33/// @ref scripts/docs/en/userver/dynamic_config.md "dynamic configs" service.
34///
35/// It is safe to concurrently invoke members of the same client because this
36/// client is a thin wrapper around clients::http::Client.
37class Client final {
38public:
39 Client(clients::http::Client& http_client, const ClientConfig&);
40
41 ~Client();
42
43 using Timestamp = std::string;
44
45 struct Reply {
46 USERVER_NAMESPACE::dynamic_config::DocsMap docs_map;
47 std::vector<std::string> kill_switches_disabled;
48 std::vector<std::string> removed;
49 Timestamp timestamp;
50
51 bool IsEmpty() const { return docs_map.Size() == 0 && removed.empty(); }
52 };
53
54 struct JsonReply {
55 formats::json::Value configs;
56 std::vector<std::string> kill_switches_disabled;
57 Timestamp timestamp;
58 };
59
60 Reply DownloadFullDocsMap();
61
62 Reply FetchDocsMap(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
63
64 JsonReply FetchJson(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
65
66private:
67 formats::json::Value
68 FetchConfigs(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
69
70 std::string FetchConfigsValues(std::string_view body);
71
72 const ClientConfig config_;
73 clients::http::Client& http_client_;
74};
75
76} // namespace dynamic_config
77
78USERVER_NAMESPACE_END