Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/matcher/matcher.h" 4 : 5 : #include "absl/status/status.h" 6 : 7 : namespace Envoy { 8 : namespace Matcher { 9 : 10 : /** 11 : * Interface for a validator that is used during match tree construction to validate 12 : * the paths, nodes, subtrees, etc. of the match tree. Currently only node-based (i.e. without 13 : * knowledge of the resulting leaf action) validation of data input is supported. 14 : * 15 : * As the match tree itself can have any structure, this class is used to accumulate a list of 16 : * violations that occur during tree construction. This has the benefit of being able to emit 17 : * an error containing all the violations, not just the first one. 18 : */ 19 : template <class DataType> class MatchTreeValidationVisitor { 20 : public: 21 5 : virtual ~MatchTreeValidationVisitor() = default; 22 : 23 : // Validates a single DataInput its type_url. 24 0 : void validateDataInput(const DataInputFactory<DataType>& data_input, absl::string_view type_url) { 25 0 : auto status = performDataInputValidation(data_input, type_url); 26 : 27 0 : if (!status.ok()) { 28 0 : errors_.emplace_back(std::move(status)); 29 0 : } 30 0 : } 31 : 32 2 : const std::vector<absl::Status>& errors() const { return errors_; } 33 : 34 : protected: 35 : // Implementations would subclass this to specify the validation logic for data inputs, 36 : // returning a helpful error message if validation fails. 37 : virtual absl::Status performDataInputValidation(const DataInputFactory<DataType>& data_input, 38 : absl::string_view type_url) PURE; 39 : 40 : private: 41 : std::vector<absl::Status> errors_; 42 : }; 43 : } // namespace Matcher 44 : } // namespace Envoy