/proc/self/cwd/source/extensions/filters/network/redis_proxy/config.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <string> |
4 | | |
5 | | #include "envoy/api/api.h" |
6 | | #include "envoy/config/core/v3/base.pb.h" |
7 | | #include "envoy/extensions/filters/network/redis_proxy/v3/redis_proxy.pb.h" |
8 | | #include "envoy/extensions/filters/network/redis_proxy/v3/redis_proxy.pb.validate.h" |
9 | | #include "envoy/upstream/upstream.h" |
10 | | |
11 | | #include "source/common/common/empty_string.h" |
12 | | #include "source/common/config/datasource.h" |
13 | | #include "source/extensions/filters/network/common/factory_base.h" |
14 | | #include "source/extensions/filters/network/well_known_names.h" |
15 | | |
16 | | namespace Envoy { |
17 | | namespace Extensions { |
18 | | namespace NetworkFilters { |
19 | | namespace RedisProxy { |
20 | | |
21 | | class ProtocolOptionsConfigImpl : public Upstream::ProtocolOptionsConfig { |
22 | | public: |
23 | | ProtocolOptionsConfigImpl( |
24 | | const envoy::extensions::filters::network::redis_proxy::v3::RedisProtocolOptions& |
25 | | proto_config) |
26 | 0 | : auth_username_(proto_config.auth_username()), auth_password_(proto_config.auth_password()) { |
27 | 0 | } |
28 | | |
29 | 0 | std::string authUsername(Api::Api& api) const { |
30 | 0 | return Config::DataSource::read(auth_username_, true, api); |
31 | 0 | } |
32 | | |
33 | 0 | std::string authPassword(Api::Api& api) const { |
34 | 0 | return Config::DataSource::read(auth_password_, true, api); |
35 | 0 | } |
36 | | |
37 | | static const std::string authUsername(const Upstream::ClusterInfoConstSharedPtr info, |
38 | 0 | Api::Api& api) { |
39 | 0 | auto options = info->extensionProtocolOptionsTyped<ProtocolOptionsConfigImpl>( |
40 | 0 | NetworkFilterNames::get().RedisProxy); |
41 | 0 | if (options) { |
42 | 0 | return options->authUsername(api); |
43 | 0 | } |
44 | 0 | return EMPTY_STRING; |
45 | 0 | } |
46 | | |
47 | | static const std::string authPassword(const Upstream::ClusterInfoConstSharedPtr info, |
48 | 0 | Api::Api& api) { |
49 | 0 | auto options = info->extensionProtocolOptionsTyped<ProtocolOptionsConfigImpl>( |
50 | 0 | NetworkFilterNames::get().RedisProxy); |
51 | 0 | if (options) { |
52 | 0 | return options->authPassword(api); |
53 | 0 | } |
54 | 0 | return EMPTY_STRING; |
55 | 0 | } |
56 | | |
57 | | private: |
58 | | envoy::config::core::v3::DataSource auth_username_; |
59 | | envoy::config::core::v3::DataSource auth_password_; |
60 | | }; |
61 | | |
62 | | /** |
63 | | * Config registration for the redis proxy filter. @see NamedNetworkFilterConfigFactory. |
64 | | */ |
65 | | class RedisProxyFilterConfigFactory |
66 | | : public Common::FactoryBase< |
67 | | envoy::extensions::filters::network::redis_proxy::v3::RedisProxy, |
68 | | envoy::extensions::filters::network::redis_proxy::v3::RedisProtocolOptions> { |
69 | | public: |
70 | 4 | RedisProxyFilterConfigFactory() : FactoryBase(NetworkFilterNames::get().RedisProxy, true) {} |
71 | | |
72 | | private: |
73 | | Network::FilterFactoryCb createFilterFactoryFromProtoTyped( |
74 | | const envoy::extensions::filters::network::redis_proxy::v3::RedisProxy& proto_config, |
75 | | Server::Configuration::FactoryContext& context) override; |
76 | | |
77 | | Upstream::ProtocolOptionsConfigConstSharedPtr createProtocolOptionsTyped( |
78 | | const envoy::extensions::filters::network::redis_proxy::v3::RedisProtocolOptions& |
79 | | proto_config, |
80 | 0 | Server::Configuration::ProtocolOptionsFactoryContext&) override { |
81 | 0 | return std::make_shared<ProtocolOptionsConfigImpl>(proto_config); |
82 | 0 | } |
83 | | }; |
84 | | |
85 | | } // namespace RedisProxy |
86 | | } // namespace NetworkFilters |
87 | | } // namespace Extensions |
88 | | } // namespace Envoy |