Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion envoy/formatter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ envoy_cc_library(
name = "substitution_formatter_interface",
hdrs = [
"substitution_formatter.h",
"substitution_formatter_base.h",
],
deps = [
":http_formatter_context_interface",
Expand Down
118 changes: 115 additions & 3 deletions envoy/formatter/substitution_formatter.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,121 @@
#pragma once

#include <memory>
#include <string>
#include <utility>
#include <vector>

#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<Formatter>;
using FormatterConstSharedPtr = std::shared_ptr<const Formatter>;

/**
* 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<std::string> optional string containing a single value extracted from
* the given context and stream info.
*/
virtual absl::optional<std::string> 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<FormatterProvider>;

class CommandParser {
public:
virtual ~CommandParser() = default;

/**
* Return a FormatterProviderBasePtr if command arg and max_length are correct for the formatter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FormatterProviderPtr

* 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove a "t"

*/
Comment on lines +77 to +85
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment for CommandParser::parse contains outdated and misspelled type references. It refers to FormatterProviderBasePtr (which does not exist) and misspells FormatterProviderPtr as FormattterProviderPtr (with three 't's). Updating these will improve the clarity and correctness of the public interface documentation.

   * Return a FormatterProviderPtr 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 FormatterProviderPtr substitution provider for the parsed command.
   */

virtual FormatterProviderPtr parse(absl::string_view command, absl::string_view command_arg,
absl::optional<size_t> max_length) const PURE;
};

using CommandParserPtr = std::unique_ptr<CommandParser>;
using CommandParserPtrVector = std::vector<CommandParserPtr>;

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
121 changes: 0 additions & 121 deletions envoy/formatter/substitution_formatter_base.h

This file was deleted.

2 changes: 1 addition & 1 deletion source/common/http/header_mutation.h
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http_service_headers.h
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion source/common/matcher/actions/string_returning_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/header_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "envoy/formatter/substitution_formatter_base.h"
#include "envoy/formatter/substitution_formatter.h"

namespace Envoy {
namespace Extensions {
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/formatter/file_content/config.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/formatter/generic_secret/config.h
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Loading