Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predicate on our "well-known attributes" #113

Merged
merged 26 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
271b464
Refactored Attribute to data::AttributeValue
alexsnaps Oct 19, 2024
762091d
Refactored property stuff to data::property
alexsnaps Oct 19, 2024
78d5eb0
Refactored using PropertyPath everywhere
alexsnaps Oct 19, 2024
7624900
Refactored using AttributeValue everywhere
alexsnaps Oct 19, 2024
54ad632
ports are u64, not strings... this err'ed into Default
alexsnaps Oct 19, 2024
eede19a
Slowly getting there
alexsnaps Oct 20, 2024
222a7cf
Wired the base
alexsnaps Oct 20, 2024
f4fd18f
Clippy fixes
alexsnaps Oct 21, 2024
34c7050
Notes for auth/json integration
alexsnaps Oct 21, 2024
df48e11
Typos and test infra for hostcalls::get_property
alexsnaps Oct 21, 2024
8c001f3
Predicate test
alexsnaps Oct 21, 2024
ce49eb2
Transparently replace PatternExpression with CEL Predicate
alexsnaps Oct 21, 2024
60820e0
Moar clippy
alexsnaps Oct 21, 2024
067aaf2
Deal with unknown attributes as JSON literals
alexsnaps Oct 22, 2024
06000e0
Arguable: but lets fall back to string on bad json
alexsnaps Oct 22, 2024
7dc7ac9
wasm props are in the filter_state
alexsnaps Oct 23, 2024
611a900
Deal with more types & json encode values
alexsnaps Oct 23, 2024
f911798
Have auth in wasm prop and log on unexpected type
alexsnaps Oct 23, 2024
dbdf7e1
Deal with previously resolved values on path digging into these
alexsnaps Oct 23, 2024
5deae3b
Don't warn on structs when storing values as json
alexsnaps Oct 23, 2024
a786e94
Support headers in CEL
alexsnaps Oct 23, 2024
00d4863
Remove trailing comment
alexsnaps Oct 23, 2024
b63057f
No more dead code
alexsnaps Oct 23, 2024
b9af3dc
Support for CEL expressions in data exports
alexsnaps Oct 24, 2024
7528942
request.time is a Timestamp
alexsnaps Oct 24, 2024
06cd03d
README reflecting new config
alexsnaps Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/data/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::data::property::Path;
use crate::data::PropertyPath;
use chrono::{DateTime, FixedOffset};
use log::{debug, error, warn};
Expand Down Expand Up @@ -121,7 +120,7 @@ where
}

pub fn set_attribute(attr: &str, value: &[u8]) {
match hostcalls::set_property(Path::from(attr).tokens(), Some(value)) {
match hostcalls::set_property(PropertyPath::from(attr).tokens(), Some(value)) {
Ok(_) => (),
Err(_) => error!("set_attribute: failed to set property {attr}"),
};
Expand Down
6 changes: 5 additions & 1 deletion src/data/cel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::data::get_attribute;
use crate::data::property::Path;
use crate::data::property::{host_get_map, Path};
use cel_interpreter::objects::{Map, ValueType};
use cel_interpreter::{Context, Value};
use cel_parser::{parse, Expression as CelExpression, Member, ParseError};
Expand Down Expand Up @@ -135,6 +135,10 @@ impl Attribute {
.expect("Failed getting to known attribute")
.map(Value::Timestamp)
.unwrap_or(Value::Null),
ValueType::Map => host_get_map(&self.path)
.map(cel_interpreter::objects::Map::from)
.map(Value::Map)
.unwrap_or(Value::Null),
_ => todo!("Need support for `{t}`s!"),
},
None => match get_attribute::<String>(&self.path).expect("Path must resolve!") {
Expand Down
28 changes: 28 additions & 0 deletions src/data/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::data::attribute::KUADRANT_NAMESPACE;
use log::debug;
use log::warn;
use proxy_wasm::types::Status;
use std::collections::HashMap;
use std::fmt::{Debug, Display, Formatter};

fn remote_address() -> Result<Option<Vec<u8>>, Status> {
Expand Down Expand Up @@ -37,6 +38,33 @@ fn host_get_property(path: &Path) -> Result<Option<Vec<u8>>, Status> {
Ok(test::TEST_PROPERTY_VALUE.take())
}

#[cfg(test)]
pub fn host_get_map(path: &Path) -> Result<HashMap<String, String>, String> {
match *path.tokens() {
["request", "headers"] => Ok(HashMap::default()),
_ => Err(format!("Unknown map requested {:?}", path)),
}
}

#[cfg(not(test))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this way of defining the fn when it's meant to be mocked for testing and not. Might be worthy to follow the same pattern for the operation dispatcher and grpc message req/res //TODO:(didierofrivia)

pub fn host_get_map(path: &Path) -> Result<HashMap<String, String>, String> {
match *path.tokens() {
["request", "headers"] => {
debug!(
"get_map: {:?}",
proxy_wasm::types::MapType::HttpRequestHeaders
);
let map =
proxy_wasm::hostcalls::get_map(proxy_wasm::types::MapType::HttpRequestHeaders)
.unwrap()
.into_iter()
.collect();
Ok(map)
}
_ => Err(format!("Unknown map requested {:?}", path)),
}
}

#[cfg(not(test))]
fn host_get_property(path: &Path) -> Result<Option<Vec<u8>>, Status> {
debug!("get_property: {:?}", path);
Expand Down
Loading