Skip to content

Commit

Permalink
action service name was lost when building runtime grpc actions
Browse files Browse the repository at this point in the history
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
  • Loading branch information
eguzki committed Nov 18, 2024
1 parent 9cd9ee5 commit e3f809e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Filter {
fn process_action_sets(&self, m_set_list: &[Rc<GRPCActionSet>]) -> 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)
Expand Down
4 changes: 3 additions & 1 deletion src/internal/auth_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::rc::Rc;
pub struct AuthAction {
grpc_service: Rc<GrpcService>,
scope: String,
service_name: String,
predicates: OnceCell<Vec<Predicate>>,
}

Expand All @@ -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(),
};

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/internal/grpc_action_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Predicate>>,
Expand Down
6 changes: 4 additions & 2 deletions src/internal/ratelimit_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl ConditionalData {
#[derive(Clone, Debug)]
pub struct RateLimitAction {
grpc_service: Rc<GrpcService>,
pub scope: String,
scope: String,
service_name: String,
conditional_data_sets: Vec<ConditionalData>,
}

Expand All @@ -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)?],
})
}
Expand All @@ -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 {
Expand Down
42 changes: 21 additions & 21 deletions tests/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e3f809e

Please sign in to comment.