LCOV - code coverage report
Current view: top level - source/extensions/matching/common_inputs/environment_variable - config.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 10 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #include "source/extensions/matching/common_inputs/environment_variable/config.h"
       2             : 
       3             : #include <memory>
       4             : 
       5             : #include "envoy/matcher/matcher.h"
       6             : 
       7             : namespace Envoy {
       8             : namespace Extensions {
       9             : namespace Matching {
      10             : namespace CommonInputs {
      11             : namespace EnvironmentVariable {
      12             : 
      13             : Envoy::Matcher::CommonProtocolInputFactoryCb
      14             : Config::createCommonProtocolInputFactoryCb(const Protobuf::Message& config,
      15           0 :                                            ProtobufMessage::ValidationVisitor& validation_visitor) {
      16           0 :   const auto& environment_config = MessageUtil::downcastAndValidate<
      17           0 :       const envoy::extensions::matching::common_inputs::environment_variable::v3::Config&>(
      18           0 :       config, validation_visitor);
      19             : 
      20             :   // We read the env variable at construction time to avoid repeat lookups.
      21             :   // This assumes that the environment remains stable during the process lifetime.
      22           0 :   auto* value = getenv(environment_config.name().data());
      23           0 :   if (value != nullptr) {
      24           0 :     return [s = std::string(value)]() { return std::make_unique<Input>(s); };
      25           0 :   }
      26             : 
      27           0 :   return []() { return std::make_unique<Input>(absl::monostate()); };
      28           0 : }
      29             : 
      30             : /**
      31             :  * Static registration for the environment data input. @see RegisterFactory.
      32             :  */
      33             : REGISTER_FACTORY(Config, Envoy::Matcher::CommonProtocolInputFactory);
      34             : 
      35             : } // namespace EnvironmentVariable
      36             : } // namespace CommonInputs
      37             : } // namespace Matching
      38             : } // namespace Extensions
      39             : } // namespace Envoy

Generated by: LCOV version 1.15