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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <string>
       4             : #include <vector>
       5             : 
       6             : #include "envoy/common/optref.h"
       7             : #include "envoy/config/subscription.h"
       8             : #include "envoy/server/instance.h"
       9             : 
      10             : #include "source/common/protobuf/protobuf.h"
      11             : 
      12             : namespace Envoy {
      13             : namespace Config {
      14             : 
      15             : /**
      16             :  * The configuration validator interface. One can implement such validator
      17             :  * to add custom constraints to the fetched config, and reject a config
      18             :  * which violates these constraints.
      19             :  * The validators will be extensions that can be dynamically configured.
      20             :  *
      21             :  * A validator example: a validator that prevents removing all Clusters
      22             :  * from an Envoy (which may be caused by a bug in the config plane, and not
      23             :  * intentional change).
      24             :  */
      25             : class ConfigValidator {
      26             : public:
      27           0 :   virtual ~ConfigValidator() = default;
      28             : 
      29             :   /**
      30             :    * Validates a given set of resources matching a State-of-the-World update.
      31             :    * @param server A server instance to fetch the state before applying the config.
      32             :    * @param resources List of decoded resources that reflect the new state.
      33             :    * @throw EnvoyException if the config should be rejected.
      34             :    */
      35             :   virtual void validate(const Server::Instance& server,
      36             :                         const std::vector<DecodedResourcePtr>& resources) PURE;
      37             : 
      38             :   /**
      39             :    * Validates a given set of resources matching an Incremental update.
      40             :    * @param server A server instance to fetch the state before applying the config.
      41             :    * @param added_resources A list of decoded resources to add to the current state.
      42             :    * @param removed_resources A list of resources to remove from the current state.
      43             :    * @throw EnvoyException if the config should be rejected.
      44             :    */
      45             :   virtual void validate(const Server::Instance& server,
      46             :                         const std::vector<DecodedResourcePtr>& added_resources,
      47             :                         const Protobuf::RepeatedPtrField<std::string>& removed_resources) PURE;
      48             : };
      49             : 
      50             : using ConfigValidatorPtr = std::unique_ptr<ConfigValidator>;
      51             : 
      52             : /**
      53             :  * A factory abstract class for creating instances of ConfigValidators.
      54             :  */
      55             : class ConfigValidatorFactory : public Config::TypedFactory {
      56             : public:
      57           0 :   ~ConfigValidatorFactory() override = default;
      58             : 
      59             :   /**
      60             :    * Creates a ConfigValidator using the given config.
      61             :    */
      62             :   virtual ConfigValidatorPtr
      63             :   createConfigValidator(const ProtobufWkt::Any& config,
      64             :                         ProtobufMessage::ValidationVisitor& validation_visitor) PURE;
      65             : 
      66          46 :   std::string category() const override { return "envoy.config.validators"; }
      67             : 
      68             :   /**
      69             :    * Returns the xDS service type url that the config validator expects to receive.
      70             :    */
      71             :   virtual std::string typeUrl() const PURE;
      72             : };
      73             : 
      74             : } // namespace Config
      75             : } // namespace Envoy

Generated by: LCOV version 1.15