1
#pragma once
2

            
3
#include "envoy/common/pure.h"
4
#include "envoy/extensions/wasm/v3/wasm.pb.h"
5
#include "envoy/extensions/wasm/v3/wasm.pb.validate.h"
6
#include "envoy/server/bootstrap_extension_config.h"
7
#include "envoy/server/filter_config.h"
8
#include "envoy/server/instance.h"
9

            
10
#include "source/common/protobuf/protobuf.h"
11
#include "source/extensions/common/wasm/remote_async_datasource.h"
12
#include "source/extensions/common/wasm/wasm.h"
13

            
14
namespace Envoy {
15
namespace Extensions {
16
namespace Bootstrap {
17
namespace Wasm {
18

            
19
using Common::Wasm::PluginConfig;
20
using Common::Wasm::PluginConfigPtr;
21
using Common::Wasm::PluginHandleSharedPtrThreadLocal;
22
using Envoy::Extensions::Common::Wasm::PluginHandleSharedPtr;
23
using Envoy::Extensions::Common::Wasm::PluginSharedPtr;
24

            
25
class WasmFactory : public Server::Configuration::BootstrapExtensionFactory {
26
public:
27
2
  ~WasmFactory() override = default;
28
8
  std::string name() const override { return "envoy.bootstrap.wasm"; }
29
  Server::BootstrapExtensionPtr
30
  createBootstrapExtension(const Protobuf::Message& config,
31
                           Server::Configuration::ServerFactoryContext& context) override;
32
6
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
33
6
    return std::make_unique<envoy::extensions::wasm::v3::WasmService>();
34
6
  }
35
};
36

            
37
class WasmServiceExtension : public Server::BootstrapExtension, Logger::Loggable<Logger::Id::wasm> {
38
public:
39
  WasmServiceExtension(const envoy::extensions::wasm::v3::WasmService& config,
40
                       Server::Configuration::ServerFactoryContext& context)
41
13
      : config_(config), context_(context) {}
42
5
  PluginConfig& wasmService() {
43
5
    ASSERT(plugin_config_ != nullptr);
44
5
    return *plugin_config_;
45
5
  }
46
  void onServerInitialized(Server::Instance&) override;
47
1
  void onWorkerThreadInitialized() override {};
48

            
49
private:
50
  void createWasm(Server::Configuration::ServerFactoryContext& context);
51

            
52
  envoy::extensions::wasm::v3::WasmService config_;
53
  Server::Configuration::ServerFactoryContext& context_;
54
  PluginConfigPtr plugin_config_;
55
};
56

            
57
} // namespace Wasm
58
} // namespace Bootstrap
59
} // namespace Extensions
60
} // namespace Envoy