From e3f809e89526be5d1cce7ba68deb66c74446b067 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Mon, 18 Nov 2024 16:31:27 +0100 Subject: [PATCH] action service name was lost when building runtime grpc actions Signed-off-by: Eguzki Astiz Lezaun --- src/filter/http_context.rs | 1 + src/internal/auth_action.rs | 4 ++- src/internal/grpc_action_set.rs | 1 + src/internal/ratelimit_action.rs | 6 +++-- tests/multi.rs | 42 ++++++++++++++++---------------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/filter/http_context.rs b/src/filter/http_context.rs index 726c7a6..9b36b68 100644 --- a/src/filter/http_context.rs +++ b/src/filter/http_context.rs @@ -36,6 +36,7 @@ impl Filter { fn process_action_sets(&self, m_set_list: &[Rc]) -> Action { if let Some(m_set) = m_set_list.iter().find(|m_set| m_set.conditions_apply()) { debug!("#{} action_set selected {}", self.context_id, m_set.name); + //debug!("#{} runtime action_set {:#?}", self.context_id, m_set); self.operation_dispatcher .borrow_mut() .build_operations(&m_set.grpc_actions) diff --git a/src/internal/auth_action.rs b/src/internal/auth_action.rs index 4ef7d0c..b888946 100644 --- a/src/internal/auth_action.rs +++ b/src/internal/auth_action.rs @@ -9,6 +9,7 @@ use std::rc::Rc; pub struct AuthAction { grpc_service: Rc, scope: String, + service_name: String, predicates: OnceCell>, } @@ -22,6 +23,7 @@ impl AuthAction { let auth_action = AuthAction { grpc_service: Rc::new(GrpcService::new(Rc::new(service.clone()))), scope: action.scope.clone(), + service_name: action.service.clone(), predicates: OnceCell::new(), }; @@ -38,7 +40,7 @@ impl AuthAction { } pub fn service(&self) -> &str { - self.grpc_service.name() + self.service_name.as_str() } pub fn scope(&self) -> &str { diff --git a/src/internal/grpc_action_set.rs b/src/internal/grpc_action_set.rs index d682038..77bed0d 100644 --- a/src/internal/grpc_action_set.rs +++ b/src/internal/grpc_action_set.rs @@ -5,6 +5,7 @@ use log::error; use std::cell::OnceCell; use std::collections::HashMap; +#[derive(Debug)] pub struct GRPCActionSet { pub name: String, pub route_rule_predicates: OnceCell>, diff --git a/src/internal/ratelimit_action.rs b/src/internal/ratelimit_action.rs index 39c769e..2acbd8a 100644 --- a/src/internal/ratelimit_action.rs +++ b/src/internal/ratelimit_action.rs @@ -127,7 +127,8 @@ impl ConditionalData { #[derive(Clone, Debug)] pub struct RateLimitAction { grpc_service: Rc, - pub scope: String, + scope: String, + service_name: String, conditional_data_sets: Vec, } @@ -136,6 +137,7 @@ impl RateLimitAction { Ok(Self { grpc_service: Rc::new(GrpcService::new(Rc::new(service.clone()))), scope: action.scope.clone(), + service_name: action.service.clone(), conditional_data_sets: vec![ConditionalData::new(action)?], }) } @@ -157,7 +159,7 @@ impl RateLimitAction { } pub fn service(&self) -> &str { - self.grpc_service.name() + self.service_name.as_str() } pub fn scope(&self) -> &str { diff --git a/tests/multi.rs b/tests/multi.rs index 5ed3f7f..1b4486e 100644 --- a/tests/multi.rs +++ b/tests/multi.rs @@ -198,15 +198,15 @@ fn it_performs_authenticated_rate_limiting() { 52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 157, 1, 10, 12, 8, 146, 140, 179, 185, 6, 16, 240, 213, 233, 163, 3, 18, 140, 1, 18, 3, 71, 69, 84, - 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98, - 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10, 7, - 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, - 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, - 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10, - 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116, - 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82, - 8, 72, 84, 84, 80, 47, 49, 46, 49, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, - 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0, + 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, + 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, + 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, + 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98, + 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 34, 10, 47, 97, + 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116, 111, 121, + 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82, 8, 72, + 84, 84, 80, 47, 49, 46, 49, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, + 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0, ]), Some(5000), ) @@ -412,15 +412,15 @@ fn unauthenticated_does_not_ratelimit() { 52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 157, 1, 10, 12, 8, 146, 140, 179, 185, 6, 16, 240, 213, 233, 163, 3, 18, 140, 1, 18, 3, 71, 69, 84, - 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98, - 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10, 7, - 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, - 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, - 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10, - 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116, - 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82, - 8, 72, 84, 84, 80, 47, 49, 46, 49, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, - 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0, + 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, + 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, + 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, + 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98, + 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 34, 10, 47, 97, + 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116, 111, 121, + 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82, 8, 72, + 84, 84, 80, 47, 49, 46, 49, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, + 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0, ]), Some(5000), ) @@ -688,9 +688,9 @@ fn authenticated_one_ratelimit_action_matches() { 146, 140, 179, 185, 6, 16, 240, 213, 233, 163, 3, 18, 140, 1, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, - 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, - 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98, - 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 34, 10, 47, 97, + 112, 97, 116, 104, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, + 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, + 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82, 8, 72, 84, 84, 80, 47, 49, 46, 49, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117,