1
#pragma once
2

            
3
#include "envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.pb.h"
4
#include "envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.pb.validate.h"
5
#include "envoy/registry/registry.h"
6
#include "envoy/router/path_rewriter.h"
7

            
8
#include "source/extensions/path/rewrite/uri_template/uri_template_rewrite.h"
9

            
10
namespace Envoy {
11
namespace Extensions {
12
namespace UriTemplate {
13
namespace Rewrite {
14

            
15
class UriTemplateRewriterFactory : public Router::PathRewriterFactory {
16
public:
17
  absl::StatusOr<Router::PathRewriterSharedPtr>
18
37
  createPathRewriter(const Protobuf::Message& rewrite_config) override {
19
37
    auto path_rewrite_config = MessageUtil::downcastAndValidate<
20
37
        const envoy::extensions::path::rewrite::uri_template::v3::UriTemplateRewriteConfig&>(
21
37
        rewrite_config, ProtobufMessage::getStrictValidationVisitor());
22

            
23
37
    if (!UriTemplate::isValidRewritePattern(path_rewrite_config.path_template_rewrite()).ok()) {
24
2
      return absl::InvalidArgumentError(
25
2
          fmt::format("path_rewrite_policy.path_template_rewrite {} is invalid",
26
2
                      path_rewrite_config.path_template_rewrite()));
27
2
    }
28
35
    return std::make_shared<UriTemplateRewriter>(path_rewrite_config);
29
37
  }
30

            
31
  // Router::PathRewriterFactory
32
508
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
33
508
    return std::make_unique<
34
508
        envoy::extensions::path::rewrite::uri_template::v3::UriTemplateRewriteConfig>();
35
508
  }
36

            
37
11990
  std::string name() const override {
38
11990
    return "envoy.path.rewrite.uri_template.uri_template_rewriter";
39
11990
  }
40
};
41

            
42
DECLARE_FACTORY(UriTemplateRewriterFactory);
43

            
44
} // namespace Rewrite
45
} // namespace UriTemplate
46
} // namespace Extensions
47
} // namespace Envoy