Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/extensions/bootstrap/wasm/config.h
Line
Count
Source (jump to first uncovered line)
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/wasm.h"
12
13
namespace Envoy {
14
namespace Extensions {
15
namespace Bootstrap {
16
namespace Wasm {
17
18
using Common::Wasm::PluginHandleSharedPtrThreadLocal;
19
using Envoy::Extensions::Common::Wasm::PluginHandleSharedPtr;
20
using Envoy::Extensions::Common::Wasm::PluginSharedPtr;
21
22
class WasmService {
23
public:
24
  WasmService(PluginSharedPtr plugin, PluginHandleSharedPtr singleton)
25
0
      : plugin_(plugin), singleton_(std::move(singleton)) {}
26
  WasmService(PluginSharedPtr plugin,
27
              ThreadLocal::TypedSlotPtr<PluginHandleSharedPtrThreadLocal>&& tls_slot)
28
0
      : plugin_(plugin), tls_slot_(std::move(tls_slot)) {}
29
30
private:
31
  PluginSharedPtr plugin_;
32
  PluginHandleSharedPtr singleton_;
33
  ThreadLocal::TypedSlotPtr<PluginHandleSharedPtrThreadLocal> tls_slot_;
34
};
35
36
using WasmServicePtr = std::unique_ptr<WasmService>;
37
38
class WasmFactory : public Server::Configuration::BootstrapExtensionFactory {
39
public:
40
  ~WasmFactory() override = default;
41
2.70k
  std::string name() const override { return "envoy.bootstrap.wasm"; }
42
  Server::BootstrapExtensionPtr
43
  createBootstrapExtension(const Protobuf::Message& config,
44
                           Server::Configuration::ServerFactoryContext& context) override;
45
1
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
46
1
    return std::make_unique<envoy::extensions::wasm::v3::WasmService>();
47
1
  }
48
};
49
50
class WasmServiceExtension : public Server::BootstrapExtension, Logger::Loggable<Logger::Id::wasm> {
51
public:
52
  WasmServiceExtension(const envoy::extensions::wasm::v3::WasmService& config,
53
                       Server::Configuration::ServerFactoryContext& context)
54
0
      : config_(config), context_(context) {}
55
0
  WasmService& wasmService() {
56
0
    ASSERT(wasm_service_ != nullptr);
57
0
    return *wasm_service_;
58
0
  }
59
  void onServerInitialized() override;
60
61
private:
62
  void createWasm(Server::Configuration::ServerFactoryContext& context);
63
64
  envoy::extensions::wasm::v3::WasmService config_;
65
  Server::Configuration::ServerFactoryContext& context_;
66
  WasmServicePtr wasm_service_;
67
  Config::DataSource::RemoteAsyncDataProviderPtr remote_data_provider_;
68
};
69
70
} // namespace Wasm
71
} // namespace Bootstrap
72
} // namespace Extensions
73
} // namespace Envoy