forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_data_fetcher.h
85 lines (70 loc) · 2.25 KB
/
remote_data_fetcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "envoy/common/pure.h"
#include "envoy/config/core/v3/http_uri.pb.h"
#include "envoy/upstream/cluster_manager.h"
namespace Envoy {
namespace Config {
namespace DataFetcher {
/**
* Failure reason.
*/
enum class FailureReason {
/* A network error occurred causing remote data retrieval failure. */
Network,
/* A failure occurred when trying to verify remote data using sha256. */
InvalidData,
};
/**
* Callback used by remote data fetcher.
*/
class RemoteDataFetcherCallback {
public:
virtual ~RemoteDataFetcherCallback() = default;
/**
* This function will be called when data is fetched successfully from remote.
* @param data remote data
*/
virtual void onSuccess(const std::string& data) PURE;
/**
* This function is called when error happens during fetching data.
* @param reason failure reason.
*/
virtual void onFailure(FailureReason reason) PURE;
};
/**
* Remote data fetcher.
*/
class RemoteDataFetcher : public Logger::Loggable<Logger::Id::config>,
public Http::AsyncClient::Callbacks {
public:
RemoteDataFetcher(Upstream::ClusterManager& cm, const envoy::config::core::v3::HttpUri& uri,
const std::string& content_hash, RemoteDataFetcherCallback& callback);
~RemoteDataFetcher() override;
// Http::AsyncClient::Callbacks
void onSuccess(const Http::AsyncClient::Request&, Http::ResponseMessagePtr&& response) override;
void onFailure(const Http::AsyncClient::Request&,
Http::AsyncClient::FailureReason reason) override;
void onBeforeFinalizeUpstreamSpan(Envoy::Tracing::Span&,
const Http::ResponseHeaderMap*) override {}
/**
* Fetch data from remote.
* @param uri remote URI
* @param content_hash for verifying data integrity
* @param callback callback when fetch is done.
*/
void fetch();
/**
* Cancel the fetch.
*/
void cancel();
private:
Upstream::ClusterManager& cm_;
const envoy::config::core::v3::HttpUri uri_;
const std::string content_hash_;
RemoteDataFetcherCallback& callback_;
Http::AsyncClient::Request* request_{};
};
using RemoteDataFetcherPtr = std::unique_ptr<RemoteDataFetcher>;
} // namespace DataFetcher
} // namespace Config
} // namespace Envoy