refactoring
This commit is contained in:
@@ -12,6 +12,7 @@ use serde_json::{Error, Value};
|
||||
|
||||
const DIRPATH_RULES: &str = "rules";
|
||||
|
||||
// TODO テストケースかかなきゃ...
|
||||
#[derive(Debug)]
|
||||
pub struct Detection {}
|
||||
|
||||
@@ -64,8 +65,11 @@ impl Detection {
|
||||
err_msgs_result.err().iter().for_each(|err_msgs| {
|
||||
// TODO 本当はファイルパスを出力したい
|
||||
// ParseYamlの変更が必要なので、一旦yamlのタイトルを表示。
|
||||
|
||||
// TODO エラーの出力方法を統一したい。
|
||||
// エラー出力用のクラスを作成してもいいかも
|
||||
println!(
|
||||
"[Failed to parse Rule file. See following detail. rule file title:{}]",
|
||||
"[ERROR] Failed to parse Rule file. (Error Rule Title : {})",
|
||||
rule.yaml["title"].as_str().unwrap_or("")
|
||||
);
|
||||
err_msgs.iter().for_each(|err_msg| println!("{}", err_msg));
|
||||
|
||||
@@ -6,6 +6,7 @@ use regex::Regex;
|
||||
use serde_json::Value;
|
||||
use yaml_rust::Yaml;
|
||||
|
||||
// TODO テストケースかかなきゃ...
|
||||
pub fn parse_rule(yaml: Yaml) -> RuleNode {
|
||||
let detection = parse_detection(&yaml);
|
||||
|
||||
@@ -358,6 +359,8 @@ impl LeafMatcher for RegexMatcher {
|
||||
}
|
||||
|
||||
fn is_match(&self, event_value: Option<&Value>) -> bool {
|
||||
// unwrap_orの引数に""ではなく" "を指定しているのは、
|
||||
// event_valueが文字列じゃない場合にis_event_value_nullの値がfalseになるように、len() == 0とならない値を指定している。
|
||||
let is_event_value_null = event_value.is_none()
|
||||
|| event_value.unwrap().is_null()
|
||||
|| event_value.unwrap().as_str().unwrap_or(" ").len() == 0;
|
||||
|
||||
Reference in New Issue
Block a user