diff --git a/src/envoy/properties.rs b/src/envoy/properties.rs index 66cb4a4..43c1a3f 100644 --- a/src/envoy/properties.rs +++ b/src/envoy/properties.rs @@ -10,8 +10,183 @@ pub struct EnvoyTypeMapper { impl EnvoyTypeMapper { pub fn new() -> Self { let mut properties: BTreeMap> = BTreeMap::new(); - properties.insert("foo.bar".to_string(), Box::new(TypedProperty::string)); - properties.insert("foo.car".to_string(), Box::new(TypedProperty::integer)); + 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), + ); + + 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)); + Self { known_properties: properties, } diff --git a/src/filter/http_context.rs b/src/filter/http_context.rs index a23540e..ba53b37 100644 --- a/src/filter/http_context.rs +++ b/src/filter/http_context.rs @@ -167,10 +167,7 @@ impl Filter { ); None } - Some(attribute_bytes) => match self - .property_mapper - .typed(path, attribute_bytes) - { + Some(attribute_bytes) => match self.property_mapper.typed(path, attribute_bytes) { Ok(tp) => Some(tp), Err(raw) => Some(TypedProperty::string(raw)), }, diff --git a/src/typing.rs b/src/typing.rs index 9f31722..34280ec 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -24,6 +24,26 @@ impl TypedProperty { } } + pub fn timestamp(bytes: Vec) -> Self { + TypedProperty::Bytes(bytes.to_vec()) + } + + pub fn string_map(bytes: Vec) -> Self { + TypedProperty::Bytes(bytes.to_vec()) + } + + pub fn complex_map(bytes: Vec) -> Self { + TypedProperty::Bytes(bytes.to_vec()) + } + + pub fn boolean(bytes: Vec) -> Self { + TypedProperty::Bytes(bytes.to_vec()) + } + + pub fn metadata(bytes: Vec) -> Self { + TypedProperty::Bytes(bytes.to_vec()) + } + pub fn bytes(bytes: Vec) -> Self { TypedProperty::Bytes(bytes.to_vec()) } @@ -46,7 +66,9 @@ impl TypedProperty { pub fn as_literal(&self) -> String { match self { - TypedProperty::String(str) => format!("\"{}\"", str.replace('\\', "\\\\").replace('"', "\\\"")), + TypedProperty::String(str) => { + format!("\"{}\"", str.replace('\\', "\\\\").replace('"', "\\\"")) + } TypedProperty::Integer(int) => int.to_string(), TypedProperty::Bytes(bytes) => { let len = 5 * bytes.len();