/proc/self/cwd/source/extensions/common/wasm/plugin.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "source/extensions/common/wasm/plugin.h" |
2 | | |
3 | | #include "envoy/common/exception.h" |
4 | | |
5 | | #include "include/proxy-wasm/wasm.h" |
6 | | |
7 | | namespace Envoy { |
8 | | namespace Extensions { |
9 | | namespace Common { |
10 | | namespace Wasm { |
11 | | |
12 | 16 | WasmConfig::WasmConfig(const envoy::extensions::wasm::v3::PluginConfig& config) : config_(config) { |
13 | 31 | for (auto& capability : config_.capability_restriction_config().allowed_capabilities()) { |
14 | | // TODO(rapilado): Set the SanitizationConfig fields once sanitization is implemented. |
15 | 31 | allowed_capabilities_[capability.first] = proxy_wasm::SanitizationConfig(); |
16 | 31 | } |
17 | | |
18 | 16 | if (config_.vm_config().has_environment_variables()) { |
19 | 9 | const auto& envs = config_.vm_config().environment_variables(); |
20 | | |
21 | | // We reject NullVm with key_values configuration |
22 | | // since it directly accesses Envoy's env vars and we should not modify Envoy's env vars here. |
23 | | // TODO(mathetake): Once proxy_get_map_values(type::EnvironmentVariables, ..) call is supported, |
24 | | // then remove this restriction. |
25 | 9 | if (config.vm_config().runtime() == "envoy.wasm.runtime.null" && !envs.key_values().empty()) { |
26 | 0 | throw EnvoyException("envoy.extensions.wasm.v3.VmConfig.EnvironmentVariables.key_values must " |
27 | 0 | "not be set for NullVm."); |
28 | 0 | } |
29 | | |
30 | | // Check key duplication. |
31 | 9 | absl::flat_hash_set<std::string> keys; |
32 | 22 | for (const auto& env : envs.key_values()) { |
33 | 22 | keys.insert(env.first); |
34 | 22 | } |
35 | 14 | for (const auto& key : envs.host_env_keys()) { |
36 | 14 | if (!keys.insert(key).second) { |
37 | 2 | throw EnvoyException( |
38 | 2 | fmt::format("Key {} is duplicated in " |
39 | 2 | "envoy.extensions.wasm.v3.VmConfig.environment_variables for {}. " |
40 | 2 | "All the keys must be unique.", |
41 | 2 | key, config_.name())); |
42 | 2 | } |
43 | 14 | } |
44 | | |
45 | | // Construct merged key-value pairs. |
46 | 17 | for (const auto& env : envs.key_values()) { |
47 | 17 | envs_[env.first] = env.second; |
48 | 17 | } |
49 | 10 | for (const auto& key : envs.host_env_keys()) { |
50 | 10 | if (auto value = std::getenv(key.data())) { |
51 | 6 | envs_[key] = value; |
52 | 6 | } |
53 | 10 | } |
54 | 7 | } |
55 | 16 | } |
56 | | |
57 | | } // namespace Wasm |
58 | | } // namespace Common |
59 | | } // namespace Extensions |
60 | | } // namespace Envoy |