Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/extensions/path/match/uri_template/v3/uri_template_match.pb.h" 4 : #include "envoy/extensions/path/match/uri_template/v3/uri_template_match.pb.validate.h" 5 : #include "envoy/registry/registry.h" 6 : #include "envoy/router/path_matcher.h" 7 : 8 : #include "source/common/protobuf/message_validator_impl.h" 9 : #include "source/common/protobuf/utility.h" 10 : #include "source/extensions/path/match/uri_template/uri_template_match.h" 11 : 12 : namespace Envoy { 13 : namespace Extensions { 14 : namespace UriTemplate { 15 : namespace Match { 16 : 17 : class UriTemplateMatcherFactory : public Router::PathMatcherFactory { 18 : public: 19 : absl::StatusOr<Router::PathMatcherSharedPtr> 20 60 : createPathMatcher(const Protobuf::Message& config) override { 21 60 : auto path_match_config = MessageUtil::downcastAndValidate< 22 60 : const envoy::extensions::path::match::uri_template::v3::UriTemplateMatchConfig&>( 23 60 : config, ProtobufMessage::getStrictValidationVisitor()); 24 : 25 60 : if (!UriTemplate::isValidMatchPattern(path_match_config.path_template()).ok()) { 26 0 : return absl::InvalidArgumentError(fmt::format("path_match_policy.path_template {} is invalid", 27 0 : path_match_config.path_template())); 28 0 : } 29 : 30 60 : return std::make_shared<UriTemplateMatcher>(path_match_config); 31 60 : } 32 : 33 : // Router::PathMatcherFactory 34 73 : ProtobufTypes::MessagePtr createEmptyConfigProto() override { 35 73 : return std::make_unique< 36 73 : envoy::extensions::path::match::uri_template::v3::UriTemplateMatchConfig>(); 37 73 : } 38 : 39 190 : std::string name() const override { return "envoy.path.match.uri_template.uri_template_matcher"; } 40 : }; 41 : 42 : DECLARE_FACTORY(UriTemplateMatcherFactory); 43 : 44 : } // namespace Match 45 : } // namespace UriTemplate 46 : } // namespace Extensions 47 : } // namespace Envoy