-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathutils.rs
44 lines (39 loc) · 1.69 KB
/
utils.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use hmac::{Hmac, Mac};
use relay_event_schema::processor::{
self, ProcessValue, ProcessingResult, ProcessingState, Processor, ValueType,
};
use relay_event_schema::protocol::{AsPair, PairList};
use sha1::Sha1;
pub fn process_pairlist<P: Processor, T: ProcessValue + AsPair>(
slf: &mut P,
value: &mut PairList<T>,
state: &ProcessingState,
) -> ProcessingResult {
// View pairlists as objects just for the purpose of PII stripping (e.g. `event.tags.mykey`
// instead of `event.tags.42.0`). For other purposes such as trimming we would run into
// problems:
//
// * tag keys need to be trimmed too and therefore need to have a path
for (idx, annotated) in value.iter_mut().enumerate() {
if let Some(ref mut pair) = annotated.value_mut() {
let (ref mut key, ref mut value) = pair.as_pair_mut();
let value_type = ValueType::for_field(value);
if let Some(key_name) = key.as_str() {
// if the pair has no key name, we skip over it for PII stripping. It is
// still processed with index-based path in the invocation of
// `process_child_values`.
let entered = state.enter_borrowed(key_name, state.inner_attrs(), value_type);
processor::process_value(value, slf, &entered)?;
} else {
let entered = state.enter_index(idx, state.inner_attrs(), value_type);
processor::process_value(value, slf, &entered)?;
}
}
}
Ok(())
}
pub fn hash_value(data: &[u8]) -> String {
let mut mac = Hmac::<Sha1>::new_from_slice(&[]).unwrap();
mac.update(data);
format!("{:X}", mac.finalize().into_bytes())
}