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#include <string>
9#include <vector>
10
11#include <userver/dynamic_config/value.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace clients::http {
16class Client;
17} // namespace clients::http
18
19namespace dynamic_config {
20
22 std::string service_name;
23 /// When true, sends `service`. Mutually exclusive with non-empty `service_overrides`.
25 std::chrono::milliseconds timeout{0};
26 int retries{1};
27 std::string config_url;
28 bool append_path_to_url{true};
29 std::string stage_name;
30 bool is_prestable{false};
31 std::string circuit;
32 /// Ordered service names sent as `service_overrides`. Mutually exclusive with `service`.
34};
35
36/// @ingroup userver_clients
37///
38/// @brief Client for the
39/// @ref scripts/docs/en/userver/dynamic_config.md "dynamic configs" service.
40///
41/// It is safe to concurrently invoke members of the same client because this
42/// client is a thin wrapper around @ref clients::http::Client.
43class Client final {
44public:
45 Client(clients::http::Client& http_client, const ClientConfig&);
46
47 ~Client();
48
49 using Timestamp = std::string;
50
51 struct Reply {
52 USERVER_NAMESPACE::dynamic_config::DocsMap docs_map;
53 std::vector<std::string> kill_switches_disabled;
54 std::vector<std::string> removed;
55 Timestamp timestamp;
56
57 bool IsEmpty() const { return docs_map.Size() == 0 && removed.empty(); }
58 };
59
60 struct JsonReply {
61 formats::json::Value configs;
62 std::vector<std::string> kill_switches_disabled;
63 Timestamp timestamp;
64 };
65
66 Reply DownloadFullDocsMap();
67
68 Reply FetchDocsMap(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
69
70 JsonReply FetchJson(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
71
72private:
73 formats::json::Value FetchConfigs(
74 const std::optional<Timestamp>& last_update,
75 const std::vector<std::string>& fields_to_load
76 );
77
78 std::string FetchConfigsValues(std::string_view body);
79
80 const ClientConfig config_;
81 clients::http::Client& http_client_;
82};
83
84} // namespace dynamic_config
85
86USERVER_NAMESPACE_END