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 {
38 public:
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> removed;
48 Timestamp timestamp;
49
50 bool IsEmpty() const { return docs_map.Size() == 0 && removed.empty(); }
51 };
52
53 struct JsonReply {
54 formats::json::Value configs;
55 Timestamp timestamp;
56 };
57
58 Reply DownloadFullDocsMap();
59
60 Reply FetchDocsMap(const std::optional<Timestamp>& last_update,
61 const std::vector<std::string>& fields_to_load);
62
63 JsonReply FetchJson(const std::optional<Timestamp>& last_update,
64 const std::vector<std::string>& fields_to_load);
65
66 private:
67 formats::json::Value FetchConfigs(
68 const std::optional<Timestamp>& last_update,
69 const std::vector<std::string>& fields_to_load);
70
71 std::string FetchConfigsValues(std::string_view body);
72
73 const ClientConfig config_;
74 clients::http::Client& http_client_;
75};
76
77} // namespace dynamic_config
78
79USERVER_NAMESPACE_END