1
#pragma once
2

            
3
#include "envoy/common/callback.h"
4
#include "envoy/common/pure.h"
5

            
6
#include "absl/strings/string_view.h"
7
#include "xds/core/v3/context_params.pb.h"
8

            
9
namespace Envoy {
10
namespace Config {
11

            
12
/**
13
 * A provider for xDS context parameters. These are currently derived from the bootstrap, but will
14
 * be set dynamically at runtime in the near future as we add support for dynamic context parameter
15
 * discovery and updates.
16
 *
17
 * In general, this is intended to be used only on the main thread, as part of the Server instance
18
 * interface and config subsystem.
19
 */
20
class ContextProvider {
21
public:
22
  /**
23
   * Callback type for when dynamic context changes. The argument provides the resource type URL for
24
   * the update.
25
   */
26
  using UpdateNotificationCb = std::function<absl::Status(absl::string_view)>;
27

            
28
55480
  virtual ~ContextProvider() = default;
29

            
30
  /**
31
   * @return const xds::core::v3::ContextParams& static node-level context parameters.
32
   */
33
  virtual const xds::core::v3::ContextParams& nodeContext() const PURE;
34

            
35
  /**
36
   * @param resource_type_url resource type URL for context parameters.
37
   * @return const xds::core::v3::ContextParams& dynamic node-level context parameters.
38
   */
39
  virtual const xds::core::v3::ContextParams&
40
  dynamicContext(absl::string_view resource_type_url) const PURE;
41

            
42
  /**
43
   * Set a dynamic context parameter.
44
   * @param resource_type_url resource type URL for context parameter.
45
   * @param key parameter key.
46
   * @param value parameter value.
47
   * @return if the update was successful.
48
   */
49
  virtual absl::Status setDynamicContextParam(absl::string_view resource_type_url,
50
                                              absl::string_view key, absl::string_view value) PURE;
51

            
52
  /**
53
   * Unset a dynamic context parameter.
54
   * @param resource_type_url resource type URL for context parameter.
55
   * @param key parameter key.
56
   * @return if the update was successful.
57
   */
58
  virtual absl::Status unsetDynamicContextParam(absl::string_view resource_type_url,
59
                                                absl::string_view key) PURE;
60

            
61
  /**
62
   * Register a callback for notification when the dynamic context changes.
63
   * @param callback notification callback.
64
   * @return Common::CallbackHandlePtr callback handle for removal.
65
   */
66
  ABSL_MUST_USE_RESULT virtual Common::CallbackHandlePtr
67
  addDynamicContextUpdateCallback(UpdateNotificationCb callback) const PURE;
68
};
69

            
70
} // namespace Config
71
} // namespace Envoy