diff --git a/limitador-server/src/envoy_rls/server.rs b/limitador-server/src/envoy_rls/server.rs index e975fc1b..50328813 100644 --- a/limitador-server/src/envoy_rls/server.rs +++ b/limitador-server/src/envoy_rls/server.rs @@ -407,18 +407,18 @@ mod tests { namespace, 10, 60, - vec!["x == '1'".try_into().expect("failed parsing!")], - vec!["z".try_into().expect("failed parsing!")], + vec!["descriptors[0].x == '1'".try_into().expect("failed parsing!")], + vec!["descriptors[0].z".try_into().expect("failed parsing!")], ), Limit::new( namespace, 0, 60, vec![ - "x == '1'".try_into().expect("failed parsing!"), - "y == '2'".try_into().expect("failed parsing!"), + "descriptors[0].x == '1'".try_into().expect("failed parsing!"), + "descriptors[0].y == '2'".try_into().expect("failed parsing!"), ], - vec!["z".try_into().expect("failed parsing!")], + vec!["descriptors[0].z".try_into().expect("failed parsing!")], ), ] .into_iter() @@ -487,8 +487,8 @@ mod tests { namespace, 10, 60, - vec!["x == '1'".try_into().expect("failed parsing!")], - vec!["y".try_into().expect("failed parsing!")], + vec!["descriptors[0].x == '1'".try_into().expect("failed parsing!")], + vec!["descriptors[0].y".try_into().expect("failed parsing!")], ); let limiter = RateLimiter::new(10_000); @@ -562,8 +562,8 @@ mod tests { namespace, 1, 60, - vec!["x == '1'".try_into().expect("failed parsing!")], - vec!["y".try_into().expect("failed parsing!")], + vec!["descriptors[0].x == '1'".try_into().expect("failed parsing!")], + vec!["descriptors[0].y".try_into().expect("failed parsing!")], ); let limiter = RateLimiter::new(10_000); diff --git a/limitador-server/src/http_api/server.rs b/limitador-server/src/http_api/server.rs index 3a7b1ef7..219c3f10 100644 --- a/limitador-server/src/http_api/server.rs +++ b/limitador-server/src/http_api/server.rs @@ -14,6 +14,7 @@ use paperclip::actix::{ }; use std::fmt; use std::sync::Arc; +use limitador::limit::Context; struct RateLimitData { limiter: Arc, @@ -122,7 +123,8 @@ async fn check( response_headers: _, } = request.into_inner(); let namespace = namespace.into(); - let ctx = values.into(); + let mut ctx = Context::default(); + ctx.list_binding("descriptors".to_string(), vec![values]); let is_rate_limited_result = match state.get_ref().limiter() { Limiter::Blocking(limiter) => limiter.is_rate_limited(&namespace, &ctx, delta), Limiter::Async(limiter) => limiter.is_rate_limited(&namespace, &ctx, delta).await, @@ -153,7 +155,8 @@ async fn report( response_headers: _, } = request.into_inner(); let namespace = namespace.into(); - let ctx = values.into(); + let mut ctx = Context::default(); + ctx.list_binding("descriptors".to_string(), vec![values]); let update_counters_result = match data.get_ref().limiter() { Limiter::Blocking(limiter) => limiter.update_counters(&namespace, &ctx, delta), Limiter::Async(limiter) => limiter.update_counters(&namespace, &ctx, delta).await, @@ -178,7 +181,8 @@ async fn check_and_report( response_headers, } = request.into_inner(); let namespace = namespace.into(); - let ctx = values.into(); + let mut ctx = Context::default(); + ctx.list_binding("descriptors".to_string(), vec![values]); let rate_limit_data = data.get_ref(); let rate_limited_and_update_result = match rate_limit_data.limiter() { Limiter::Blocking(limiter) => limiter.check_rate_limited_and_update(