1
#include "source/extensions/matching/actions/format_string/config.h"
2

            
3
#include "envoy/registry/registry.h"
4

            
5
#include "source/common/formatter/substitution_format_string.h"
6
#include "source/common/http/header_map_impl.h"
7
#include "source/common/protobuf/utility.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace Matching {
12
namespace Actions {
13
namespace FormatString {
14

            
15
const Network::FilterChain*
16
ActionImpl::get(const Server::Configuration::FilterChainsByName& filter_chains_by_name,
17
2
                const StreamInfo::StreamInfo& info) const {
18
2
  const std::string name = formatter_->format({}, info);
19
2
  const auto chain_match = filter_chains_by_name.find(name);
20
2
  if (chain_match != filter_chains_by_name.end()) {
21
1
    return chain_match->second.get();
22
1
  }
23
1
  return nullptr;
24
2
}
25

            
26
Matcher::ActionConstSharedPtr
27
ActionFactory::createAction(const Protobuf::Message& proto_config,
28
                            FilterChainActionFactoryContext& context,
29
1
                            ProtobufMessage::ValidationVisitor& validator) {
30
1
  const auto& config =
31
1
      MessageUtil::downcastAndValidate<const envoy::config::core::v3::SubstitutionFormatString&>(
32
1
          proto_config, validator);
33

            
34
1
  Server::GenericFactoryContextImpl generic_context(context, validator);
35
1
  Formatter::FormatterConstSharedPtr formatter = THROW_OR_RETURN_VALUE(
36
1
      Formatter::SubstitutionFormatStringUtils::fromProtoConfig(config, generic_context),
37
1
      Formatter::FormatterPtr);
38
1
  return std::make_shared<ActionImpl>(std::move(formatter));
39
1
}
40

            
41
REGISTER_FACTORY(ActionFactory, Matcher::ActionFactory<FilterChainActionFactoryContext>);
42

            
43
} // namespace FormatString
44
} // namespace Actions
45
} // namespace Matching
46
} // namespace Extensions
47
} // namespace Envoy