diff --git a/envoy/formatter/BUILD b/envoy/formatter/BUILD index e89af77551941..f4ca1f020467f 100644 --- a/envoy/formatter/BUILD +++ b/envoy/formatter/BUILD @@ -24,7 +24,6 @@ envoy_cc_library( name = "substitution_formatter_interface", hdrs = [ "substitution_formatter.h", - "substitution_formatter_base.h", ], deps = [ ":http_formatter_context_interface", diff --git a/envoy/formatter/substitution_formatter.h b/envoy/formatter/substitution_formatter.h index b43f5270b7e77..351cf0f5cab84 100644 --- a/envoy/formatter/substitution_formatter.h +++ b/envoy/formatter/substitution_formatter.h @@ -1,9 +1,121 @@ #pragma once +#include +#include +#include +#include + +#include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" #include "envoy/formatter/http_formatter_context.h" -#include "envoy/formatter/substitution_formatter_base.h" -#include "envoy/http/header_map.h" +#include "envoy/server/factory_context.h" +#include "envoy/stream_info/stream_info.h" + +#include "source/common/protobuf/protobuf.h" + +#include "absl/strings/string_view.h" +#include "absl/types/optional.h" namespace Envoy { -namespace Formatter {} // namespace Formatter +namespace Formatter { + +/** + * Interface for multiple protocols/modules formatters. + */ +class Formatter { +public: + virtual ~Formatter() = default; + + /** + * Return a formatted substitution line. + * @param context supplies the formatter context. + * @param stream_info supplies the stream info. + * @return std::string string containing the complete formatted substitution line. + */ + virtual std::string format(const Context& context, + const StreamInfo::StreamInfo& stream_info) const PURE; +}; + +using FormatterPtr = std::unique_ptr; +using FormatterConstSharedPtr = std::shared_ptr; + +/** + * Interface for multiple protocols/modules formatter providers. + */ +class FormatterProvider { +public: + virtual ~FormatterProvider() = default; + + /** + * Format the value with the given context and stream info. + * @param context supplies the formatter context. + * @param stream_info supplies the stream info. + * @return absl::optional optional string containing a single value extracted from + * the given context and stream info. + */ + virtual absl::optional format(const Context& context, + const StreamInfo::StreamInfo& stream_info) const PURE; + + /** + * Format the value with the given context and stream info. + * @param context supplies the formatter context. + * @param stream_info supplies the stream info. + * @return Protobuf::Value containing a single value extracted from the given + * context and stream info. + */ + virtual Protobuf::Value formatValue(const Context& context, + const StreamInfo::StreamInfo& stream_info) const PURE; +}; + +using FormatterProviderPtr = std::unique_ptr; + +class CommandParser { +public: + virtual ~CommandParser() = default; + + /** + * Return a FormatterProviderBasePtr if command arg and max_length are correct for the formatter + * provider associated with command. + * @param command command name. + * @param command_arg command specific argument. Empty if no argument is provided. + * @param max_length length to which the output produced by FormatterProvider + * should be truncated to (optional). + * + * @return FormattterProviderPtr substitution provider for the parsed command. + */ + virtual FormatterProviderPtr parse(absl::string_view command, absl::string_view command_arg, + absl::optional max_length) const PURE; +}; + +using CommandParserPtr = std::unique_ptr; +using CommandParserPtrVector = std::vector; + +class CommandParserFactory : public Config::TypedFactory { +public: + /** + * Creates a particular CommandParser implementation. + * + * @param config supplies the configuration for the command parser. + * @param context supplies the factory context. + * @return CommandParserPtr the CommandParser which will be used in + * SubstitutionFormatParser::parse() when evaluating an access log format string. + */ + virtual CommandParserPtr + createCommandParserFromProto(const Protobuf::Message& config, + Server::Configuration::GenericFactoryContext& context) PURE; + + std::string category() const override { return "envoy.formatter"; } +}; + +class BuiltInCommandParserFactory : public Config::UntypedFactory { +public: + std::string category() const override { return "envoy.built_in_formatters"; } + + /** + * Creates a particular CommandParser implementation. + */ + virtual CommandParserPtr createCommandParser() const PURE; +}; + +} // namespace Formatter } // namespace Envoy diff --git a/envoy/formatter/substitution_formatter_base.h b/envoy/formatter/substitution_formatter_base.h deleted file mode 100644 index 351cf0f5cab84..0000000000000 --- a/envoy/formatter/substitution_formatter_base.h +++ /dev/null @@ -1,121 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "envoy/common/pure.h" -#include "envoy/config/typed_config.h" -#include "envoy/formatter/http_formatter_context.h" -#include "envoy/server/factory_context.h" -#include "envoy/stream_info/stream_info.h" - -#include "source/common/protobuf/protobuf.h" - -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" - -namespace Envoy { -namespace Formatter { - -/** - * Interface for multiple protocols/modules formatters. - */ -class Formatter { -public: - virtual ~Formatter() = default; - - /** - * Return a formatted substitution line. - * @param context supplies the formatter context. - * @param stream_info supplies the stream info. - * @return std::string string containing the complete formatted substitution line. - */ - virtual std::string format(const Context& context, - const StreamInfo::StreamInfo& stream_info) const PURE; -}; - -using FormatterPtr = std::unique_ptr; -using FormatterConstSharedPtr = std::shared_ptr; - -/** - * Interface for multiple protocols/modules formatter providers. - */ -class FormatterProvider { -public: - virtual ~FormatterProvider() = default; - - /** - * Format the value with the given context and stream info. - * @param context supplies the formatter context. - * @param stream_info supplies the stream info. - * @return absl::optional optional string containing a single value extracted from - * the given context and stream info. - */ - virtual absl::optional format(const Context& context, - const StreamInfo::StreamInfo& stream_info) const PURE; - - /** - * Format the value with the given context and stream info. - * @param context supplies the formatter context. - * @param stream_info supplies the stream info. - * @return Protobuf::Value containing a single value extracted from the given - * context and stream info. - */ - virtual Protobuf::Value formatValue(const Context& context, - const StreamInfo::StreamInfo& stream_info) const PURE; -}; - -using FormatterProviderPtr = std::unique_ptr; - -class CommandParser { -public: - virtual ~CommandParser() = default; - - /** - * Return a FormatterProviderBasePtr if command arg and max_length are correct for the formatter - * provider associated with command. - * @param command command name. - * @param command_arg command specific argument. Empty if no argument is provided. - * @param max_length length to which the output produced by FormatterProvider - * should be truncated to (optional). - * - * @return FormattterProviderPtr substitution provider for the parsed command. - */ - virtual FormatterProviderPtr parse(absl::string_view command, absl::string_view command_arg, - absl::optional max_length) const PURE; -}; - -using CommandParserPtr = std::unique_ptr; -using CommandParserPtrVector = std::vector; - -class CommandParserFactory : public Config::TypedFactory { -public: - /** - * Creates a particular CommandParser implementation. - * - * @param config supplies the configuration for the command parser. - * @param context supplies the factory context. - * @return CommandParserPtr the CommandParser which will be used in - * SubstitutionFormatParser::parse() when evaluating an access log format string. - */ - virtual CommandParserPtr - createCommandParserFromProto(const Protobuf::Message& config, - Server::Configuration::GenericFactoryContext& context) PURE; - - std::string category() const override { return "envoy.formatter"; } -}; - -class BuiltInCommandParserFactory : public Config::UntypedFactory { -public: - std::string category() const override { return "envoy.built_in_formatters"; } - - /** - * Creates a particular CommandParser implementation. - */ - virtual CommandParserPtr createCommandParser() const PURE; -}; - -} // namespace Formatter -} // namespace Envoy diff --git a/source/common/http/header_mutation.h b/source/common/http/header_mutation.h index eeabd3e0b38a8..25d03110f4830 100644 --- a/source/common/http/header_mutation.h +++ b/source/common/http/header_mutation.h @@ -1,7 +1,7 @@ #pragma once #include "envoy/config/common/mutation_rules/v3/mutation_rules.pb.h" -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" #include "envoy/http/header_evaluator.h" #include "envoy/server/factory_context.h" diff --git a/source/common/http/http_service_headers.h b/source/common/http/http_service_headers.h index fc236f8c20831..fa7cf1cd5ef64 100644 --- a/source/common/http/http_service_headers.h +++ b/source/common/http/http_service_headers.h @@ -1,7 +1,7 @@ #pragma once #include "envoy/config/core/v3/http_service.pb.h" -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" #include "envoy/http/header_map.h" #include "envoy/server/factory_context.h" diff --git a/source/common/matcher/actions/string_returning_action.cc b/source/common/matcher/actions/string_returning_action.cc index 8f12178296176..372db0b3bd6da 100644 --- a/source/common/matcher/actions/string_returning_action.cc +++ b/source/common/matcher/actions/string_returning_action.cc @@ -2,7 +2,7 @@ #include "envoy/config/core/v3/substitution_format_string.pb.h" #include "envoy/config/core/v3/substitution_format_string.pb.validate.h" -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" #include "envoy/registry/registry.h" #include "source/common/formatter/substitution_format_string.h" diff --git a/source/common/router/header_parser.h b/source/common/router/header_parser.h index f2dd3fe135d45..210af176889fc 100644 --- a/source/common/router/header_parser.h +++ b/source/common/router/header_parser.h @@ -5,7 +5,7 @@ #include "envoy/access_log/access_log.h" #include "envoy/config/core/v3/base.pb.h" -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" #include "envoy/http/header_evaluator.h" #include "envoy/http/header_map.h" diff --git a/source/extensions/filters/udp/dns_filter/dns_filter_access_log.h b/source/extensions/filters/udp/dns_filter/dns_filter_access_log.h index 4810974758ac0..d26658906511a 100644 --- a/source/extensions/filters/udp/dns_filter/dns_filter_access_log.h +++ b/source/extensions/filters/udp/dns_filter/dns_filter_access_log.h @@ -1,6 +1,6 @@ #pragma once -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" namespace Envoy { namespace Extensions { diff --git a/source/extensions/formatter/file_content/config.h b/source/extensions/formatter/file_content/config.h index b36191f18dfdc..a2b37eaf6d30a 100644 --- a/source/extensions/formatter/file_content/config.h +++ b/source/extensions/formatter/file_content/config.h @@ -1,7 +1,7 @@ #pragma once #include "envoy/extensions/formatter/file_content/v3/file_content.pb.h" -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" #include "envoy/server/factory_context.h" namespace Envoy { diff --git a/source/extensions/formatter/generic_secret/config.h b/source/extensions/formatter/generic_secret/config.h index 2b7f0b9bdb597..56d71cc4b133e 100644 --- a/source/extensions/formatter/generic_secret/config.h +++ b/source/extensions/formatter/generic_secret/config.h @@ -1,7 +1,7 @@ #pragma once #include "envoy/extensions/formatter/generic_secret/v3/generic_secret.pb.h" -#include "envoy/formatter/substitution_formatter_base.h" +#include "envoy/formatter/substitution_formatter.h" #include "envoy/secret/secret_manager.h" #include "envoy/server/factory_context.h"