-
Notifications
You must be signed in to change notification settings - Fork 5
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
Typing #41
Typing #41
Changes from all commits
2925a5f
d903b61
a132ec0
e33ca1e
70a5fd3
d9219c9
393fd7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
use crate::typing::TypedProperty; | ||
use std::collections::BTreeMap; | ||
|
||
type MapperFn = dyn Fn(Vec<u8>) -> TypedProperty; | ||
|
||
pub struct EnvoyTypeMapper { | ||
known_properties: BTreeMap<String, Box<MapperFn>>, | ||
} | ||
|
||
impl EnvoyTypeMapper { | ||
pub fn new() -> Self { | ||
let mut properties: BTreeMap<String, Box<MapperFn>> = BTreeMap::new(); | ||
properties.insert( | ||
"request.time".to_string(), | ||
Box::new(TypedProperty::timestamp), | ||
); | ||
|
||
properties.insert("request.id".to_string(), Box::new(TypedProperty::string)); | ||
properties.insert( | ||
"request.protocol".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"request.scheme".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert("request.host".to_string(), Box::new(TypedProperty::string)); | ||
properties.insert( | ||
"request.method".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert("request.path".to_string(), Box::new(TypedProperty::string)); | ||
properties.insert( | ||
"request.url_path".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert("request.query".to_string(), Box::new(TypedProperty::string)); | ||
properties.insert( | ||
"request.referer".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"request.useragent".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert("request.body".to_string(), Box::new(TypedProperty::string)); | ||
properties.insert( | ||
"source.address".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"source.service".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"source.principal".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"source.certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"destination.address".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"destination.service".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"destination.principal".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"destination.certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.requested_server_name".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.tls_session.sni".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.tls_version".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.subject_local_certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.subject_peer_certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.dns_san_local_certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.dns_san_peer_certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.uri_san_local_certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.uri_san_peer_certificate".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"connection.sha256_peer_certificate_digest".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
properties.insert( | ||
"ratelimit.domain".to_string(), | ||
Box::new(TypedProperty::string), | ||
); | ||
|
||
properties.insert("request.size".to_string(), Box::new(TypedProperty::integer)); | ||
properties.insert("source.port".to_string(), Box::new(TypedProperty::integer)); | ||
properties.insert( | ||
"destination.port".to_string(), | ||
Box::new(TypedProperty::integer), | ||
); | ||
properties.insert( | ||
"connection.id".to_string(), | ||
Box::new(TypedProperty::integer), | ||
); | ||
properties.insert( | ||
"ratelimit.hits_addend".to_string(), | ||
Box::new(TypedProperty::integer), | ||
); | ||
|
||
properties.insert("metadata".to_string(), Box::new(TypedProperty::metadata)); | ||
|
||
properties.insert( | ||
"request.headers".to_string(), | ||
Box::new(TypedProperty::string_map), | ||
); | ||
properties.insert( | ||
"request.context_extensions".to_string(), | ||
Box::new(TypedProperty::string_map), | ||
); | ||
properties.insert( | ||
"source.labels".to_string(), | ||
Box::new(TypedProperty::string_map), | ||
); | ||
properties.insert( | ||
"destination.labels".to_string(), | ||
Box::new(TypedProperty::string_map), | ||
); | ||
properties.insert( | ||
"filter_state".to_string(), | ||
Box::new(TypedProperty::string_map), | ||
); | ||
|
||
properties.insert( | ||
"auth.metadata".to_string(), | ||
Box::new(TypedProperty::complex_map), | ||
); | ||
properties.insert( | ||
"auth.authorization".to_string(), | ||
Box::new(TypedProperty::complex_map), | ||
); | ||
properties.insert( | ||
"auth.response".to_string(), | ||
Box::new(TypedProperty::complex_map), | ||
); | ||
properties.insert( | ||
"auth.callbacks".to_string(), | ||
Box::new(TypedProperty::complex_map), | ||
); | ||
Comment on lines
+162
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do we need a special Another option would be the "translation" to happen in the policy controller, and therefore the wasm shim won't ever even need to know about them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually merely defines the typing... but you are right that I conflated the typing with the host. Maybe I should treat all auth related ones differently... tho they'd still use some typed mapper function just as the envoy properties do... 🤔 |
||
|
||
properties.insert( | ||
"connection.mtls".to_string(), | ||
Box::new(TypedProperty::boolean), | ||
); | ||
|
||
properties.insert( | ||
"request.raw_body".to_string(), | ||
Box::new(TypedProperty::bytes), | ||
); | ||
properties.insert("auth.identity".to_string(), Box::new(TypedProperty::bytes)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
Self { | ||
known_properties: properties, | ||
} | ||
} | ||
|
||
pub fn typed(&self, path: &str, raw: Vec<u8>) -> Result<TypedProperty, Vec<u8>> { | ||
match self.known_properties.get(path) { | ||
None => Err(raw), | ||
Some(mapper) => Ok(mapper(raw)), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code from
src/envoy
has been copied&pasted from somewhere else. What if we "upgrade" this dependency?