1
#pragma once
2

            
3
#include <string>
4

            
5
#include "envoy/api/api.h"
6
#include "envoy/config/core/v3/substitution_format_string.pb.h"
7
#include "envoy/formatter/substitution_formatter.h"
8
#include "envoy/server/factory_context.h"
9

            
10
#include "source/common/config/datasource.h"
11
#include "source/common/config/utility.h"
12
#include "source/common/formatter/substitution_formatter.h"
13
#include "source/common/protobuf/message_validator_impl.h"
14
#include "source/common/protobuf/protobuf.h"
15
#include "source/common/runtime/runtime_features.h"
16
#include "source/server/generic_factory_context.h"
17

            
18
namespace Envoy {
19
namespace Formatter {
20

            
21
/**
22
 * Utilities for using envoy::config::core::v3::SubstitutionFormatString
23
 */
24
class SubstitutionFormatStringUtils {
25
public:
26
  using FormattersConfig =
27
      Protobuf::RepeatedPtrField<envoy::config::core::v3::TypedExtensionConfig>;
28

            
29
  /**
30
   * Parse list of formatter configurations to commands.
31
   */
32
  static absl::StatusOr<std::vector<CommandParserPtr>>
33
  parseFormatters(const FormattersConfig& formatters,
34
                  Server::Configuration::GenericFactoryContext& context,
35
                  std::vector<CommandParserPtr>&& commands_parsers = {});
36

            
37
  /**
38
   * Generate a formatter object from config SubstitutionFormatString.
39
   */
40
  static absl::StatusOr<FormatterPtr>
41
  fromProtoConfig(const envoy::config::core::v3::SubstitutionFormatString& config,
42
                  Server::Configuration::GenericFactoryContext& context,
43
                  std::vector<CommandParserPtr>&& command_parsers = {});
44
  /**
45
   * Generate a Json formatter object from proto::Struct config
46
   */
47
  static FormatterPtr createJsonFormatter(const Protobuf::Struct& struct_format,
48
                                          bool omit_empty_values,
49
                                          const std::vector<CommandParserPtr>& commands = {});
50
};
51

            
52
} // namespace Formatter
53
} // namespace Envoy