Skip to content

Commit 44d7feb

Browse files
committed
dynamic_modules: add examples for network & listener modules
Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
1 parent 2d4b47f commit 44d7feb

18 files changed

Lines changed: 2680 additions & 21 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ RUN CC="zig cc -target aarch64-linux-gnu" CXX="zig c++ -target aarch64-linux-gnu
4646
RUN CC="zig cc -target x86_64-linux-gnu" CXX="zig c++ -target x86_64-linux-gnu" CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o /build/amd64_libgo_module.so .
4747

4848
##### Build the final image #####
49-
FROM envoyproxy/envoy:v1.36.2 AS envoy
49+
FROM envoyproxy/envoy:v1.37.0 AS envoy
5050
ARG TARGETARCH
5151
ENV ENVOY_DYNAMIC_MODULES_SEARCH_PATH=/usr/local/lib
5252
COPY --from=rust_builder /build/${TARGETARCH}_librust_module.so /usr/local/lib/librust_module.so

ENVOY_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dc2d3098ae5641555f15c71d5bb5ce0060a8015c
1+
6d9bb7d9a85d616b220d1f8fe67b61f82bbdb8d3

rust/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[package]
32
name = "envoy-proxy-dynamic-modules-rust-sdk-examples"
43
version = "0.1.0"
@@ -8,7 +7,7 @@ repository = "https://github.com/envoyproxy/dynamic-modules-example"
87

98
[dependencies]
109
# The SDK version must match the Envoy version due to the strict compatibility requirements.
11-
envoy-proxy-dynamic-modules-rust-sdk = { git = "https://github.com/envoyproxy/envoy", rev = "dc2d3098ae5641555f15c71d5bb5ce0060a8015c" }
10+
envoy-proxy-dynamic-modules-rust-sdk = { git = "https://github.com/envoyproxy/envoy", rev = "6d9bb7d9a85d616b220d1f8fe67b61f82bbdb8d3" }
1211
serde = { version = "1.0", features = ["derive"] }
1312
serde_json = "1.0"
1413
rand = "0.9.0"
@@ -17,7 +16,8 @@ matchers = "0.2.0"
1716
[dev-dependencies]
1817
tempfile = "3.16.0"
1918

19+
# Main library - HTTP filters (backward compatible)
2020
[lib]
2121
name = "rust_module"
2222
path = "src/lib.rs"
23-
crate-type = ["cdylib"]
23+
crate-type = ["cdylib", "rlib"]

rust/src/http_access_logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl FilterConfig {
7777

7878
impl<EHF: EnvoyHttpFilter> HttpFilterConfig<EHF> for FilterConfig {
7979
/// This is called for each new HTTP filter.
80-
fn new_http_filter(&mut self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
80+
fn new_http_filter(&self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
8181
let tx = self.tx.clone();
8282
Box::new(Filter {
8383
tx,

rust/src/http_header_mutation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl FilterConfig {
3131

3232
impl<EHF: EnvoyHttpFilter> HttpFilterConfig<EHF> for FilterConfig {
3333
/// This is called for each new HTTP filter.
34-
fn new_http_filter(&mut self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
34+
fn new_http_filter(&self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
3535
Box::new(Filter {
3636
request_headers: self.request_headers.clone(),
3737
remove_request_headers: self.remove_request_headers.clone(),

rust/src/http_metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl FilterConfig {
3838

3939
impl<EHF: EnvoyHttpFilter> HttpFilterConfig<EHF> for FilterConfig {
4040
/// This is called for each new HTTP filter.
41-
fn new_http_filter(&mut self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
41+
fn new_http_filter(&self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
4242
Box::new(Filter {
4343
version: self.config.version.clone(),
4444
start_time: None,

rust/src/http_passthrough.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl FilterConfig {
2121

2222
impl<EHF: EnvoyHttpFilter> HttpFilterConfig<EHF> for FilterConfig {
2323
/// This is called for each new HTTP filter.
24-
fn new_http_filter(&mut self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
24+
fn new_http_filter(&self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
2525
Box::new(Filter {})
2626
}
2727
}

rust/src/http_random_auth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl FilterConfig {
1818

1919
impl<EHF: EnvoyHttpFilter> HttpFilterConfig<EHF> for FilterConfig {
2020
/// This is called for each new HTTP filter.
21-
fn new_http_filter(&mut self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
21+
fn new_http_filter(&self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
2222
Box::new(Filter {})
2323
}
2424
}
@@ -37,7 +37,7 @@ impl<EHF: EnvoyHttpFilter> HttpFilter<EHF> for Filter {
3737
) -> abi::envoy_dynamic_module_type_on_http_filter_request_headers_status {
3838
let reject = rand::rng().random::<bool>();
3939
if reject {
40-
envoy_filter.send_response(403, vec![], Some(b"Access forbidden"));
40+
envoy_filter.send_response(403, vec![], Some(b"Access forbidden"), None);
4141
return abi::envoy_dynamic_module_type_on_http_filter_request_headers_status::StopIteration;
4242
}
4343
abi::envoy_dynamic_module_type_on_http_filter_request_headers_status::Continue

rust/src/http_zero_copy_regex_waf.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl FilterConfig {
3030

3131
impl<EHF: EnvoyHttpFilter> HttpFilterConfig<EHF> for FilterConfig {
3232
/// This is called for each new HTTP filter.
33-
fn new_http_filter(&mut self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
33+
fn new_http_filter(&self, _envoy: &mut EHF) -> Box<dyn HttpFilter<EHF>> {
3434
Box::new(Filter {
3535
re: self.re.clone(),
3636
})
@@ -61,7 +61,7 @@ impl<EHF: EnvoyHttpFilter> HttpFilter<EHF> for Filter {
6161
// [`EnvoyMutBuffer`]s. Each [`EnvoyMutBuffer`] is a mutable buffer that can be
6262
// used to read the body data.
6363
let data = envoy_filter
64-
.get_request_body()
64+
.get_buffered_request_body()
6565
.expect("Failed to get request body");
6666
let mut body_reader = BodyReader::new(data);
6767
let matched = self
@@ -70,7 +70,7 @@ impl<EHF: EnvoyHttpFilter> HttpFilter<EHF> for Filter {
7070
.expect("Failed to do regex match");
7171
if matched {
7272
// If the regex matches, we send a 403 response.
73-
envoy_filter.send_response(403, vec![], Some(b"Access forbidden"));
73+
envoy_filter.send_response(403, vec![], Some(b"Access forbidden"), None);
7474
return abi::envoy_dynamic_module_type_on_http_filter_request_body_status::StopIterationNoBuffer;
7575
}
7676
abi::envoy_dynamic_module_type_on_http_filter_request_body_status::Continue
@@ -126,7 +126,7 @@ mod tests {
126126
#[test]
127127
/// This demonstrates how to write a test without Envoy using a mock provided by the SDK.
128128
fn test_filter() {
129-
let mut filter_config = FilterConfig::new("Hello [Ww].+").unwrap();
129+
let filter_config = FilterConfig::new("Hello [Ww].+").unwrap();
130130
let mut envoy_filter = MockEnvoyHttpFilter::new();
131131
let mut filter: Box<dyn HttpFilter<MockEnvoyHttpFilter>> =
132132
filter_config.new_http_filter(&mut envoy_filter);
@@ -136,7 +136,7 @@ mod tests {
136136

137137
// End of stream and matching regex, so we should send a 403 response.
138138
envoy_filter
139-
.expect_get_request_body()
139+
.expect_get_buffered_request_body()
140140
.returning(|| {
141141
static mut HELLO: [u8; 6] = *b"Hello ";
142142
static mut WORLD: [u8; 6] = *b"World!";
@@ -148,14 +148,14 @@ mod tests {
148148
.times(1);
149149
envoy_filter
150150
.expect_send_response()
151-
.withf(|status, _, _| *status == 403)
152-
.returning(|_, _, _| {})
151+
.withf(|status, _, _, _| *status == 403)
152+
.returning(|_, _, _, _| {})
153153
.times(1);
154154
assert_eq!(filter.on_request_body(&mut envoy_filter, true), abi::envoy_dynamic_module_type_on_http_filter_request_body_status::StopIterationNoBuffer);
155155

156156
// End of stream and not matching regex, so we should continue.
157157
envoy_filter
158-
.expect_get_request_body()
158+
.expect_get_buffered_request_body()
159159
.returning(|| {
160160
static mut GOOD: [u8; 5] = *b"Good ";
161161
static mut MORNING: [u8; 8] = *b"Morning!";

0 commit comments

Comments
 (0)