Line data Source code
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 0 : const StreamInfo::StreamInfo& info) const { 18 0 : const std::string name = formatter_->formatWithContext({}, info); 19 0 : const auto chain_match = filter_chains_by_name.find(name); 20 0 : if (chain_match != filter_chains_by_name.end()) { 21 0 : return chain_match->second.get(); 22 0 : } 23 0 : return nullptr; 24 0 : } 25 : 26 : Matcher::ActionFactoryCb 27 : ActionFactory::createActionFactoryCb(const Protobuf::Message& proto_config, 28 : FilterChainActionFactoryContext& context, 29 0 : ProtobufMessage::ValidationVisitor& validator) { 30 0 : const auto& config = 31 0 : MessageUtil::downcastAndValidate<const envoy::config::core::v3::SubstitutionFormatString&>( 32 0 : proto_config, validator); 33 : 34 0 : Server::GenericFactoryContextImpl generic_context(context, validator); 35 0 : Formatter::FormatterConstSharedPtr formatter = 36 0 : Formatter::SubstitutionFormatStringUtils::fromProtoConfig(config, generic_context); 37 0 : return [formatter]() { return std::make_unique<ActionImpl>(formatter); }; 38 0 : } 39 : 40 : REGISTER_FACTORY(ActionFactory, Matcher::ActionFactory<FilterChainActionFactoryContext>); 41 : 42 : } // namespace FormatString 43 : } // namespace Actions 44 : } // namespace Matching 45 : } // namespace Extensions 46 : } // namespace Envoy