1
#pragma once
2

            
3
#include "envoy/common/exception.h"
4
#include "envoy/common/optref.h"
5
#include "envoy/common/pure.h"
6
#include "envoy/runtime/runtime.h"
7

            
8
#include "source/common/protobuf/protobuf.h"
9

            
10
#include "absl/strings/string_view.h"
11

            
12
namespace Envoy {
13
namespace ProtobufMessage {
14

            
15
/**
16
 * Visitor interface for a Protobuf::Message. The methods of ValidationVisitor are invoked to
17
 * perform validation based on events encountered during or after the parsing of proto binary
18
 * or JSON/YAML.
19
 */
20
class ValidationVisitor {
21
public:
22
134188
  virtual ~ValidationVisitor() = default;
23

            
24
  /**
25
   * Invoked when an unknown field is encountered.
26
   * @param description human readable description of the field.
27
   * @return a status indicating if an unknown field was found.
28
   */
29
  virtual absl::Status onUnknownField(absl::string_view description) PURE;
30

            
31
  /**
32
   * If true, skip this validation visitor in the interest of speed when
33
   * possible.
34
   **/
35
  virtual bool skipValidation() PURE;
36

            
37
  /**
38
   * Invoked when deprecated field is encountered.
39
   * @param description human readable description of the field.
40
   * @param soft_deprecation is set to true, visitor would log a warning message, otherwise would
41
   * return an error
42
   */
43
  virtual absl::Status onDeprecatedField(absl::string_view description, bool soft_deprecation) PURE;
44

            
45
  /**
46
   * Called when a message or field is marked as work in progress or a message is contained in a
47
   * proto file marked as work in progress.
48
   */
49
  virtual void onWorkInProgress(absl::string_view description) PURE;
50

            
51
  /**
52
   * Called to update runtime stats on deprecated fields.
53
   */
54
  virtual OptRef<Runtime::Loader> runtime() PURE;
55
};
56

            
57
class ValidationContext {
58
public:
59
50950
  virtual ~ValidationContext() = default;
60

            
61
  /**
62
   * @return ValidationVisitor& the validation visitor for static configuration.
63
   */
64
  virtual ValidationVisitor& staticValidationVisitor() PURE;
65

            
66
  /**
67
   * @return ValidationVisitor& the validation visitor for dynamic configuration.
68
   */
69
  virtual ValidationVisitor& dynamicValidationVisitor() PURE;
70
};
71

            
72
} // namespace ProtobufMessage
73
} // namespace Envoy