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
49
  createPathMatcher(const Protobuf::Message& config) override {
21
49
    auto path_match_config = MessageUtil::downcastAndValidate<
22
49
        const envoy::extensions::path::match::uri_template::v3::UriTemplateMatchConfig&>(
23
49
        config, ProtobufMessage::getStrictValidationVisitor());
24

            
25
49
    const absl::Status valid = UriTemplate::isValidMatchPattern(path_match_config.path_template());
26
49
    if (!valid.ok()) {
27
5
      return absl::InvalidArgumentError(
28
5
          fmt::format("path_match_policy.path_template {} is invalid: {}",
29
5
                      path_match_config.path_template(), valid.message()));
30
5
    }
31

            
32
44
    return std::make_shared<UriTemplateMatcher>(path_match_config);
33
49
  }
34

            
35
  // Router::PathMatcherFactory
36
523
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
37
523
    return std::make_unique<
38
523
        envoy::extensions::path::match::uri_template::v3::UriTemplateMatchConfig>();
39
523
  }
40

            
41
11991
  std::string name() const override { return "envoy.path.match.uri_template.uri_template_matcher"; }
42
};
43

            
44
DECLARE_FACTORY(UriTemplateMatcherFactory);
45

            
46
} // namespace Match
47
} // namespace UriTemplate
48
} // namespace Extensions
49
} // namespace Envoy