diff --git a/src/detections/configs.rs b/src/detections/configs.rs index cbd02fe4..ab5dc0c7 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -83,14 +83,3 @@ fn read_csv(filename: &str) -> Vec> { return ret; } - -/// Argsから言語情報を読み取り Lang を返す -pub fn get_lang() -> Lang { - let lang: String = singleton().args.value_of("lang").unwrap_or("").to_string(); - - match &*lang { - "Ja" | "ja" => Lang::Ja, - "En" | "en" => Lang::En, - _ => Lang::En, - } -} diff --git a/src/detections/powershell.rs b/src/detections/powershell.rs index 74cef1a6..9a4a8c5d 100644 --- a/src/detections/powershell.rs +++ b/src/detections/powershell.rs @@ -27,7 +27,7 @@ impl PowerShell { } let message = MESSAGES.lock().unwrap(); - println!("{}", message.return_message("4103")); + println!("{}", message.get("4103")); let default = String::from(""); let commandline = event_data.get("ContextInfo").unwrap_or(&default); @@ -53,7 +53,7 @@ impl PowerShell { return; } let message = MESSAGES.lock().unwrap(); - println!("{}", message.return_message("4104")); + println!("{}", message.get("4104")); let default = String::from(""); let path = event_data.get("Path").unwrap().to_string(); diff --git a/src/detections/print.rs b/src/detections/print.rs index c796c41c..c91adb26 100644 --- a/src/detections/print.rs +++ b/src/detections/print.rs @@ -1,5 +1,5 @@ extern crate lazy_static; -use crate::detections::configs::{get_lang, Lang}; +use crate::detections::configs::{singleton, Lang}; use crate::models::rule::MessageText; use lazy_static::lazy_static; use std::collections::HashMap; @@ -29,12 +29,12 @@ impl Message { } /// メッセージを設定 - pub fn insert_message(&mut self, error_code: String, message: MessageText) { + pub fn insert(&mut self, error_code: String, message: MessageText) { self.map.insert(error_code, message); } /// メッセージを返す - pub fn return_message(&self, message_num: &str) -> &MessageText { + pub fn get(&self, message_num: &str) -> &MessageText { self.map .get(message_num) .unwrap_or(self.map.get("undefined").unwrap()) @@ -52,11 +52,22 @@ impl fmt::Display for MessageText { } } +/// Argsから言語情報を読み取り Lang を返す +pub fn get_lang() -> Lang { + let lang: String = singleton().args.value_of("lang").unwrap_or("").to_string(); + + match &*lang { + "Ja" | "ja" => Lang::Ja, + "En" | "en" => Lang::En, + _ => Lang::En, + } +} + #[test] fn test_create_and_read_message() { let mut error_message = Message::new(); - error_message.insert_message( + error_message.insert( "4103".to_string(), MessageText { ja: "パイプライン実行をしています".to_string(), @@ -64,10 +75,7 @@ fn test_create_and_read_message() { }, ); - let display = format!( - "{}", - format_args!("{}", error_message.return_message("4103")) - ); + let display = format!("{}", format_args!("{}", error_message.get("4103"))); assert_eq!(display, "Execute pipeline") } diff --git a/src/main.rs b/src/main.rs index 84325960..46327208 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ fn main() -> Result<(), DeError> { let mut message = MESSAGES.lock().unwrap(); if let Some(messages) = _rule.rule.messages { for (key, texts) in messages { - message.insert_message(key, texts); + message.insert(key, texts); } } }