LCOV - code coverage report
Current view: top level - envoy/protobuf - message_validator.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 3 4 75.0 %
Date: 2024-01-05 06:35:25 Functions: 3 4 75.0 %

          Line data    Source code
       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             :  * Exception class for reporting validation errors due to the presence of unknown
      17             :  * fields in a protobuf.
      18             :  */
      19             : class UnknownProtoFieldException : public EnvoyException {
      20             : public:
      21          22 :   UnknownProtoFieldException(const std::string& message) : EnvoyException(message) {}
      22             : };
      23             : 
      24             : /**
      25             :  * Exception class for reporting validation errors due to the presence of deprecated
      26             :  * fields in a protobuf.
      27             :  */
      28             : class DeprecatedProtoFieldException : public EnvoyException {
      29             : public:
      30           0 :   DeprecatedProtoFieldException(const std::string& message) : EnvoyException(message) {}
      31             : };
      32             : 
      33             : /**
      34             :  * Visitor interface for a Protobuf::Message. The methods of ValidationVisitor are invoked to
      35             :  * perform validation based on events encountered during or after the parsing of proto binary
      36             :  * or JSON/YAML.
      37             :  */
      38             : class ValidationVisitor {
      39             : public:
      40        2557 :   virtual ~ValidationVisitor() = default;
      41             : 
      42             :   /**
      43             :    * Invoked when an unknown field is encountered.
      44             :    * @param description human readable description of the field.
      45             :    */
      46             :   virtual void onUnknownField(absl::string_view description) PURE;
      47             : 
      48             :   /**
      49             :    * If true, skip this validation visitor in the interest of speed when
      50             :    * possible.
      51             :    **/
      52             :   virtual bool skipValidation() PURE;
      53             : 
      54             :   /**
      55             :    * Invoked when deprecated field is encountered.
      56             :    * @param description human readable description of the field.
      57             :    * @param soft_deprecation is set to true, visitor would log a warning message, otherwise would
      58             :    * throw an exception.
      59             :    */
      60             :   virtual void onDeprecatedField(absl::string_view description, bool soft_deprecation) PURE;
      61             : 
      62             :   /**
      63             :    * Called when a message or field is marked as work in progress or a message is contained in a
      64             :    * proto file marked as work in progress.
      65             :    */
      66             :   virtual void onWorkInProgress(absl::string_view description) PURE;
      67             : 
      68             :   /**
      69             :    * Called to update runtime stats on deprecated fields.
      70             :    */
      71             :   virtual OptRef<Runtime::Loader> runtime() PURE;
      72             : };
      73             : 
      74             : class ValidationContext {
      75             : public:
      76         481 :   virtual ~ValidationContext() = default;
      77             : 
      78             :   /**
      79             :    * @return ValidationVisitor& the validation visitor for static configuration.
      80             :    */
      81             :   virtual ValidationVisitor& staticValidationVisitor() PURE;
      82             : 
      83             :   /**
      84             :    * @return ValidationVisitor& the validation visitor for dynamic configuration.
      85             :    */
      86             :   virtual ValidationVisitor& dynamicValidationVisitor() PURE;
      87             : };
      88             : 
      89             : } // namespace ProtobufMessage
      90             : } // namespace Envoy

Generated by: LCOV version 1.15