refactoring

This commit is contained in:
ichiichi11
2020-11-22 12:12:05 +09:00
parent abd46f9b1b
commit 1adcb8c44b
3 changed files with 39 additions and 252 deletions

View File

@@ -1,6 +1,7 @@
extern crate regex;
use crate::detections::configs;
use crate::detections::utils;
use regex::Regex;
use serde_json::Value;
use yaml_rust::Yaml;
@@ -25,28 +26,6 @@ fn parse_detection(yaml: &Yaml) -> Option<DetectionNode> {
}
}
pub fn get_event_value<'a>(key: &String, event_value: &'a Value) -> Option<&'a Value> {
if key.len() == 0 {
return Option::None;
}
let alias_config = configs::singleton().event_key_alias_config;
let event_key = match alias_config.get_event_key(key.to_string()) {
Some(alias_event_key) => alias_event_key,
None => key,
};
let mut ret: &Value = event_value;
for key in event_key.split(".") {
if ret.is_object() == false {
return Option::None;
}
ret = &ret[key];
}
return Option::Some(ret);
}
fn concat_selection_key(key_list: &Vec<String>) -> String {
return key_list
.iter()
@@ -261,7 +240,7 @@ impl LeafSelectionNode {
return Option::None;
}
return get_event_value(&self.key_list[0].to_string(), event_value);
return utils::get_event_value(&self.key_list[0].to_string(), event_value);
}
// LeafMatcherの一覧を取得する。