1
#include "envoy/extensions/matching/actions/transform_stat/v3/transform_stat.pb.validate.h"
2
#include "envoy/registry/registry.h"
3

            
4
#include "source/extensions/matching/actions/transform_stat/transform_stat.h"
5

            
6
namespace Envoy {
7
namespace Extensions {
8
namespace Matching {
9
namespace Actions {
10
namespace TransformStat {
11

            
12
class TransformStatActionFactory : public Matcher::ActionFactory<ActionContext> {
13
public:
14
  Matcher::ActionConstSharedPtr
15
  createAction(const Protobuf::Message& config, ActionContext& /*context*/,
16
14
               ProtobufMessage::ValidationVisitor& validation_visitor) override {
17
14
    const auto& action_config =
18
14
        MessageUtil::downcastAndValidate<const ProtoTransformStat&>(config, validation_visitor);
19

            
20
14
    if (action_config.has_drop_stat()) {
21
7
      return std::make_shared<DropStat>(action_config.drop_stat());
22
9
    } else if (action_config.has_drop_tag()) {
23
2
      return std::make_shared<DropTag>();
24
5
    } else if (action_config.has_update_tag()) {
25
4
      const auto& update_tag = action_config.update_tag();
26
4
      return std::make_shared<UpdateTag>(update_tag.new_tag_value());
27
4
    }
28

            
29
1
    return std::make_shared<NoOpAction>();
30
14
  }
31

            
32
11
  std::string name() const override {
33
11
    return "envoy.extensions.matching.actions.transform_stat.v3.TransformStat";
34
11
  }
35

            
36
12
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
37
12
    return std::make_unique<ProtoTransformStat>();
38
12
  }
39
};
40

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

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