1
#include "source/extensions/router/cluster_specifiers/matcher/config.h"
2

            
3
#include "envoy/extensions/router/cluster_specifiers/matcher/v3/matcher.pb.validate.h"
4

            
5
#include "source/common/router/matcher_visitor.h"
6

            
7
namespace Envoy {
8
namespace Extensions {
9
namespace Router {
10
namespace Matcher {
11

            
12
Envoy::Router::ClusterSpecifierPluginSharedPtr
13
MatcherClusterSpecifierPluginFactoryConfig::createClusterSpecifierPlugin(
14
5
    const Protobuf::Message& config, Server::Configuration::ServerFactoryContext& context) {
15
5
  const auto& typed_config =
16
5
      MessageUtil::downcastAndValidate<const MatcherClusterSpecifierConfigProto&>(
17
5
          config, context.messageValidationVisitor());
18

            
19
5
  ClusterActionContext action_context;
20
  // Reuse the validation visitor because the new cluster specifier matcher has same input
21
  // with route matcher.
22
5
  Envoy::Router::RouteActionValidationVisitor validation_visitor;
23
5
  Envoy::Matcher::MatchTreeFactory<Http::HttpMatchingData, ClusterActionContext> factory(
24
5
      action_context, context, validation_visitor);
25

            
26
5
  auto matcher = factory.create(typed_config.cluster_matcher())();
27
5
  return std::make_shared<MatcherClusterSpecifierPlugin>(std::move(matcher));
28
5
}
29

            
30
REGISTER_FACTORY(MatcherClusterSpecifierPluginFactoryConfig,
31
                 Envoy::Router::ClusterSpecifierPluginFactoryConfig);
32

            
33
} // namespace Matcher
34
} // namespace Router
35
} // namespace Extensions
36
} // namespace Envoy