Skip to content

Commit

Permalink
Add debug code for logging well-known attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <[email protected]>
  • Loading branch information
adam-cattermole committed Nov 8, 2024
1 parent 80b7e93 commit 9103d31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/data/cel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cel_interpreter::objects::{Key, Map, ValueType};
use cel_interpreter::{Context, ExecutionError, ResolveResult, Value};
use cel_parser::{parse, Expression as CelExpression, Member, ParseError};
use chrono::{DateTime, FixedOffset};
use log::debug;
use proxy_wasm::types::{Bytes, Status};
use serde_json::Value as JsonValue;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -441,6 +442,22 @@ fn properties<'e>(exp: &'e CelExpression, all: &mut Vec<Vec<&'e str>>, path: &mu
}
}

#[allow(dead_code)]
pub fn debug_all_well_known_attributes() {
let attributes = new_well_known_attribute_map();
attributes.iter().for_each(|(key, value_type)| {
match proxy_wasm::hostcalls::get_property(key.tokens()) {
Ok(opt_bytes) => match opt_bytes {
None => debug!("{:#?}({}): None", key, value_type),
Some(bytes) => debug!("{:#?}({}): {:?}", key, value_type, bytes),
},
Err(err) => {
debug!("{:#?}({}): (err) {:?}", key, value_type, err)
}
}
})
}

pub mod data {
use crate::data::cel::Attribute;
use cel_interpreter::objects::{Key, Map};
Expand Down
2 changes: 2 additions & 0 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ pub use cel::Predicate;

pub use property::get_property;
pub use property::Path as PropertyPath;

// pub use cel::debug_all_well_known_attributes;
4 changes: 4 additions & 0 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use proxy_wasm::traits::{Context, HttpContext};
use proxy_wasm::types::Action;
use std::cell::RefCell;
use std::rc::Rc;
// use crate::data;

pub struct Filter {
pub context_id: u32,
Expand Down Expand Up @@ -94,6 +95,9 @@ impl HttpContext for Filter {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
debug!("#{} on_http_request_headers", self.context_id);

// uncomment to debug log all well known attributes
// data::debug_all_well_known_attributes();

match self
.config
.index
Expand Down

0 comments on commit 9103d31

Please sign in to comment.