Skip to content

Commit ba89dc7

Browse files
committed
style match lib.rs
Signed-off-by: Gal Ovadia <ggalovadia@gmail.com>
1 parent 5da6dc7 commit ba89dc7

4 files changed

Lines changed: 44 additions & 35 deletions

File tree

rust/src/egress_policies/dns_gateway.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ impl PolicyMatcher {
3030
}
3131
}
3232

33-
pub fn new_udp_filter_config<EC: EnvoyUdpListenerFilterConfig, ELF: EnvoyUdpListenerFilter>(
34-
_envoy_filter_config: &mut EC,
35-
_name: &str,
36-
config: &[u8],
37-
) -> Option<Box<dyn UdpListenerFilterConfig<ELF>>> {
33+
impl DnsGatewayFilterConfig {
34+
pub fn new(config: &[u8]) -> Option<Self> {
3835
// Parse config as JSON. The config arrives as a JSON-serialized google.protobuf.Any.
3936
// Supported wrappers:
4037
// - StringValue: {"@type":"...StringValue", "value":"<json string>"}
@@ -81,9 +78,10 @@ pub fn new_udp_filter_config<EC: EnvoyUdpListenerFilterConfig, ELF: EnvoyUdpList
8178
});
8279
}
8380

84-
envoy_log_info!("DnsGateway initialized with {} policies", policies.len());
81+
envoy_log_info!("DnsGateway initialized with {} policies", policies.len());
8582

86-
Some(Box::new(DnsGatewayFilterConfig { policies }))
83+
Some(DnsGatewayFilterConfig { policies })
84+
}
8785
}
8886

8987
impl<ELF: EnvoyUdpListenerFilter> UdpListenerFilterConfig<ELF> for DnsGatewayFilterConfig {

rust/src/egress_policies/hostname_lookup.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ use super::virtual_ip_cache::get_cache;
77

88
pub struct HostnameLookupFilterConfig {}
99

10-
pub fn new_network_filter_config<EC: EnvoyNetworkFilterConfig, ENF: EnvoyNetworkFilter>(
11-
_envoy_filter_config: &mut EC,
12-
_name: &str,
13-
_config: &[u8],
14-
) -> Option<Box<dyn NetworkFilterConfig<ENF>>> {
15-
envoy_log_info!("HostnameLookup filter initialized");
16-
Some(Box::new(HostnameLookupFilterConfig {}))
10+
impl HostnameLookupFilterConfig {
11+
pub fn new(_config: &[u8]) -> Option<Self> {
12+
envoy_log_info!("HostnameLookup filter initialized");
13+
Some(HostnameLookupFilterConfig {})
14+
}
1715
}
1816

1917
impl<ENF: EnvoyNetworkFilter> NetworkFilterConfig<ENF> for HostnameLookupFilterConfig {

rust/src/egress_policies/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ pub mod dns_gateway;
8787
pub mod hostname_lookup;
8888
pub mod virtual_ip_cache;
8989

90-
pub use dns_gateway::new_udp_filter_config as new_dns_gateway_config;
91-
pub use hostname_lookup::new_network_filter_config as new_hostname_lookup_config;
90+
pub use dns_gateway::DnsGatewayFilterConfig;
91+
pub use hostname_lookup::HostnameLookupFilterConfig;
9292
pub use virtual_ip_cache::{get_cache, init_cache, EgressPolicy, VirtualIpCache};

rust/src/lib.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ pub mod listener_tls_detector;
6464
// Implements a system for defining egress policies by hostname.
6565
pub mod egress_policies;
6666

67+
declare_all_init_functions!(
68+
init,
69+
http: new_http_filter_config_fn,
70+
network: new_network_filter_config_fn,
71+
udp_listener: new_udp_listener_filter_config_fn,
72+
);
73+
6774
/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::ProgramInitFunction`].
6875
///
6976
/// This is called exactly once when the module is loaded. It can be used to
@@ -76,14 +83,6 @@ fn init() -> bool {
7683
true
7784
}
7885

79-
// Register all filter types
80-
declare_all_init_functions!(
81-
init,
82-
http: new_http_filter_config_fn,
83-
network: new_network_filter_config_fn,
84-
udp_listener: new_udp_listener_filter_config_fn,
85-
);
86-
8786
/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::NewHttpFilterConfigFunction`].
8887
///
8988
/// This is the entrypoint every time a new HTTP filter is created via the DynamicModuleFilter config.
@@ -109,37 +108,51 @@ fn new_http_filter_config_fn<EC: EnvoyHttpFilterConfig, EHF: EnvoyHttpFilter>(
109108
.map(|config| Box::new(config) as Box<dyn HttpFilterConfig<EHF>>),
110109
"metrics" => http_metrics::FilterConfig::new(filter_config, envoy_filter_config)
111110
.map(|config| Box::new(config) as Box<dyn HttpFilterConfig<EHF>>),
112-
_ => panic!("Unknown filter name: {filter_name}"),
111+
_ => panic!("Unknown HTTP filter name: {filter_name}"),
113112
}
114113
}
115114

115+
116+
117+
/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::NewNetworkFilterConfigFunction`].
118+
///
119+
/// This is the entrypoint every time a new Network filter is created via the DynamicModuleNetworkFilter config.
120+
///
121+
/// Each argument matches the corresponding argument in the Envoy config here:
122+
/// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/dynamic_modules/v3/dynamic_modules.proto#envoy-v3-api-msg-extensions-dynamic-modules-v3-dynamicmoduleconfig
123+
///
124+
/// Returns None if the filter name or config is determined to be invalid by each filter's `new` function.
116125
fn new_network_filter_config_fn<EC: EnvoyNetworkFilterConfig, ENF: EnvoyNetworkFilter>(
117-
envoy_filter_config: &mut EC,
126+
_envoy_filter_config: &mut EC,
118127
filter_name: &str,
119128
filter_config: &[u8],
120129
) -> Option<Box<dyn NetworkFilterConfig<ENF>>> {
121130
match filter_name {
122-
"hostname_lookup" => egress_policies::new_hostname_lookup_config(
123-
envoy_filter_config,
124-
filter_name,
125-
filter_config,
126-
),
131+
"hostname_lookup" => egress_policies::HostnameLookupFilterConfig::new(filter_config)
132+
.map(|config| Box::new(config) as Box<dyn NetworkFilterConfig<ENF>>),
127133
_ => panic!("Unknown network filter name: {filter_name}"),
128134
}
129135
}
130136

137+
/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::NewUdpListenerFilterConfigFunction`].
138+
///
139+
/// This is the entrypoint every time a new UDP Listener filter is created via the DynamicModuleUdpListenerFilter config.
140+
///
141+
/// Each argument matches the corresponding argument in the Envoy config here:
142+
/// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/dynamic_modules/v3/dynamic_modules.proto#envoy-v3-api-msg-extensions-dynamic-modules-v3-dynamicmoduleconfig
143+
///
144+
/// Returns None if the filter name or config is determined to be invalid by each filter's `new` function.
131145
fn new_udp_listener_filter_config_fn<
132146
EC: EnvoyUdpListenerFilterConfig,
133147
ELF: EnvoyUdpListenerFilter,
134148
>(
135-
envoy_filter_config: &mut EC,
149+
_envoy_filter_config: &mut EC,
136150
filter_name: &str,
137151
filter_config: &[u8],
138152
) -> Option<Box<dyn UdpListenerFilterConfig<ELF>>> {
139153
match filter_name {
140-
"dns_gateway" => {
141-
egress_policies::new_dns_gateway_config(envoy_filter_config, filter_name, filter_config)
142-
}
154+
"dns_gateway" => egress_policies::DnsGatewayFilterConfig::new(filter_config)
155+
.map(|config| Box::new(config) as Box<dyn UdpListenerFilterConfig<ELF>>),
143156
_ => panic!("Unknown UDP listener filter name: {filter_name}"),
144157
}
145158
}

0 commit comments

Comments
 (0)