Skip to content

Commit

Permalink
Added all known properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Jan 10, 2024
1 parent 70a5fd3 commit d9219c9
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 7 deletions.
179 changes: 177 additions & 2 deletions src/envoy/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,183 @@ pub struct EnvoyTypeMapper {
impl EnvoyTypeMapper {
pub fn new() -> Self {
let mut properties: BTreeMap<String, Box<MapperFn>> = 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,
}
Expand Down
5 changes: 1 addition & 4 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
Expand Down
24 changes: 23 additions & 1 deletion src/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ impl TypedProperty {
}
}

pub fn timestamp(bytes: Vec<u8>) -> Self {
TypedProperty::Bytes(bytes.to_vec())
}

pub fn string_map(bytes: Vec<u8>) -> Self {
TypedProperty::Bytes(bytes.to_vec())
}

pub fn complex_map(bytes: Vec<u8>) -> Self {
TypedProperty::Bytes(bytes.to_vec())
}

pub fn boolean(bytes: Vec<u8>) -> Self {
TypedProperty::Bytes(bytes.to_vec())
}

pub fn metadata(bytes: Vec<u8>) -> Self {
TypedProperty::Bytes(bytes.to_vec())
}

pub fn bytes(bytes: Vec<u8>) -> Self {
TypedProperty::Bytes(bytes.to_vec())
}
Expand All @@ -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();
Expand Down

0 comments on commit d9219c9

Please sign in to comment.